VirtualBox

Changeset 77620 in vbox


Ignore:
Timestamp:
Mar 8, 2019 3:03:08 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager UI: Another large bunch of refactoring for Chooser pane, this time UIChooserItem and sub-classes cleanup.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp

    r77596 r77620  
    3232#include "UIChooser.h"
    3333#include "UIChooserItem.h"
    34 #include "UIChooserView.h"
    35 #include "UIChooserModel.h"
    3634#include "UIChooserItemGroup.h"
    3735#include "UIChooserItemGlobal.h"
    3836#include "UIChooserItemMachine.h"
     37#include "UIChooserView.h"
     38#include "UIChooserModel.h"
     39
     40/* Other VBox includes: */
     41#include "iprt/assert.h"
    3942
    4043
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h

    r77596 r77620  
    253253      * @{ */
    254254        /** Returns previous geometry. */
    255         const QRectF &previousGeometry() const { return m_previousGeometry; }
     255        QRectF previousGeometry() const { return m_previousGeometry; }
    256256        /** Defines previous @a geometry. */
    257257        void setPreviousGeometry(const QRectF &geometry) { m_previousGeometry = geometry; }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp

    r77596 r77620  
    1717
    1818/* Qt includes: */
    19 #include <QGraphicsScene>
    2019#include <QGraphicsSceneMouseEvent>
    2120#include <QGraphicsView>
     
    2423
    2524/* GUI includes: */
    26 #include "VBoxGlobal.h"
    2725#include "UIChooserItemGlobal.h"
    2826#include "UIChooserModel.h"
     
    226224void UIChooserItemGlobal::updateToolTip()
    227225{
    228 //    setToolTip(toolTipText());
     226    // Nothing for now..
    229227}
    230228
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h

    r77596 r77620  
    2424/* GUI includes: */
    2525#include "UIChooserItem.h"
    26 
    27 /* Forward declarations: */
    28 class QMimeData;
    29 class QPainter;
    30 class QStyleOptionGraphicsItem;
    31 class UIGraphicsToolBar;
    32 class UIGraphicsZoomButton;
    3326
    3427
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r77604 r77620  
    1717
    1818/* Qt includes: */
     19#include <QGraphicsLinearLayout>
    1920#include <QGraphicsScene>
    2021#include <QGraphicsSceneDragDropEvent>
     22#include <QGraphicsView>
    2123#include <QHBoxLayout>
    2224#include <QLineEdit>
    23 #include <QMenu>
    2425#include <QPainter>
    2526#include <QStyleOptionGraphicsItem>
    26 #include <QGraphicsLinearLayout>
    27 #include <QGraphicsProxyWidget>
    2827#include <QWindow>
    2928
     
    3332#include "UIChooserItemMachine.h"
    3433#include "UIChooserModel.h"
    35 #include "UIChooserView.h"
    3634#include "UIGraphicsRotatorButton.h"
    3735#include "UIGraphicsScrollArea.h"
     
    10411039                }
    10421040
    1043                 /* Copy passed item into this group: */
     1041                /* Copy passed group-item into this group: */
    10441042                UIChooserItem *pNewGroupItem = new UIChooserItemGroup(this, pItem->toGroupItem(), iPosition);
    10451043                if (isClosed())
     
    10751073                UIChooserModel *pModel = model();
    10761074
    1077                 /* Get passed item: */
     1075                /* Get passed machine-item: */
    10781076                const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime);
    10791077                AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
     
    12381236void UIChooserItemGroup::prepare()
    12391237{
    1240     /* Painting stuff: */
     1238    /* Prepare self: */
    12411239    m_nameFont = font();
    12421240    m_nameFont.setWeight(QFont::Bold);
     
    12441242    m_minimumHeaderSize = QSize(0, 0);
    12451243
    1246     /* Items except roots: */
    1247     if (!isRoot())
     1244    /* Prepare header widgets of root item: */
     1245    if (isRoot())
     1246    {
     1247#if 0
     1248        /* Except main root ofc: */
     1249        if (!isMainRoot())
     1250        {
     1251            /* Setup exit-button: */
     1252            m_pExitButton = new UIGraphicsButton(this, UIIconPool::iconSet(":/previous_16px.png"));
     1253            if (m_pExitButton)
     1254            {
     1255                m_pExitButton->hide();
     1256                QSizeF sh = m_pExitButton->minimumSizeHint();
     1257                m_pExitButton->setTransformOriginPoint(sh.width() / 2, sh.height() / 2);
     1258                connect(m_pExitButton, &UIGraphicsButton::sigButtonClicked,
     1259                        this, &UIChooserItemGroup::sltUnindentRoot);
     1260            }
     1261            m_exitButtonSize = m_pExitButton ? m_pExitButton->minimumSizeHint().toSize() : QSize(0, 0);
     1262        }
     1263#endif
     1264    }
     1265    /* Prepare header widgets of non-root item: */
     1266    else
    12481267    {
    12491268        /* Setup toggle-button: */
    12501269        m_pToggleButton = new UIGraphicsRotatorButton(this, "additionalHeight", isOpened());
    1251         connect(m_pToggleButton, &UIGraphicsRotatorButton::sigRotationStart,
    1252                 this, &UIChooserItemGroup::sltGroupToggleStart);
    1253         connect(m_pToggleButton, &UIGraphicsRotatorButton::sigRotationFinish,
    1254                 this, &UIChooserItemGroup::sltGroupToggleFinish);
    1255         m_pToggleButton->hide();
     1270        if (m_pToggleButton)
     1271        {
     1272            m_pToggleButton->hide();
     1273            connect(m_pToggleButton, &UIGraphicsRotatorButton::sigRotationStart,
     1274                    this, &UIChooserItemGroup::sltGroupToggleStart);
     1275            connect(m_pToggleButton, &UIGraphicsRotatorButton::sigRotationFinish,
     1276                    this, &UIChooserItemGroup::sltGroupToggleFinish);
     1277        }
    12561278        m_toggleButtonSize = m_pToggleButton ? m_pToggleButton->minimumSizeHint().toSize() : QSize(0, 0);
    12571279
    12581280        /* Setup enter-button: */
    12591281        m_pEnterButton = new UIGraphicsButton(this, UIIconPool::iconSet(":/next_16px.png"));
    1260         connect(m_pEnterButton, &UIGraphicsButton::sigButtonClicked,
    1261                 this, &UIChooserItemGroup::sltIndentRoot);
    1262         m_pEnterButton->hide();
     1282        if (m_pEnterButton)
     1283        {
     1284            m_pEnterButton->hide();
     1285            connect(m_pEnterButton, &UIGraphicsButton::sigButtonClicked,
     1286                    this, &UIChooserItemGroup::sltIndentRoot);
     1287        }
    12631288        m_enterButtonSize = m_pEnterButton ? m_pEnterButton->minimumSizeHint().toSize() : QSize(0, 0);
    12641289
    12651290        /* Setup name-editor: */
    12661291        m_pNameEditorWidget = new UIEditorGroupRename(name());
    1267         m_pNameEditorWidget->setFont(m_nameFont);
    1268         connect(m_pNameEditorWidget, &UIEditorGroupRename::sigEditingFinished,
    1269                 this, &UIChooserItemGroup::sltNameEditingFinished);
    1270     }
    1271 
    1272 #if 0
    1273     /* Items except main root: */
    1274     if (!isMainRoot())
    1275     {
    1276         /* Setup exit-button: */
    1277         m_pExitButton = new UIGraphicsButton(this, UIIconPool::iconSet(":/previous_16px.png"));
    1278         connect(m_pExitButton, &UIGraphicsButton::sigButtonClicked,
    1279                 this, &UIChooserItemGroup::sltUnindentRoot);
    1280         QSizeF sh = m_pExitButton->minimumSizeHint();
    1281         m_pExitButton->setTransformOriginPoint(sh.width() / 2, sh.height() / 2);
    1282         m_pExitButton->hide();
    1283         m_exitButtonSize = m_pExitButton ? m_pExitButton->minimumSizeHint().toSize() : QSize(0, 0);
    1284     }
    1285 #endif
     1292        if (m_pNameEditorWidget)
     1293        {
     1294            m_pNameEditorWidget->setFont(m_nameFont);
     1295            connect(m_pNameEditorWidget, &UIEditorGroupRename::sigEditingFinished,
     1296                    this, &UIChooserItemGroup::sltNameEditingFinished);
     1297        }
     1298    }
    12861299
    12871300    /* Prepare favorite children container: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h

    r77596 r77620  
    2222#endif
    2323
    24 /* Qt includes: */
    25 #include <QPixmap>
    26 #include <QString>
    27 #include <QWidget>
    28 
    2924/* GUI includes: */
    3025#include "UIChooserItem.h"
     
    3227/* Forward declarations: */
    3328class QGraphicsLinearLayout;
    34 class QGraphicsScene;
    35 class QLineEdit;
    36 class QMenu;
    37 class QMimeData;
    38 class QPainter;
    39 class QStyleOptionGraphicsItem;
    4029class UIEditorGroupRename;
    4130class UIGraphicsButton;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r77604 r77620  
    1717
    1818/* Qt includes: */
    19 #include <QGraphicsScene>
    20 #include <QGraphicsSceneMouseEvent>
     19#include <QGraphicsSceneDragDropEvent>
    2120#include <QGraphicsView>
    2221#include <QPainter>
     
    2524
    2625/* GUI includes: */
    27 #include "VBoxGlobal.h"
    2826#include "UIChooserItemGroup.h"
    2927#include "UIChooserItemMachine.h"
    3028#include "UIChooserModel.h"
    31 #include "UIActionPoolManager.h"
    3229#include "UIIconPool.h"
    33 #include "UIImageTools.h"
    3430#include "UIVirtualBoxManager.h"
    35 
    36 /* COM includes: */
    37 #include "COMEnums.h"
    38 #include "CMachine.h"
    3931
    4032/* Other VBox includes: */
     
    9183bool UIChooserItemMachine::isLockedMachine() const
    9284{
    93     KMachineState state = machineState();
    94     return state != KMachineState_PoweredOff &&
    95            state != KMachineState_Saved &&
    96            state != KMachineState_Teleported &&
    97            state != KMachineState_Aborted;
     85    const KMachineState enmState = machineState();
     86    return enmState != KMachineState_PoweredOff &&
     87           enmState != KMachineState_Saved &&
     88           enmState != KMachineState_Teleported &&
     89           enmState != KMachineState_Aborted;
    9890}
    9991
     
    164156    m_strDescription = tr("Virtual Machine");
    165157
    166     /* Update state text: */
    167     updateStateText();
     158    /* Update state text size: */
     159    updateStateTextSize();
    168160
    169161    /* Update machine tool-tip: */
     
    296288    recache();
    297289    updatePixmaps();
    298     updateName();
    299     updateSnapshotName();
    300     updateStateText();
     290    updateMinimumNameWidth();
     291    updateVisibleName();
     292    updateMinimumSnapshotNameWidth();
     293    updateVisibleSnapshotName();
     294    updateStateTextSize();
    301295    updateToolTip();
    302296
     
    379373    /* And machine-item content to take into account: */
    380374    int iTopLineWidth = m_iMinimumNameWidth;
    381     if (!m_strSnapshotName.isEmpty())
     375    if (!snapshotName().isEmpty())
    382376        iTopLineWidth += (iMinorSpacing +
    383377                          m_iMinimumSnapshotNameWidth);
     
    507501                /* Group passed item with current item into the new group: */
    508502                UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(parentItem(),
    509                                                                              UIChooserModel::uniqueGroupName(parentItem()),
    510                                                                              true);
     503                                                                           UIChooserModel::uniqueGroupName(parentItem()),
     504                                                                           true);
    511505                new UIChooserItemMachine(pNewGroupItem, this);
    512506                new UIChooserItemMachine(pNewGroupItem, pItem->toMachineItem());
     
    605599    /* Init: */
    606600    updatePixmaps();
    607     updateName();
    608     updateSnapshotName();
     601    updateMinimumNameWidth();
     602    updateVisibleName();
     603    updateMinimumSnapshotNameWidth();
     604    updateVisibleSnapshotName();
    609605
    610606    /* Apply language settings: */
     
    736732}
    737733
    738 void UIChooserItemMachine::updateName()
    739 {
    740     /* Get new name: */
    741     QString strName = name();
    742 
    743     /* Is there something changed? */
    744     if (m_strName == strName)
    745         return;
    746 
    747     /* Update linked values: */
    748     m_strName = strName;
    749     updateMinimumNameWidth();
    750     updateVisibleName();
    751 }
    752 
    753 void UIChooserItemMachine::updateSnapshotName()
    754 {
    755     /* Get new snapshot-name: */
    756     QString strSnapshotName = snapshotName();
    757 
    758     /* Is there something changed? */
    759     if (m_strSnapshotName == strSnapshotName)
    760         return;
    761 
    762     /* Update linked values: */
    763     m_strSnapshotName = strSnapshotName;
    764     updateMinimumSnapshotNameWidth();
    765     updateVisibleSnapshotName();
    766 }
    767 
    768734void UIChooserItemMachine::updateFirstRowMaximumWidth()
    769735{
     
    803769    QPaintDevice *pPaintDevice = model()->paintDevice();
    804770    QFontMetrics fm(m_nameFont, pPaintDevice);
    805     int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15)));
     771    int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, name(), textWidth(m_nameFont, pPaintDevice, 15)));
    806772
    807773    /* Is there something changed? */
     
    819785    int iMinimumSnapshotNameWidth = 0;
    820786    /* Is there any snapshot exists? */
    821     if (!m_strSnapshotName.isEmpty())
     787    if (!snapshotName().isEmpty())
    822788    {
    823789        QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
    824790        int iBracketWidth = fm.width("()"); /* bracket width */
    825         int iActualTextWidth = fm.width(m_strSnapshotName); /* snapshot-name width */
     791        int iActualTextWidth = fm.width(snapshotName()); /* snapshot-name width */
    826792        int iMinimumTextWidth = fm.width("..."); /* ellipsis width */
    827793        iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
     
    884850
    885851    /* Calculate new visible name and name-size: */
    886     QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
     852    QString strVisibleName = compressText(m_nameFont, pPaintDevice, name(), m_iMaximumNameWidth);
    887853    QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName);
    888854
     
    908874    /* Calculate new visible snapshot-name: */
    909875    int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()");
    910     QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, m_strSnapshotName,
     876    QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, snapshotName(),
    911877                                                  m_iMaximumSnapshotNameWidth - iBracketWidth);
    912878    strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName);
     
    926892}
    927893
    928 void UIChooserItemMachine::updateStateText()
     894void UIChooserItemMachine::updateStateTextSize()
    929895{
    930896    /* Get new state-text and state-text size: */
    931     QString strStateText = machineStateName();
    932     QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), m_strStateText);
     897    const QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), machineStateName());
    933898
    934899    /* Update linked values: */
     
    937902        m_stateTextSize = stateTextSize;
    938903        updateGeometry();
    939     }
    940     if (m_strStateText != strStateText)
    941     {
    942         m_strStateText = strStateText;
    943         update();
    944904    }
    945905}
     
    12761236                          model()->paintDevice(),
    12771237                          /* Text to paint: */
    1278                           m_strStateText);
     1238                          machineStateName());
    12791239            }
    12801240        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h

    r77596 r77620  
    2222#endif
    2323
    24 /* Qt includes */
    25 #include <QUuid>
    26 
    2724/* GUI includes: */
    2825#include "UIVirtualMachineItem.h"
    2926#include "UIChooserItem.h"
    30 
    31 /* Forward declarations: */
    32 class CMachine;
    3327
    3428/** UIChooserItem extension implementing machine item. */
     
    108102        /** Updates item tool-tip. */
    109103        virtual void updateToolTip() /* override */;
    110 
    111104    /** @} */
    112105
     
    234227        /** Updates tool pixmap. */
    235228        void updateToolPixmap();
    236         /** Updates name. */
    237         void updateName();
    238         /** Updates snapshot name. */
    239         void updateSnapshotName();
    240229        /** Updates first row maximum width. */
    241230        void updateFirstRowMaximumWidth();
     
    252241        /** Updates visible snapshot name. */
    253242        void updateVisibleSnapshotName();
    254         /** Updates state text. */
    255         void updateStateText();
     243        /** Updates state text size. */
     244        void updateStateTextSize();
    256245    /** @} */
    257246
     
    298287        QPixmap  m_toolPixmap;
    299288
    300         /** Holds item name. */
    301         QString  m_strName;
    302289        /** Holds item description. */
    303290        QString  m_strDescription;
    304291        /** Holds item visible name. */
    305292        QString  m_strVisibleName;
    306         /** Holds item snapshot name. */
    307         QString  m_strSnapshotName;
    308293        /** Holds item visible snapshot name. */
    309294        QString  m_strVisibleSnapshotName;
    310         /** Holds item state text. */
    311         QString  m_strStateText;
    312295
    313296        /** Holds item name font. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r77605 r77620  
    20652065    foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Machine))
    20662066        orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pItem->toMachineItem()->id()));
    2067     }
     2067}
    20682068
    20692069void UIChooserModel::makeSureGroupDefinitionsSaveIsFinished()
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