VirtualBox

Ignore:
Timestamp:
Apr 16, 2019 11:49:44 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9434: Import Appliance wizard: Form Editor widget: Adjust table layout and columns.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp

    r78131 r78143  
    1818/* Qt includes: */
    1919#include <QComboBox>
     20#include <QEvent>
    2021#include <QHeaderView>
    2122#include <QItemEditorFactory>
     
    563564    /// @todo add some check..
    564565    m_pTableModel->setFormValues(comForm.GetValues());
     566    adjustTable();
     567}
     568
     569bool UIFormEditorWidget::eventFilter(QObject *pObject, QEvent *pEvent)
     570{
     571    /* Process events for table only: */
     572    if (pObject != m_pTableView)
     573        return QWidget::eventFilter(pObject, pEvent);
     574
     575    /* Process different event-types: */
     576    switch (pEvent->type())
     577    {
     578        case QEvent::Show:
     579        case QEvent::Resize:
     580        {
     581            /* Adjust table: */
     582            adjustTable();
     583            break;
     584        }
     585        default:
     586            break;
     587    }
     588
     589    /* Call to base-class: */
     590    return QWidget::eventFilter(pObject, pEvent);
    565591}
    566592
     
    571597    if (pLayout)
    572598    {
     599        pLayout->setContentsMargins(0, 0, 0, 0);
     600
    573601        /* Create view: */
    574602        m_pTableView = new UIFormEditorView(this);
     
    579607            m_pTableView->verticalHeader()->setDefaultSectionSize((int)(m_pTableView->verticalHeader()->minimumSectionSize() * 1.33));
    580608            m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
     609            m_pTableView->installEventFilter(this);
    581610
    582611            /* Create model: */
     
    614643}
    615644
     645void UIFormEditorWidget::adjustTable()
     646{
     647    m_pTableView->horizontalHeader()->setStretchLastSection(false);
     648    /* If table is NOT empty: */
     649    if (m_pTableModel->rowCount())
     650    {
     651        /* Resize table to contents size-hint and emit a spare place for first column: */
     652        m_pTableView->resizeColumnsToContents();
     653        const int iFullWidth = m_pTableView->viewport()->width();
     654        const int iNameWidth = m_pTableView->horizontalHeader()->sectionSize(UIFormEditorDataType_Name);
     655        const int iValueWidth = qMax(0, iFullWidth - iNameWidth);
     656        m_pTableView->horizontalHeader()->resizeSection(UIFormEditorDataType_Value, iValueWidth);
     657    }
     658    /* If table is empty: */
     659    else
     660    {
     661        /* Resize table columns to be equal in size: */
     662        const int iFullWidth = m_pTableView->viewport()->width();
     663        m_pTableView->horizontalHeader()->resizeSection(UIFormEditorDataType_Name, iFullWidth / 2);
     664        m_pTableView->horizontalHeader()->resizeSection(UIFormEditorDataType_Value, iFullWidth / 2);
     665    }
     666    m_pTableView->horizontalHeader()->setStretchLastSection(true);
     667}
     668
    616669
    617670#include "UIFormEditorWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.h

    r78131 r78143  
    7070    void setVirtualSystemDescriptionForm(const CVirtualSystemDescriptionForm &comForm);
    7171
     72protected:
     73
     74    /** Preprocesses any Qt @a pEvent for passed @a pObject. */
     75    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     76
    7277private:
    7378
    7479    /** Prepares all. */
    7580    void prepare();
     81
     82    /** Adjusts table column sizes. */
     83    void adjustTable();
    7684
    7785    /** Holds the table-view instance. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette