VirtualBox

Changeset 73600 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 9, 2018 6:02:16 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: VirtualBox Manager UI: Chooser pane: Invent global item meaning, wrap it up.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r73492 r73600  
    761761        src/manager/chooser/UIChooserItem.h \
    762762        src/manager/chooser/UIChooserItemGroup.h \
     763        src/manager/chooser/UIChooserItemGlobal.h \
    763764        src/manager/chooser/UIChooserItemMachine.h \
    764765        src/manager/details/UIDetails.h \
     
    14381439        src/manager/chooser/UIChooserItem.cpp \
    14391440        src/manager/chooser/UIChooserItemGroup.cpp \
     1441        src/manager/chooser/UIChooserItemGlobal.cpp \
    14401442        src/manager/chooser/UIChooserItemMachine.cpp \
    14411443        src/manager/details/UIDetails.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.cpp

    r73492 r73600  
    7272}
    7373
    74 UIVirtualMachineItem* UIChooser::currentItem() const
     74bool UIChooser::isGlobalItemSelected() const
     75{
     76    return m_pChooserModel->isGlobalItemSelected();
     77}
     78
     79bool UIChooser::isMachineItemSelected() const
     80{
     81    return m_pChooserModel->isMachineItemSelected();
     82}
     83
     84UIVirtualMachineItem *UIChooser::currentItem() const
    7585{
    7686    return m_pChooserModel->currentMachineItem();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.h

    r73492 r73600  
    7171
    7272    /* API: Current-item stuff: */
    73     UIVirtualMachineItem* currentItem() const;
     73    bool isGlobalItemSelected() const;
     74    bool isMachineItemSelected() const;
     75    UIVirtualMachineItem *currentItem() const;
    7476    QList<UIVirtualMachineItem*> currentItems() const;
    7577    bool isSingleGroupSelected() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserHandlerKeyboard.cpp

    r73424 r73600  
    268268                {
    269269                    case UIChooserItemType_Group:
     270                    case UIChooserItemType_Global:
    270271                    case UIChooserItemType_Machine:
    271272                    {
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserHandlerMouse.cpp

    r73424 r73600  
    2727# include "UIChooserModel.h"
    2828# include "UIChooserItemGroup.h"
     29# include "UIChooserItemGlobal.h"
    2930# include "UIChooserItemMachine.h"
    3031
     
    7374                if (UIChooserItemGroup *pGroupItem = qgraphicsitem_cast<UIChooserItemGroup*>(pItemUnderMouse))
    7475                    pClickedItem = pGroupItem;
     76                /* Or a global one? */
     77                else if (UIChooserItemGlobal *pGlobalItem = qgraphicsitem_cast<UIChooserItemGlobal*>(pItemUnderMouse))
     78                    pClickedItem = pGlobalItem;
    7579                /* Or a machine one? */
    7680                else if (UIChooserItemMachine *pMachineItem = qgraphicsitem_cast<UIChooserItemMachine*>(pItemUnderMouse))
     
    128132                if (UIChooserItemGroup *pGroupItem = qgraphicsitem_cast<UIChooserItemGroup*>(pItemUnderMouse))
    129133                    pClickedItem = pGroupItem;
     134                /* Or a global one? */
     135                else if (UIChooserItemGlobal *pGlobalItem = qgraphicsitem_cast<UIChooserItemGlobal*>(pItemUnderMouse))
     136                    pClickedItem = pGlobalItem;
    130137                /* Or a machine one? */
    131138                else if (UIChooserItemMachine *pMachineItem = qgraphicsitem_cast<UIChooserItemMachine*>(pItemUnderMouse))
     
    211218                else if (pItemUnderMouse->type() == UIChooserItemType_Machine)
    212219                {
    213                     /* Activate machine item: */
     220                    /* Activate machine-item: */
    214221                    model()->activateMachineItem();
    215222                }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp

    r73424 r73600  
    3939# include "UIChooserModel.h"
    4040# include "UIChooserItemGroup.h"
     41# include "UIChooserItemGlobal.h"
    4142# include "UIChooserItemMachine.h"
    4243
     
    265266}
    266267
     268UIChooserItemGlobal* UIChooserItem::toGlobalItem()
     269{
     270    UIChooserItemGlobal *pItem = qgraphicsitem_cast<UIChooserItemGlobal*>(this);
     271    AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemGlobal!"));
     272    return pItem;
     273}
     274
    267275UIChooserItemMachine* UIChooserItem::toMachineItem()
    268276{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h

    r73424 r73600  
    2121/* Qt includes: */
    2222#include <QMimeData>
     23#include <QString>
    2324
    2425/* GUI includes: */
     
    3334class UIChooserModel;
    3435class UIChooserItemGroup;
     36class UIChooserItemGlobal;
    3537class UIChooserItemMachine;
    3638class QGraphicsSceneHoverEvent;
     
    4345enum UIChooserItemType
    4446{
    45     UIChooserItemType_Any     = QGraphicsItem::UserType,
    46     UIChooserItemType_Group   = QGraphicsItem::UserType + 1,
    47     UIChooserItemType_Machine = QGraphicsItem::UserType + 2
     47    UIChooserItemType_Any = QGraphicsItem::UserType,
     48    UIChooserItemType_Group,
     49    UIChooserItemType_Global,
     50    UIChooserItemType_Machine
    4851};
    4952
     
    5255{
    5356    UIChooserItemSearchFlag_Machine   = RT_BIT(0),
    54     UIChooserItemSearchFlag_Group     = RT_BIT(1),
    55     UIChooserItemSearchFlag_ExactName = RT_BIT(2)
     57    UIChooserItemSearchFlag_Global    = RT_BIT(1),
     58    UIChooserItemSearchFlag_Group     = RT_BIT(2),
     59    UIChooserItemSearchFlag_ExactName = RT_BIT(3)
    5660};
    5761
     
    8286
    8387    /* API: Cast stuff: */
    84     UIChooserItemGroup* toGroupItem();
    85     UIChooserItemMachine* toMachineItem();
     88    UIChooserItemGroup *toGroupItem();
     89    UIChooserItemGlobal *toGlobalItem();
     90    UIChooserItemMachine *toMachineItem();
    8691
    8792    /* API: Model stuff: */
     
    118123    virtual void removeAll(const QString &strId) = 0;
    119124    virtual UIChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags) = 0;
    120     virtual UIChooserItemMachine* firstMachineItem() = 0;
     125    virtual UIChooserItem* firstMachineItem() = 0;
    121126    virtual void sortItems() = 0;
    122127
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp

    r73555 r73600  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIChooserItemMachine class implementation.
     3 * VBox Qt GUI - UIChooserItemGlobal class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727/* GUI includes: */
    2828# include "VBoxGlobal.h"
    29 # include "UIChooserItemGroup.h"
    30 # include "UIChooserItemMachine.h"
     29# include "UIChooserItemGlobal.h"
    3130# include "UIChooserModel.h"
    32 # include "UIGraphicsToolBar.h"
    33 # include "UIActionPoolSelector.h"
    34 # include "UIGraphicsZoomButton.h"
    3531# include "UIIconPool.h"
    36 # include "UIImageTools.h"
     32//# include "UIImageTools.h"
    3733# include "UIVirtualBoxManager.h"
    3834
    39 /* COM includes: */
    40 # include "COMEnums.h"
    41 # include "CMachine.h"
    42 
    4335#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4436
    4537
    46 /* static */
    47 QString UIChooserItemMachine::className() { return "UIChooserItemMachine"; }
    48 
    49 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent,
    50                                              const CMachine &machine,
    51                                              int iPosition /* = -1 */)
     38UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent,
     39                                         int iPosition /* = -1 */)
    5240    : UIChooserItem(pParent, pParent->isTemporary())
    53     , UIVirtualMachineItem(machine)
    5441{
    5542    /* Prepare: */
     
    5744
    5845    /* Add item to the parent: */
    59     AssertMsg(parentItem(), ("No parent set for machine-item!"));
     46    AssertMsg(parentItem(), ("No parent set for global-item!"));
    6047    parentItem()->addItem(this, iPosition);
    6148    setZValue(parentItem()->zValue() + 1);
     
    6350    /* Configure connections: */
    6451    connect(gpManager, &UIVirtualBoxManager::sigWindowRemapped,
    65             this, &UIChooserItemMachine::sltHandleWindowRemapped);
     52            this, &UIChooserItemGlobal::sltHandleWindowRemapped);
    6653
    6754    /* Init: */
    68     updatePixmaps();
    69     updateName();
    70     updateSnapshotName();
     55    updatePixmap();
    7156
    7257    /* Translate finally: */
     
    7459}
    7560
    76 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent,
    77                                              UIChooserItemMachine *pCopyFrom,
    78                                              int iPosition /* = -1 */)
     61UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent,
     62                                         UIChooserItemGlobal * ,
     63                                         int iPosition /* = -1 */)
    7964    : UIChooserItem(pParent, pParent->isTemporary())
    80     , UIVirtualMachineItem(pCopyFrom->machine())
    8165{
    8266    /* Prepare: */
     
    8468
    8569    /* Add item to the parent: */
    86     AssertMsg(parentItem(), ("No parent set for machine-item!"));
     70    AssertMsg(parentItem(), ("No parent set for global-item!"));
    8771    parentItem()->addItem(this, iPosition);
    8872    setZValue(parentItem()->zValue() + 1);
     
    9074    /* Configure connections: */
    9175    connect(gpManager, &UIVirtualBoxManager::sigWindowRemapped,
    92             this, &UIChooserItemMachine::sltHandleWindowRemapped);
     76            this, &UIChooserItemGlobal::sltHandleWindowRemapped);
    9377
    9478    /* Init: */
    95     updatePixmaps();
    96     updateName();
    97     updateSnapshotName();
     79    updatePixmap();
    9880
    9981    /* Translate finally: */
     
    10183}
    10284
    103 UIChooserItemMachine::~UIChooserItemMachine()
     85UIChooserItemGlobal::~UIChooserItemGlobal()
    10486{
    10587    /* If that item is focused: */
     
    123105
    124106    /* Remove item from the parent: */
    125     AssertMsg(parentItem(), ("No parent set for machine-item!"));
     107    AssertMsg(parentItem(), ("No parent set for global-item!"));
    126108    parentItem()->removeItem(this);
    127109}
    128110
    129 QString UIChooserItemMachine::name() const
    130 {
    131     return UIVirtualMachineItem::name();
    132 }
    133 
    134 QString UIChooserItemMachine::description() const
     111QString UIChooserItemGlobal::name() const
     112{
     113    return m_strName;
     114}
     115
     116QString UIChooserItemGlobal::description() const
    135117{
    136118    return m_strDescription;
    137119}
    138120
    139 QString UIChooserItemMachine::fullName() const
    140 {
    141     /* Get full parent name, append with '/' if not yet appended: */
    142     AssertMsg(parentItem(), ("Incorrect parent set!"));
    143     QString strFullParentName = parentItem()->fullName();
    144     if (!strFullParentName.endsWith('/'))
    145         strFullParentName.append('/');
    146     /* Return full item name based on parent prefix: */
    147     return strFullParentName + name();
    148 }
    149 
    150 QString UIChooserItemMachine::definition() const
    151 {
    152     return QString("m=%1").arg(name());
    153 }
    154 
    155 bool UIChooserItemMachine::isLockedMachine() const
    156 {
    157     KMachineState state = machineState();
    158     return state != KMachineState_PoweredOff &&
    159            state != KMachineState_Saved &&
    160            state != KMachineState_Teleported &&
    161            state != KMachineState_Aborted;
    162 }
    163 
    164 /* static */
    165 void UIChooserItemMachine::enumerateMachineItems(const QList<UIChooserItem*> &il,
    166                                                   QList<UIChooserItemMachine*> &ol,
    167                                                   int iEnumerationFlags /* = 0 */)
    168 {
    169     /* Enumerate all the passed items: */
    170     foreach (UIChooserItem *pItem, il)
    171     {
    172         /* If that is machine-item: */
    173         if (pItem->type() == UIChooserItemType_Machine)
    174         {
    175             /* Get the iterated machine-item: */
    176             UIChooserItemMachine *pMachineItem = pItem->toMachineItem();
    177             /* Skip if exactly this item is already enumerated: */
    178             if (ol.contains(pMachineItem))
    179                 continue;
    180             /* Skip if item with same ID is already enumerated but we need unique: */
    181             if ((iEnumerationFlags & UIChooserItemMachineEnumerationFlag_Unique) &&
    182                 contains(ol, pMachineItem))
    183                 continue;
    184             /* Skip if this item is accessible and we no need it: */
    185             if ((iEnumerationFlags & UIChooserItemMachineEnumerationFlag_Inaccessible) &&
    186                 pMachineItem->accessible())
    187                 continue;
    188             /* Add it: */
    189             ol << pMachineItem;
    190         }
    191         /* If that is group-item: */
    192         else if (pItem->type() == UIChooserItemType_Group)
    193         {
    194             /* Enumerate all the machine-items recursively: */
    195             enumerateMachineItems(pItem->items(UIChooserItemType_Machine), ol, iEnumerationFlags);
    196             /* Enumerate all the group-items recursively: */
    197             enumerateMachineItems(pItem->items(UIChooserItemType_Group), ol, iEnumerationFlags);
    198         }
    199     }
    200 }
    201 
    202 void UIChooserItemMachine::sltHandleWindowRemapped()
    203 {
    204     /* Recache and update pixmaps: */
    205     recachePixmap();
    206     updatePixmaps();
    207 }
    208 
    209 QVariant UIChooserItemMachine::data(int iKey) const
     121QString UIChooserItemGlobal::fullName() const
     122{
     123    return m_strName;
     124}
     125
     126QString UIChooserItemGlobal::definition() const
     127{
     128    return QString("n=%1").arg(name());
     129}
     130
     131void UIChooserItemGlobal::sltHandleWindowRemapped()
     132{
     133    updatePixmap();
     134}
     135
     136QVariant UIChooserItemGlobal::data(int iKey) const
    210137{
    211138    /* Provide other members with required data: */
     
    213140    {
    214141        /* Layout hints: */
    215         case MachineItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
    216         case MachineItemData_MajorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
    217         case MachineItemData_MinorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
    218         case MachineItemData_TextSpacing: return 0;
    219 
    220         /* Pixmaps: */
    221         case MachineItemData_SettingsButtonPixmap: return UIIconPool::iconSet(":/vm_settings_16px.png");
    222         case MachineItemData_StartButtonPixmap: return UIIconPool::iconSet(":/vm_start_16px.png");
    223         case MachineItemData_PauseButtonPixmap: return UIIconPool::iconSet(":/vm_pause_16px.png");
    224         case MachineItemData_CloseButtonPixmap: return UIIconPool::iconSet(":/exit_16px.png");
    225 
    226         /* Sizes: */
    227         case MachineItemData_ToolBarSize: return m_pToolBar ? m_pToolBar->minimumSizeHint().toSize() : QSize(0, 0);
     142        case GlobalItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     143        case GlobalItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
    228144
    229145        /* Default: */
     
    233149}
    234150
    235 void UIChooserItemMachine::updatePixmaps()
    236 {
    237     /* Update pixmap: */
    238     updatePixmap();
    239 
    240     /* Update state-pixmap: */
    241     updateStatePixmap();
    242 }
    243 
    244 void UIChooserItemMachine::updatePixmap()
    245 {
    246     /* Get new pixmap and pixmap-size: */
    247     QSize pixmapSize;
    248     QPixmap pixmap = osPixmap(&pixmapSize);
     151void UIChooserItemGlobal::updatePixmap()
     152{
     153    /* Acquire new metric, then compose pixmap-size: */
     154    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     155    const QSize pixmapSize = QSize(iMetric, iMetric);
     156
     157    /* Create new icon, then acquire pixmap: */
     158    const QIcon icon = UIIconPool::iconSet(":/tools_global_32px.png");
     159    const QPixmap pixmap = icon.pixmap(gpManager->windowHandle(), pixmapSize);
     160
    249161    /* Update linked values: */
    250162    if (m_pixmapSize != pixmapSize)
    251163    {
    252164        m_pixmapSize = pixmapSize;
    253         updateFirstRowMaximumWidth();
     165        updateMaximumNameWidth();
    254166        updateGeometry();
    255167    }
     
    261173}
    262174
    263 void UIChooserItemMachine::updateStatePixmap()
    264 {
    265     /* Determine the icon metric: */
    266     const QStyle *pStyle = QApplication::style();
    267     const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    268     /* Get new state-pixmap and state-pixmap size: */
    269     const QIcon stateIcon = machineStateIcon();
    270     AssertReturnVoid(!stateIcon.isNull());
    271     const QSize statePixmapSize = QSize(iIconMetric, iIconMetric);
    272     const QPixmap statePixmap = stateIcon.pixmap(gpManager->windowHandle(), statePixmapSize);
    273     /* Update linked values: */
    274     if (m_statePixmapSize != statePixmapSize)
    275     {
    276         m_statePixmapSize = statePixmapSize;
    277         updateGeometry();
    278     }
    279     if (m_statePixmap.toImage() != statePixmap.toImage())
    280     {
    281         m_statePixmap = statePixmap;
    282         update();
    283     }
    284 }
    285 
    286 void UIChooserItemMachine::updateName()
    287 {
    288     /* Get new name: */
    289     QString strName = name();
    290 
    291     /* Is there something changed? */
    292     if (m_strName == strName)
    293         return;
    294 
    295     /* Update linked values: */
    296     m_strName = strName;
    297     updateMinimumNameWidth();
    298     updateVisibleName();
    299 }
    300 
    301 void UIChooserItemMachine::updateSnapshotName()
    302 {
    303     /* Get new snapshot-name: */
    304     QString strSnapshotName = snapshotName();
    305 
    306     /* Is there something changed? */
    307     if (m_strSnapshotName == strSnapshotName)
    308         return;
    309 
    310     /* Update linked values: */
    311     m_strSnapshotName = strSnapshotName;
    312     updateMinimumSnapshotNameWidth();
    313     updateVisibleSnapshotName();
    314 }
    315 
    316 void UIChooserItemMachine::updateFirstRowMaximumWidth()
    317 {
    318     /* Prepare variables: */
    319     int iMargin = data(MachineItemData_Margin).toInt();
    320     int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt();
    321     int iToolBarWidth = data(MachineItemData_ToolBarSize).toSize().width();
    322 
    323     /* Calculate new maximum width for the first row: */
    324     int iFirstRowMaximumWidth = (int)geometry().width();
    325     iFirstRowMaximumWidth -= iMargin; /* left margin */
    326     iFirstRowMaximumWidth -= m_pixmapSize.width(); /* pixmap width */
    327     iFirstRowMaximumWidth -= iMajorSpacing; /* spacing between pixmap and name(s) */
    328     if (m_pToolBar)
    329     {
    330         iFirstRowMaximumWidth -= iMajorSpacing; /* spacing before toolbar */
    331         iFirstRowMaximumWidth -= iToolBarWidth; /* toolbar width */
    332     }
    333     iFirstRowMaximumWidth -= iMargin; /* right margin */
    334 
    335     /* Is there something changed? */
    336     if (m_iFirstRowMaximumWidth == iFirstRowMaximumWidth)
    337         return;
    338 
    339     /* Update linked values: */
    340     m_iFirstRowMaximumWidth = iFirstRowMaximumWidth;
    341     updateMaximumNameWidth();
    342     updateMaximumSnapshotNameWidth();
    343 }
    344 
    345 void UIChooserItemMachine::updateMinimumNameWidth()
     175void UIChooserItemGlobal::updateMinimumNameWidth()
    346176{
    347177    /* Calculate new minimum name width: */
    348178    QPaintDevice *pPaintDevice = model()->paintDevice();
    349     QFontMetrics fm(m_nameFont, pPaintDevice);
    350     int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15)));
     179    const QFontMetrics fm(m_nameFont, pPaintDevice);
     180    const int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15)));
    351181
    352182    /* Is there something changed? */
     
    359189}
    360190
    361 void UIChooserItemMachine::updateMinimumSnapshotNameWidth()
    362 {
    363     /* Calculate new minimum snapshot-name width: */
    364     int iMinimumSnapshotNameWidth = 0;
    365     /* Is there any snapshot exists? */
    366     if (!m_strSnapshotName.isEmpty())
    367     {
    368         QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
    369         int iBracketWidth = fm.width("()"); /* bracket width */
    370         int iActualTextWidth = fm.width(m_strSnapshotName); /* snapshot-name width */
    371         int iMinimumTextWidth = fm.width("..."); /* ellipsis width */
    372         iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
    373     }
    374 
    375     /* Is there something changed? */
    376     if (m_iMinimumSnapshotNameWidth == iMinimumSnapshotNameWidth)
    377         return;
    378 
    379     /* Update linked values: */
    380     m_iMinimumSnapshotNameWidth = iMinimumSnapshotNameWidth;
    381     updateMaximumNameWidth();
    382     updateGeometry();
    383 }
    384 
    385 void UIChooserItemMachine::updateMaximumNameWidth()
    386 {
     191void UIChooserItemGlobal::updateMaximumNameWidth()
     192{
     193    /* Prepare variables: */
     194    const int iMargin = data(GlobalItemData_Margin).toInt();
     195    const int iSpacing = data(GlobalItemData_Spacing).toInt();
     196
    387197    /* Calculate new maximum name width: */
    388     int iMaximumNameWidth = m_iFirstRowMaximumWidth;
    389     /* Do we have a minimum snapshot-name width? */
    390     if (m_iMinimumSnapshotNameWidth != 0)
    391     {
    392         /* Prepare variables: */
    393         int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
    394         /* Take spacing and snapshot-name into account: */
    395         iMaximumNameWidth -= (iMinorSpacing + m_iMinimumSnapshotNameWidth);
    396     }
     198    int iMaximumNameWidth = (int)geometry().width();
     199    iMaximumNameWidth -= iMargin; /* left margin */
     200    iMaximumNameWidth -= m_pixmapSize.width(); /* pixmap width */
     201    iMaximumNameWidth -= iSpacing; /* spacing between pixmap and name */
     202    iMaximumNameWidth -= iMargin; /* right margin */
    397203
    398204    /* Is there something changed? */
     
    405211}
    406212
    407 void UIChooserItemMachine::updateMaximumSnapshotNameWidth()
    408 {
    409     /* Prepare variables: */
    410     int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
    411 
    412     /* Calculate new maximum snapshot-name width: */
    413     int iMaximumSnapshotNameWidth = m_iFirstRowMaximumWidth;
    414     iMaximumSnapshotNameWidth -= (iMinorSpacing + m_visibleNameSize.width());
    415 
    416     /* Is there something changed? */
    417     if (m_iMaximumSnapshotNameWidth == iMaximumSnapshotNameWidth)
    418         return;
    419 
    420     /* Update linked values: */
    421     m_iMaximumSnapshotNameWidth = iMaximumSnapshotNameWidth;
    422     updateVisibleSnapshotName();
    423 }
    424 
    425 void UIChooserItemMachine::updateVisibleName()
     213void UIChooserItemGlobal::updateVisibleName()
    426214{
    427215    /* Prepare variables: */
     
    429217
    430218    /* Calculate new visible name and name-size: */
    431     QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
    432     QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName);
     219    const QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
     220    const QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName);
    433221
    434222    /* Update linked values: */
     
    436224    {
    437225        m_visibleNameSize = visibleNameSize;
    438         updateMaximumSnapshotNameWidth();
    439226        updateGeometry();
    440227    }
     
    446233}
    447234
    448 void UIChooserItemMachine::updateVisibleSnapshotName()
    449 {
    450     /* Prepare variables: */
    451     QPaintDevice *pPaintDevice = model()->paintDevice();
    452 
    453     /* Calculate new visible snapshot-name: */
    454     int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()");
    455     QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, m_strSnapshotName,
    456                                                   m_iMaximumSnapshotNameWidth - iBracketWidth);
    457     strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName);
    458     QSize visibleSnapshotNameSize = textSize(m_snapshotNameFont, pPaintDevice, strVisibleSnapshotName);
     235void UIChooserItemGlobal::retranslateUi()
     236{
     237    /* Update description: */
     238    m_strName = tr("Global Tools");
     239    m_strDescription = m_strName;
    459240
    460241    /* Update linked values: */
    461     if (m_visibleSnapshotNameSize != visibleSnapshotNameSize)
    462     {
    463         m_visibleSnapshotNameSize = visibleSnapshotNameSize;
    464         updateGeometry();
    465     }
    466     if (m_strVisibleSnapshotName != strVisibleSnapshotName)
    467     {
    468         m_strVisibleSnapshotName = strVisibleSnapshotName;
    469         update();
    470     }
    471 }
    472 
    473 void UIChooserItemMachine::updateStateText()
    474 {
    475     /* Get new state-text and state-text size: */
    476     QString strStateText = machineStateName();
    477     QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), m_strStateText);
    478 
    479     /* Update linked values: */
    480     if (m_stateTextSize != stateTextSize)
    481     {
    482         m_stateTextSize = stateTextSize;
    483         updateGeometry();
    484     }
    485     if (m_strStateText != strStateText)
    486     {
    487         m_strStateText = strStateText;
    488         update();
    489     }
    490 }
    491 
    492 void UIChooserItemMachine::retranslateUi()
    493 {
    494     /* Update description: */
    495     m_strDescription = tr("Virtual Machine");
    496 
    497     /* Update state text: */
    498     updateStateText();
    499 
    500     /* Update machine tool-tip: */
     242    updateMinimumNameWidth();
     243    updateVisibleName();
     244
     245    /* Update tool-tip: */
    501246    updateToolTip();
    502247}
    503248
    504 void UIChooserItemMachine::startEditing()
    505 {
    506     AssertMsgFailed(("Machine graphics item do NOT support editing yet!"));
    507 }
    508 
    509 void UIChooserItemMachine::updateToolTip()
    510 {
    511     setToolTip(toolTipText());
    512 }
    513 
    514 void UIChooserItemMachine::addItem(UIChooserItem*, int)
    515 {
    516     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    517 }
    518 
    519 void UIChooserItemMachine::removeItem(UIChooserItem*)
    520 {
    521     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    522 }
    523 
    524 void UIChooserItemMachine::setItems(const QList<UIChooserItem*>&, UIChooserItemType)
    525 {
    526     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    527 }
    528 
    529 QList<UIChooserItem*> UIChooserItemMachine::items(UIChooserItemType) const
    530 {
    531     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    532     return QList<UIChooserItem*>();
    533 }
    534 
    535 bool UIChooserItemMachine::hasItems(UIChooserItemType) const
    536 {
    537     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    538     return false;
    539 }
    540 
    541 void UIChooserItemMachine::clearItems(UIChooserItemType)
    542 {
    543     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    544 }
    545 
    546 void UIChooserItemMachine::updateAll(const QString &strId)
    547 {
    548     /* Skip other ids: */
    549     if (id() != strId)
    550         return;
    551 
    552     /* Update this machine-item: */
    553     recache();
    554     updatePixmaps();
    555     updateName();
    556     updateSnapshotName();
    557     updateStateText();
     249void UIChooserItemGlobal::startEditing()
     250{
     251    AssertMsgFailed(("Global graphics item do NOT support editing yet!"));
     252}
     253
     254void UIChooserItemGlobal::updateToolTip()
     255{
     256//    setToolTip(toolTipText());
     257}
     258
     259void UIChooserItemGlobal::addItem(UIChooserItem*, int)
     260{
     261    AssertMsgFailed(("Global graphics item do NOT support children!"));
     262}
     263
     264void UIChooserItemGlobal::removeItem(UIChooserItem*)
     265{
     266    AssertMsgFailed(("Global graphics item do NOT support children!"));
     267}
     268
     269void UIChooserItemGlobal::setItems(const QList<UIChooserItem*>&, UIChooserItemType)
     270{
     271    AssertMsgFailed(("Global graphics item do NOT support children!"));
     272}
     273
     274QList<UIChooserItem*> UIChooserItemGlobal::items(UIChooserItemType) const
     275{
     276    AssertMsgFailedReturn(("Global graphics item do NOT support children!"), QList<UIChooserItem*>());
     277}
     278
     279bool UIChooserItemGlobal::hasItems(UIChooserItemType) const
     280{
     281    AssertMsgFailedReturn(("Global graphics item do NOT support children!"), false);
     282}
     283
     284void UIChooserItemGlobal::clearItems(UIChooserItemType)
     285{
     286    AssertMsgFailed(("Global graphics item do NOT support children!"));
     287}
     288
     289void UIChooserItemGlobal::updateAll(const QString &)
     290{
     291    /* Update this global-item: */
     292    updatePixmap();
    558293    updateToolTip();
    559294
     
    563298}
    564299
    565 void UIChooserItemMachine::removeAll(const QString &strId)
    566 {
    567     /* Skip wrong id: */
    568     if (id() != strId)
    569         return;
    570 
    571     /* Exclude itself from the current items: */
    572     if (model()->currentItems().contains(this))
    573         model()->removeFromCurrentItems(this);
    574     /* Move the focus item to the first available current after that: */
    575     if (model()->focusItem() == this && !model()->currentItems().isEmpty())
    576         model()->setFocusItem(model()->currentItems().first());
    577 
    578     /* Remove item: */
    579     delete this;
    580 }
    581 
    582 UIChooserItem* UIChooserItemMachine::searchForItem(const QString &strSearchTag, int iItemSearchFlags)
    583 {
    584     /* Ignoring if we are not searching for the machine-item? */
    585     if (!(iItemSearchFlags & UIChooserItemSearchFlag_Machine))
     300void UIChooserItemGlobal::removeAll(const QString &)
     301{
     302    AssertMsgFailed(("Global graphics item do NOT support deleting!"));
     303}
     304
     305UIChooserItem *UIChooserItemGlobal::searchForItem(const QString &, int iItemSearchFlags)
     306{
     307    /* Ignoring if we are not searching for the global-item? */
     308    if (!(iItemSearchFlags & UIChooserItemSearchFlag_Global))
    586309        return 0;
    587 
    588     /* Are we searching by the exact name? */
    589     if (iItemSearchFlags & UIChooserItemSearchFlag_ExactName)
    590     {
    591         /* Exact name doesn't match? */
    592         if (name() != strSearchTag)
    593             return 0;
    594     }
    595     /* Are we searching by the few first symbols? */
    596     else
    597     {
    598         /* Name doesn't start with passed symbols? */
    599         if (!name().startsWith(strSearchTag, Qt::CaseInsensitive))
    600             return 0;
    601     }
    602310
    603311    /* Returning this: */
     
    605313}
    606314
    607 UIChooserItemMachine* UIChooserItemMachine::firstMachineItem()
    608 {
    609     return this;
    610 }
    611 
    612 void UIChooserItemMachine::sortItems()
    613 {
    614     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    615 }
    616 
    617 void UIChooserItemMachine::updateLayout()
    618 {
    619     /* Update tool-bar: */
    620     if (m_pToolBar)
    621     {
    622         /* Prepare variables: */
    623         QSize size = geometry().size().toSize();
    624 
    625         /* Prepare variables: */
    626         int iMachineItemWidth = size.width();
    627         int iMachineItemHeight = size.height();
    628         int iToolBarHeight = data(MachineItemData_ToolBarSize).toSize().height();
    629 
    630         /* Configure tool-bar: */
    631         QSize toolBarSize = m_pToolBar->minimumSizeHint().toSize();
    632         int iToolBarX = iMachineItemWidth - 1 - toolBarSize.width();
    633         int iToolBarY = (iMachineItemHeight - iToolBarHeight) / 2;
    634         m_pToolBar->setPos(iToolBarX, iToolBarY);
    635         m_pToolBar->resize(toolBarSize);
    636         m_pToolBar->updateLayout();
    637 
    638         /* Configure buttons: */
    639         m_pStartButton->updateAnimation();
    640         m_pSettingsButton->updateAnimation();
    641         m_pCloseButton->updateAnimation();
    642         m_pPauseButton->updateAnimation();
    643     }
    644 }
    645 
    646 int UIChooserItemMachine::minimumWidthHint() const
     315UIChooserItem *UIChooserItemGlobal::firstMachineItem()
     316{
     317    return 0;
     318}
     319
     320void UIChooserItemGlobal::sortItems()
     321{
     322    AssertMsgFailed(("Global graphics item do NOT support children!"));
     323}
     324
     325int UIChooserItemGlobal::minimumWidthHint() const
    647326{
    648327    /* Prepare variables: */
    649     int iMargin = data(MachineItemData_Margin).toInt();
    650     int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt();
    651     int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
    652     int iToolBarWidth = data(MachineItemData_ToolBarSize).toSize().width();
     328    int iMargin = data(GlobalItemData_Margin).toInt();
     329    int iSpacing = data(GlobalItemData_Spacing).toInt();
    653330
    654331    /* Calculating proposed width: */
     
    657334    /* Two margins: */
    658335    iProposedWidth += 2 * iMargin;
    659     /* And machine-item content to take into account: */
    660     int iTopLineWidth = m_iMinimumNameWidth;
    661     if (!m_strSnapshotName.isEmpty())
    662         iTopLineWidth += (iMinorSpacing +
    663                           m_iMinimumSnapshotNameWidth);
    664     int iBottomLineWidth = m_statePixmapSize.width() +
    665                            iMinorSpacing +
    666                            m_stateTextSize.width();
    667     int iRightColumnWidth = qMax(iTopLineWidth, iBottomLineWidth);
    668     int iMachineItemWidth = m_pixmapSize.width() +
    669                             iMajorSpacing +
    670                             iRightColumnWidth;
    671     if (m_pToolBar)
    672         iMachineItemWidth += (iMajorSpacing + iToolBarWidth);
    673     iProposedWidth += iMachineItemWidth;
     336    /* And global-item content to take into account: */
     337    iProposedWidth += (m_pixmapSize.width() +
     338                       iSpacing +
     339                       m_iMinimumNameWidth);
    674340
    675341    /* Return result: */
     
    677343}
    678344
    679 int UIChooserItemMachine::minimumHeightHint() const
     345int UIChooserItemGlobal::minimumHeightHint() const
    680346{
    681347    /* Prepare variables: */
    682     int iMargin = data(MachineItemData_Margin).toInt();
    683     int iMachineItemTextSpacing = data(MachineItemData_TextSpacing).toInt();
    684     int iToolBarHeight = data(MachineItemData_ToolBarSize).toSize().height();
     348    int iMargin = data(GlobalItemData_Margin).toInt();
    685349
    686350    /* Calculating proposed height: */
     
    689353    /* Two margins: */
    690354    iProposedHeight += 2 * iMargin;
    691     /* And machine-item content to take into account: */
    692     int iTopLineHeight = qMax(m_visibleNameSize.height(), m_visibleSnapshotNameSize.height());
    693     int iBottomLineHeight = qMax(m_statePixmapSize.height(), m_stateTextSize.height());
    694     int iRightColumnHeight = iTopLineHeight +
    695                              iMachineItemTextSpacing +
    696                              iBottomLineHeight;
    697     QList<int> heights;
    698     heights << m_pixmapSize.height() << iRightColumnHeight << iToolBarHeight;
    699     int iMaxHeight = 0;
    700     foreach (int iHeight, heights)
    701         iMaxHeight = qMax(iMaxHeight, iHeight);
    702     iProposedHeight += iMaxHeight;
     355    /* And global-item content to take into account: */
     356    iProposedHeight += qMax(m_pixmapSize.height(), m_visibleNameSize.height());
    703357
    704358    /* Return result: */
     
    706360}
    707361
    708 QSizeF UIChooserItemMachine::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
     362QSizeF UIChooserItemGlobal::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    709363{
    710364    /* If Qt::MinimumSize requested: */
     
    715369}
    716370
    717 QPixmap UIChooserItemMachine::toPixmap()
     371QPixmap UIChooserItemGlobal::toPixmap()
    718372{
    719373    /* Ask item to paint itself into pixmap: */
    720     QSize minimumSize = minimumSizeHint().toSize();
     374    const QSize minimumSize = minimumSizeHint().toSize();
    721375    QPixmap pixmap(minimumSize);
    722376    QPainter painter(&pixmap);
     
    727381}
    728382
    729 bool UIChooserItemMachine::isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const
    730 {
    731     /* No drops while saving groups: */
    732     if (model()->isGroupSavingInProgress())
    733         return false;
    734     /* No drops for immutable item: */
    735     if (isLockedMachine())
    736         return false;
    737     /* Get mime: */
    738     const QMimeData *pMimeData = pEvent->mimeData();
    739     /* If drag token is shown, its up to parent to decide: */
    740     if (where != DragToken_Off)
    741         return parentItem()->isDropAllowed(pEvent);
    742     /* Else we should make sure machine is accessible: */
    743     if (!accessible())
    744         return false;
    745     /* Else we should try to cast mime to known classes: */
    746     if (pMimeData->hasFormat(UIChooserItemMachine::className()))
    747     {
    748         /* Make sure passed item id is not ours: */
    749         const UIChooserItemMimeData *pCastedMimeData = qobject_cast<const UIChooserItemMimeData*>(pMimeData);
    750         AssertMsg(pCastedMimeData, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
    751         UIChooserItem *pItem = pCastedMimeData->item();
    752         UIChooserItemMachine *pMachineItem = pItem->toMachineItem();
    753         /* Make sure passed machine is mutable: */
    754         if (pMachineItem->isLockedMachine())
    755             return false;
    756         return pMachineItem->id() != id();
    757     }
    758     /* That was invalid mime: */
     383bool UIChooserItemGlobal::isDropAllowed(QGraphicsSceneDragDropEvent *, DragToken) const
     384{
     385    /* No drops at all: */
    759386    return false;
    760387}
    761388
    762 void UIChooserItemMachine::processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where)
    763 {
    764     /* Get mime: */
    765     const QMimeData *pMime = pEvent->mimeData();
    766     /* Make sure this handler called by this item (not by children): */
    767     AssertMsg(!pFromWho && where == DragToken_Off, ("Machine graphics item do NOT support children!"));
    768     Q_UNUSED(pFromWho);
    769     Q_UNUSED(where);
    770     if (pMime->hasFormat(UIChooserItemMachine::className()))
    771     {
    772         switch (pEvent->proposedAction())
    773         {
    774             case Qt::MoveAction:
    775             case Qt::CopyAction:
    776             {
    777                 /* Remember scene: */
    778                 UIChooserModel *pModel = model();
    779 
    780                 /* Get passed item: */
    781                 const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime);
    782                 AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
    783                 UIChooserItem *pItem = pCastedMime->item();
    784 
    785                 /* Group passed item with current item into the new group: */
    786                 UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(parentItem(),
    787                                                                              UIChooserModel::uniqueGroupName(parentItem()),
    788                                                                              true);
    789                 new UIChooserItemMachine(pNewGroupItem, this);
    790                 new UIChooserItemMachine(pNewGroupItem, pItem->toMachineItem());
    791 
    792                 /* If proposed action is 'move': */
    793                 if (pEvent->proposedAction() == Qt::MoveAction)
    794                 {
    795                     /* Delete passed item: */
    796                     delete pItem;
    797                 }
    798                 /* Delete this item: */
    799                 delete this;
    800 
    801                 /* Update model: */
    802                 pModel->cleanupGroupTree();
    803                 pModel->updateNavigation();
    804                 pModel->updateLayout();
    805                 pModel->setCurrentItem(pNewGroupItem);
    806                 pModel->saveGroupSettings();
    807                 break;
    808             }
    809             default:
    810                 break;
    811         }
    812     }
    813 }
    814 
    815 void UIChooserItemMachine::resetDragToken()
    816 {
    817     /* Reset drag token for this item: */
    818     if (dragTokenPlace() != DragToken_Off)
    819     {
    820         setDragTokenPlace(DragToken_Off);
    821         update();
    822     }
    823 }
    824 
    825 QMimeData* UIChooserItemMachine::createMimeData()
    826 {
    827     return new UIChooserItemMimeData(this);
    828 }
    829 
    830 void UIChooserItemMachine::showEvent(QShowEvent *pEvent)
     389void UIChooserItemGlobal::processDrop(QGraphicsSceneDragDropEvent *, UIChooserItem *, DragToken)
     390{
     391    /* Nothing to process: */
     392}
     393
     394void UIChooserItemGlobal::resetDragToken()
     395{
     396    /* Nothing to process: */
     397}
     398
     399QMimeData *UIChooserItemGlobal::createMimeData()
     400{
     401    /* Nothing to return: */
     402    return 0;
     403}
     404
     405void UIChooserItemGlobal::showEvent(QShowEvent *pEvent)
    831406{
    832407    /* Call to base-class: */
    833408    UIChooserItem::showEvent(pEvent);
    834409
    835     /* Recache and update pixmaps: */
    836     recachePixmap();
    837     updatePixmaps();
    838 }
    839 
    840 void UIChooserItemMachine::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
     410    /* Update pixmaps: */
     411    updatePixmap();
     412}
     413
     414void UIChooserItemGlobal::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
    841415{
    842416    /* Call to base-class: */
     
    844418
    845419    /* What is the new geometry? */
    846     QRectF newGeometry = geometry();
     420    const QRectF newGeometry = geometry();
    847421
    848422    /* Should we update visible name? */
    849423    if (previousGeometry().width() != newGeometry.width())
    850         updateFirstRowMaximumWidth();
     424        updateMaximumNameWidth();
    851425
    852426    /* Remember the new geometry: */
     
    854428}
    855429
    856 void UIChooserItemMachine::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
     430void UIChooserItemGlobal::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
    857431{
    858432    /* Call to base-class: */
    859433    UIChooserItem::mousePressEvent(pEvent);
    860     /* No drag for inaccessible: */
    861     if (!accessible())
    862         pEvent->ignore();
    863 }
    864 
    865 void UIChooserItemMachine::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget* /* pWidget = 0 */)
     434    /* No drag at all: */
     435    pEvent->ignore();
     436}
     437
     438void UIChooserItemGlobal::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget * /* pWidget = 0 */)
    866439{
    867440    /* Setup: */
     
    875448}
    876449
    877 void UIChooserItemMachine::paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
     450void UIChooserItemGlobal::paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
    878451{
    879452    /* Prepare variables: */
     
    887460}
    888461
    889 void UIChooserItemMachine::paintBackground(QPainter *pPainter, const QRect &rect)
     462void UIChooserItemGlobal::paintBackground(QPainter *pPainter, const QRect &rect)
    890463{
    891464    /* Save painter: */
     
    893466
    894467    /* Prepare color: */
    895     QPalette pal = palette();
     468    const QPalette pal = palette();
    896469
    897470    /* Selection background: */
     
    918491    }
    919492
    920     /* Paint drag token UP? */
    921     if (dragTokenPlace() != DragToken_Off)
    922     {
    923         /* Window color: */
    924         QColor base = pal.color(QPalette::Active, model()->currentItems().contains(this) ?
    925                                 QPalette::Highlight : QPalette::Window);
    926         QLinearGradient dragTokenGradient;
    927         QRect dragTokenRect = rect;
    928         if (dragTokenPlace() == DragToken_Up)
    929         {
    930             dragTokenRect.setHeight(5);
    931             dragTokenGradient.setStart(dragTokenRect.bottomLeft());
    932             dragTokenGradient.setFinalStop(dragTokenRect.topLeft());
    933         }
    934         else if (dragTokenPlace() == DragToken_Down)
    935         {
    936             dragTokenRect.setTopLeft(dragTokenRect.bottomLeft() - QPoint(0, 5));
    937             dragTokenGradient.setStart(dragTokenRect.topLeft());
    938             dragTokenGradient.setFinalStop(dragTokenRect.bottomLeft());
    939         }
    940         dragTokenGradient.setColorAt(0, base.darker(dragTokenDarkness()));
    941         dragTokenGradient.setColorAt(1, base.darker(dragTokenDarkness() + 40));
    942         pPainter->fillRect(dragTokenRect, dragTokenGradient);
    943     }
    944 
    945493    /* Restore painter: */
    946494    pPainter->restore();
    947495}
    948496
    949 void UIChooserItemMachine::paintFrameRectangle(QPainter *pPainter, const QRect &rect)
     497void UIChooserItemGlobal::paintFrameRectangle(QPainter *pPainter, const QRect &rect)
    950498{
    951499    /* Only chosen and/or hovered item should have a frame: */
     
    955503    /* Simple frame: */
    956504    pPainter->save();
    957     QPalette pal = palette();
     505    const QPalette pal = palette();
    958506    QColor strokeColor = pal.color(QPalette::Active,
    959507                                   model()->currentItems().contains(this) ?
     
    964512}
    965513
    966 void UIChooserItemMachine::paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
     514void UIChooserItemGlobal::paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
    967515{
    968516    /* Prepare variables: */
    969     QRect fullRect = pOption->rect;
    970     int iFullHeight = fullRect.height();
    971     int iMargin = data(MachineItemData_Margin).toInt();
    972     int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt();
    973     int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
    974     int iMachineItemTextSpacing = data(MachineItemData_TextSpacing).toInt();
     517    const QRect fullRect = pOption->rect;
     518    const int iFullHeight = fullRect.height();
     519    const int iMargin = data(GlobalItemData_Margin).toInt();
     520    const int iSpacing = data(GlobalItemData_Spacing).toInt();
    975521
    976522    /* Selected item foreground: */
    977523    if (model()->currentItems().contains(this))
    978524    {
    979         QPalette pal = palette();
     525        const QPalette pal = palette();
    980526        pPainter->setPen(pal.color(QPalette::HighlightedText));
    981527    }
     
    984530    {
    985531        /* Prepare color: */
    986         QPalette pal = palette();
    987         QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
    988         QColor hhl = highlight.lighter(m_iHoverHighlightLightness);
     532        const QPalette pal = palette();
     533        const QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
     534        const QColor hhl = highlight.lighter(m_iHoverHighlightLightness);
    989535        if (hhl.value() - hhl.saturation() > 0)
    990536            pPainter->setPen(pal.color(QPalette::Active, QPalette::Text));
     
    999545    {
    1000546        /* Prepare variables: */
    1001         int iMachinePixmapX = iLeftColumnIndent;
    1002         int iMachinePixmapY = (iFullHeight - m_pixmap.height() / m_pixmap.devicePixelRatio()) / 2;
     547        const int iGlobalPixmapX = iLeftColumnIndent;
     548        const int iGlobalPixmapY = (iFullHeight - m_pixmap.height() / m_pixmap.devicePixelRatio()) / 2;
     549
    1003550        /* Paint pixmap: */
    1004551        paintPixmap(/* Painter: */
    1005552                    pPainter,
    1006553                    /* Point to paint in: */
    1007                     QPoint(iMachinePixmapX, iMachinePixmapY),
     554                    QPoint(iGlobalPixmapX, iGlobalPixmapY),
    1008555                    /* Pixmap to paint: */
    1009556                    m_pixmap);
     
    1011558
    1012559    /* Calculate indents: */
    1013     int iRightColumnIndent = iLeftColumnIndent +
    1014                              m_pixmapSize.width() +
    1015                              iMajorSpacing;
     560    const int iRightColumnIndent = iLeftColumnIndent +
     561                                   m_pixmapSize.width() +
     562                                   iSpacing;
    1016563
    1017564    /* Paint right column: */
    1018565    {
    1019         /* Calculate indents: */
    1020         int iTopLineHeight = qMax(m_visibleNameSize.height(), m_visibleSnapshotNameSize.height());
    1021         int iBottomLineHeight = qMax(m_statePixmapSize.height(), m_stateTextSize.height());
    1022         int iRightColumnHeight = iTopLineHeight + iMachineItemTextSpacing + iBottomLineHeight;
    1023         int iTopLineIndent = (iFullHeight - iRightColumnHeight) / 2;
    1024 
    1025         /* Paint top line: */
    1026         {
    1027             /* Paint left element: */
    1028             {
    1029                 /* Prepare variables: */
    1030                 int iNameX = iRightColumnIndent;
    1031                 int iNameY = iTopLineIndent;
    1032                 /* Paint name: */
    1033                 paintText(/* Painter: */
    1034                           pPainter,
    1035                           /* Point to paint in: */
    1036                           QPoint(iNameX, iNameY),
    1037                           /* Font to paint text: */
    1038                           m_nameFont,
    1039                           /* Paint device: */
    1040                           model()->paintDevice(),
    1041                           /* Text to paint: */
    1042                           m_strVisibleName);
    1043             }
    1044 
    1045             /* Calculate indents: */
    1046             int iSnapshotNameIndent = iRightColumnIndent +
    1047                                       m_visibleNameSize.width() +
    1048                                       iMinorSpacing;
    1049 
    1050             /* Paint right element: */
    1051             if (!snapshotName().isEmpty())
    1052             {
    1053                 /* Prepare variables: */
    1054                 int iSnapshotNameX = iSnapshotNameIndent;
    1055                 int iSnapshotNameY = iTopLineIndent;
    1056                 /* Paint snapshot-name: */
    1057                 paintText(/* Painter: */
    1058                           pPainter,
    1059                           /* Point to paint in: */
    1060                           QPoint(iSnapshotNameX, iSnapshotNameY),
    1061                           /* Font to paint text: */
    1062                           m_snapshotNameFont,
    1063                           /* Paint device: */
    1064                           model()->paintDevice(),
    1065                           /* Text to paint: */
    1066                           m_strVisibleSnapshotName);
    1067             }
    1068         }
    1069 
    1070         /* Calculate indents: */
    1071         int iBottomLineIndent = iTopLineIndent + iTopLineHeight;
    1072 
    1073         /* Paint bottom line: */
    1074         {
    1075             /* Paint left element: */
    1076             {
    1077                 /* Prepare variables: */
    1078                 int iMachineStatePixmapX = iRightColumnIndent;
    1079                 int iMachineStatePixmapY = iBottomLineIndent;
    1080                 /* Paint state pixmap: */
    1081                 paintPixmap(/* Painter: */
    1082                             pPainter,
    1083                             /* Point to paint in: */
    1084                             QPoint(iMachineStatePixmapX, iMachineStatePixmapY),
    1085                             /* Pixmap to paint: */
    1086                             m_statePixmap);
    1087             }
    1088 
    1089             /* Calculate indents: */
    1090             int iMachineStateTextIndent = iRightColumnIndent +
    1091                                           m_statePixmapSize.width() +
    1092                                           iMinorSpacing;
    1093 
    1094             /* Paint right element: */
    1095             {
    1096                 /* Prepare variables: */
    1097                 int iMachineStateTextX = iMachineStateTextIndent;
    1098                 int iMachineStateTextY = iBottomLineIndent;
    1099                 /* Paint state text: */
    1100                 paintText(/* Painter: */
    1101                           pPainter,
    1102                           /* Point to paint in: */
    1103                           QPoint(iMachineStateTextX, iMachineStateTextY),
    1104                           /* Font to paint text: */
    1105                           m_stateTextFont,
    1106                           /* Paint device: */
    1107                           model()->paintDevice(),
    1108                           /* Text to paint: */
    1109                           m_strStateText);
    1110             }
    1111         }
    1112     }
    1113 
    1114     /* Tool-bar: */
    1115     if (m_pToolBar)
    1116     {
    1117         /* Show/hide tool-bar: */
    1118         if (isHovered())
    1119         {
    1120             if (!m_pToolBar->isVisible())
    1121                 m_pToolBar->show();
    1122         }
    1123         else
    1124         {
    1125             if (m_pToolBar->isVisible())
    1126                 m_pToolBar->hide();
    1127         }
    1128     }
    1129 }
    1130 
    1131 void UIChooserItemMachine::prepare()
    1132 {
    1133     /* Tool-bar/buttons: */
    1134     m_pToolBar = 0;
    1135     m_pSettingsButton = 0;
    1136     m_pStartButton = 0;
    1137     m_pPauseButton = 0;
    1138     m_pCloseButton = 0;
    1139 
     566        /* Prepare variables: */
     567        const int iNameX = iRightColumnIndent;
     568        const int iNameY = (iFullHeight - m_visibleNameSize.height()) / 2;
     569
     570        /* Paint name: */
     571        paintText(/* Painter: */
     572                  pPainter,
     573                  /* Point to paint in: */
     574                  QPoint(iNameX, iNameY),
     575                  /* Font to paint text: */
     576                  m_nameFont,
     577                  /* Paint device: */
     578                  model()->paintDevice(),
     579                  /* Text to paint: */
     580                  m_strVisibleName);
     581    }
     582}
     583
     584void UIChooserItemGlobal::prepare()
     585{
    1140586    /* Colors: */
    1141587#ifdef VBOX_WS_MAC
     
    1152598    m_nameFont = font();
    1153599    m_nameFont.setWeight(QFont::Bold);
    1154     m_snapshotNameFont = font();
    1155     m_stateTextFont = font();
    1156600
    1157601    /* Sizes: */
    1158     m_iFirstRowMaximumWidth = 0;
    1159602    m_iMinimumNameWidth = 0;
    1160603    m_iMaximumNameWidth = 0;
    1161     m_iMinimumSnapshotNameWidth = 0;
    1162     m_iMaximumSnapshotNameWidth = 0;
    1163 
    1164     /* Other things disabled for now: */
    1165     return;
    1166 
    1167 #if 0 /* disabled for now */
    1168     /* Create tool-bar: */
    1169     m_pToolBar = new UIGraphicsToolBar(this, 2, 2);
    1170 
    1171     /* Create buttons: */
    1172     m_pSettingsButton = new UIGraphicsZoomButton(m_pToolBar,
    1173                                                  data(MachineItemData_SettingsButtonPixmap).value<QIcon>(),
    1174                                                  UIGraphicsZoomDirection_Top | UIGraphicsZoomDirection_Left);
    1175     m_pSettingsButton->setIndent(m_pToolBar->toolBarMargin() - 1);
    1176     m_pToolBar->insertItem(m_pSettingsButton, 0, 0);
    1177 
    1178     m_pStartButton = new UIGraphicsZoomButton(m_pToolBar,
    1179                                               data(MachineItemData_StartButtonPixmap).value<QIcon>(),
    1180                                               UIGraphicsZoomDirection_Top | UIGraphicsZoomDirection_Right);
    1181     m_pStartButton->setIndent(m_pToolBar->toolBarMargin() - 1);
    1182     m_pToolBar->insertItem(m_pStartButton, 0, 1);
    1183 
    1184     m_pPauseButton = new UIGraphicsZoomButton(m_pToolBar,
    1185                                               data(MachineItemData_PauseButtonPixmap).value<QIcon>(),
    1186                                               UIGraphicsZoomDirection_Bottom | UIGraphicsZoomDirection_Left);
    1187     m_pPauseButton->setIndent(m_pToolBar->toolBarMargin() - 1);
    1188     m_pToolBar->insertItem(m_pPauseButton, 1, 0);
    1189 
    1190     m_pCloseButton = new UIGraphicsZoomButton(m_pToolBar,
    1191                                               data(MachineItemData_CloseButtonPixmap).value<QIcon>(),
    1192                                               UIGraphicsZoomDirection_Bottom | UIGraphicsZoomDirection_Right);
    1193     m_pCloseButton->setIndent(m_pToolBar->toolBarMargin() - 1);
    1194     m_pToolBar->insertItem(m_pCloseButton, 1, 1);
    1195 
    1196     connect(m_pSettingsButton, SIGNAL(sigButtonClicked()),
    1197             actionPool()->action(UIActionIndexST_M_Machine_S_Settings), SLOT(trigger()),
    1198             Qt::QueuedConnection);
    1199     connect(m_pStartButton, SIGNAL(sigButtonClicked()),
    1200             actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow), SLOT(trigger()),
    1201             Qt::QueuedConnection);
    1202     connect(m_pPauseButton, SIGNAL(sigButtonClicked()),
    1203             actionPool()->action(UIActionIndexST_M_Machine_T_Pause), SLOT(trigger()),
    1204             Qt::QueuedConnection);
    1205     connect(m_pCloseButton, SIGNAL(sigButtonClicked()),
    1206             actionPool()->action(UIActionIndexST_M_Machine_M_Close_S_PowerOff), SLOT(trigger()),
    1207             Qt::QueuedConnection);
    1208 #endif /* disabled for now */
    1209 }
    1210 
    1211 /* static */
    1212 bool UIChooserItemMachine::contains(const QList<UIChooserItemMachine*> &list, UIChooserItemMachine *pItem)
    1213 {
    1214     /* Check if passed list contains passed machine-item id: */
    1215     foreach (UIChooserItemMachine *pIteratedItem, list)
    1216         if (pIteratedItem->id() == pItem->id())
    1217             return true;
    1218     /* Found nothing? */
    1219     return false;
    1220 }
    1221 
     604}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h

    r73555 r73600  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIChooserItemMachine class declaration.
     3 * VBox Qt GUI - UIChooserItemGlobal class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UIChooserItemMachine_h__
    19 #define __UIChooserItemMachine_h__
     18#ifndef __UIChooserItemGlobal_h__
     19#define __UIChooserItemGlobal_h__
    2020
    2121/* GUI includes: */
    22 #include "UIVirtualMachineItem.h"
    2322#include "UIChooserItem.h"
    2423
    2524/* Forward declarations: */
    26 class CMachine;
    2725class UIGraphicsToolBar;
    2826class UIGraphicsZoomButton;
    2927
    3028/* Machine-item enumeration flags: */
    31 enum UIChooserItemMachineEnumerationFlag
     29enum UIChooserItemGlobalEnumerationFlag
    3230{
    33     UIChooserItemMachineEnumerationFlag_Unique       = RT_BIT(0),
    34     UIChooserItemMachineEnumerationFlag_Inaccessible = RT_BIT(1)
     31    UIChooserItemGlobalEnumerationFlag_Unique       = RT_BIT(0),
     32    UIChooserItemGlobalEnumerationFlag_Inaccessible = RT_BIT(1)
    3533};
    3634
    37 /* Graphics machine item
     35/* Graphics global-item
    3836 * for graphics selector model/view architecture: */
    39 class UIChooserItemMachine : public UIChooserItem, public UIVirtualMachineItem
     37class UIChooserItemGlobal : public UIChooserItem
    4038{
    4139    Q_OBJECT;
     
    4341public:
    4442
    45     /* Class-name used for drag&drop mime-data format: */
    46     static QString className();
    47 
    4843    /* Graphics-item type: */
    49     enum { Type = UIChooserItemType_Machine };
     44    enum { Type = UIChooserItemType_Global };
    5045    int type() const { return Type; }
    5146
    5247    /* Constructor (new item): */
    53     UIChooserItemMachine(UIChooserItem *pParent, const CMachine &machine, int iPosition = -1);
     48    UIChooserItemGlobal(UIChooserItem *pParent, int iPosition = -1);
    5449    /* Constructor (new item copy): */
    55     UIChooserItemMachine(UIChooserItem *pParent, UIChooserItemMachine *pCopyFrom, int iPosition = -1);
     50    UIChooserItemGlobal(UIChooserItem *pParent, UIChooserItemGlobal *pCopyFrom, int iPosition = -1);
    5651    /* Destructor: */
    57     ~UIChooserItemMachine();
     52    ~UIChooserItemGlobal();
    5853
    5954    /* API: Basic stuff: */
     
    6257    QString fullName() const;
    6358    QString definition() const;
    64     bool isLockedMachine() const;
    65 
    66     /* API: Machine-item enumeration stuff: */
    67     static void enumerateMachineItems(const QList<UIChooserItem*> &il,
    68                                       QList<UIChooserItemMachine*> &ol,
    69                                       int iEnumerationFlags = 0);
    7059
    7160private slots:
     
    7766
    7867    /* Data enumerator: */
    79     enum MachineItemData
     68    enum GlobalItemData
    8069    {
    8170        /* Layout hints: */
    82         MachineItemData_Margin,
    83         MachineItemData_MajorSpacing,
    84         MachineItemData_MinorSpacing,
    85         MachineItemData_TextSpacing,
    86         /* Pixmaps: */
    87         MachineItemData_SettingsButtonPixmap,
    88         MachineItemData_StartButtonPixmap,
    89         MachineItemData_PauseButtonPixmap,
    90         MachineItemData_CloseButtonPixmap,
    91         /* Sizes: */
    92         MachineItemData_ToolBarSize
     71        GlobalItemData_Margin,
     72        GlobalItemData_Spacing,
    9373    };
    9474
     
    9777
    9878    /* Helpers: Update stuff: */
    99     void updatePixmaps();
    10079    void updatePixmap();
    101     void updateStatePixmap();
    102     void updateName();
    103     void updateSnapshotName();
    104     void updateFirstRowMaximumWidth();
    10580    void updateMinimumNameWidth();
    106     void updateMinimumSnapshotNameWidth();
    10781    void updateMaximumNameWidth();
    108     void updateMaximumSnapshotNameWidth();
    10982    void updateVisibleName();
    110     void updateVisibleSnapshotName();
    111     void updateStateText();
    11283
    11384    /* Helper: Translate stuff: */
     
    12798    void updateAll(const QString &strId);
    12899    void removeAll(const QString &strId);
    129     UIChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    130     UIChooserItemMachine* firstMachineItem();
     100    UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags);
     101    UIChooserItem *firstMachineItem();
    131102    void sortItems();
    132103
    133104    /* Helpers: Layout stuff: */
    134     void updateLayout();
     105    void updateLayout() {}
    135106    int minimumWidthHint() const;
    136107    int minimumHeightHint() const;
     
    142113    void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where);
    143114    void resetDragToken();
    144     QMimeData* createMimeData();
     115    QMimeData *createMimeData();
    145116
    146117    /** Handles show @a pEvent. */
     
    164135
    165136    /* Helper: Machine-item enumeration stuff: */
    166     static bool contains(const QList<UIChooserItemMachine*> &list,
    167                          UIChooserItemMachine *pItem);
     137    static bool contains(const QList<UIChooserItemGlobal*> &list,
     138                         UIChooserItemGlobal *pItem);
    168139
    169140    /* Variables: */
    170     UIGraphicsToolBar *m_pToolBar;
    171     UIGraphicsZoomButton *m_pSettingsButton;
    172     UIGraphicsZoomButton *m_pStartButton;
    173     UIGraphicsZoomButton *m_pPauseButton;
    174     UIGraphicsZoomButton *m_pCloseButton;
    175141    int m_iHighlightLightness;
    176142    int m_iHoverLightness;
     
    178144    /* Cached values: */
    179145    QFont m_nameFont;
    180     QFont m_snapshotNameFont;
    181     QFont m_stateTextFont;
    182146    QPixmap m_pixmap;
    183     QPixmap m_statePixmap;
    184147    QString m_strName;
    185148    QString m_strDescription;
    186149    QString m_strVisibleName;
    187     QString m_strSnapshotName;
    188     QString m_strVisibleSnapshotName;
    189     QString m_strStateText;
    190150    QSize m_pixmapSize;
    191     QSize m_statePixmapSize;
    192151    QSize m_visibleNameSize;
    193     QSize m_visibleSnapshotNameSize;
    194     QSize m_stateTextSize;
    195     int m_iFirstRowMaximumWidth;
    196152    int m_iMinimumNameWidth;
    197153    int m_iMaximumNameWidth;
    198     int m_iMinimumSnapshotNameWidth;
    199     int m_iMaximumSnapshotNameWidth;
    200154};
    201155
    202 #endif /* __UIChooserItemMachine_h__ */
    203 
     156#endif /* __UIChooserItemGlobal_h__ */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r73424 r73600  
    3131/* GUI includes: */
    3232# include "UIChooserItemGroup.h"
     33# include "UIChooserItemGlobal.h"
    3334# include "UIChooserItemMachine.h"
    3435# include "UIChooserModel.h"
     
    470471    foreach (UIChooserItem *pGroupItem, pFrom->items(UIChooserItemType_Group))
    471472        new UIChooserItemGroup(pTo, pGroupItem->toGroupItem());
     473    /* Copy global-items: */
     474    foreach (UIChooserItem *pGlobalItem, pFrom->items(UIChooserItemType_Global))
     475        new UIChooserItemGlobal(pTo, pGlobalItem->toGlobalItem());
    472476    /* Copy machine-items: */
    473477    foreach (UIChooserItem *pMachineItem, pFrom->items(UIChooserItemType_Machine))
     
    807811            break;
    808812        }
     813        case UIChooserItemType_Global:
     814        {
     815            AssertMsg(!m_globalItems.contains(pItem), ("Global-item already added!"));
     816            if (iPosition < 0 || iPosition >= m_globalItems.size())
     817                m_globalItems.append(pItem);
     818            else
     819                m_globalItems.insert(iPosition, pItem);
     820            scene()->addItem(pItem);
     821            break;
     822        }
    809823        case UIChooserItemType_Machine:
    810824        {
     
    842856            break;
    843857        }
     858        case UIChooserItemType_Global:
     859        {
     860            AssertMsg(m_globalItems.contains(pItem), ("Global-item was not found!"));
     861            scene()->removeItem(pItem);
     862            m_globalItems.removeAt(m_globalItems.indexOf(pItem));
     863            break;
     864        }
    844865        case UIChooserItemType_Machine:
    845866        {
     
    868889    {
    869890        case UIChooserItemType_Group: m_groupItems = items; break;
     891        case UIChooserItemType_Global: m_globalItems = items; break;
    870892        case UIChooserItemType_Machine: m_machineItems = items; break;
    871893        default: AssertMsgFailed(("Invalid item type!")); break;
     
    882904    switch (type)
    883905    {
    884         case UIChooserItemType_Any: return items(UIChooserItemType_Group) + items(UIChooserItemType_Machine);
     906        case UIChooserItemType_Any: return items(UIChooserItemType_Global) + items(UIChooserItemType_Group) + items(UIChooserItemType_Machine);
    885907        case UIChooserItemType_Group: return m_groupItems;
     908        case UIChooserItemType_Global: return m_globalItems;
    886909        case UIChooserItemType_Machine: return m_machineItems;
    887910        default: break;
     
    895918    {
    896919        case UIChooserItemType_Any:
    897             return hasItems(UIChooserItemType_Group) || hasItems(UIChooserItemType_Machine);
     920            return hasItems(UIChooserItemType_Global) || hasItems(UIChooserItemType_Group) || hasItems(UIChooserItemType_Machine);
    898921        case UIChooserItemType_Group:
    899922            return !m_groupItems.isEmpty();
     923        case UIChooserItemType_Global:
     924            return !m_globalItems.isEmpty();
    900925        case UIChooserItemType_Machine:
    901926            return !m_machineItems.isEmpty();
     
    911936        {
    912937            clearItems(UIChooserItemType_Group);
     938            clearItems(UIChooserItemType_Global);
    913939            clearItems(UIChooserItemType_Machine);
    914940            break;
     
    918944            while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); }
    919945            AssertMsg(m_groupItems.isEmpty(), ("Group items cleanup failed!"));
     946            break;
     947        }
     948        case UIChooserItemType_Global:
     949        {
     950            while (!m_globalItems.isEmpty()) { delete m_globalItems.last(); }
     951            AssertMsg(m_globalItems.isEmpty(), ("Global items cleanup failed!"));
    920952            break;
    921953        }
     
    9711003    /* Search among all the children, but machines first: */
    9721004    foreach (UIChooserItem *pItem, items(UIChooserItemType_Machine))
     1005        if (UIChooserItem *pFoundItem = pItem->searchForItem(strSearchTag, iItemSearchFlags))
     1006            return pFoundItem;
     1007    foreach (UIChooserItem *pItem, items(UIChooserItemType_Global))
    9731008        if (UIChooserItem *pFoundItem = pItem->searchForItem(strSearchTag, iItemSearchFlags))
    9741009            return pFoundItem;
     
    9811016}
    9821017
    983 UIChooserItemMachine* UIChooserItemGroup::firstMachineItem()
     1018UIChooserItem *UIChooserItemGroup::firstMachineItem()
    9841019{
    9851020    /* If this group-item have at least one machine-item: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h

    r73424 r73600  
    145145    void updateAll(const QString &strId);
    146146    void removeAll(const QString &strId);
    147     UIChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    148     UIChooserItemMachine* firstMachineItem();
     147    UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags);
     148    UIChooserItem *firstMachineItem();
    149149    void sortItems();
    150150
     
    203203    QGraphicsProxyWidget *m_pNameEditor;
    204204    QList<UIChooserItem*> m_groupItems;
     205    QList<UIChooserItem*> m_globalItems;
    205206    QList<UIChooserItem*> m_machineItems;
    206207    int m_iAdditionalHeight;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r73424 r73600  
    605605}
    606606
    607 UIChooserItemMachine* UIChooserItemMachine::firstMachineItem()
     607UIChooserItem *UIChooserItemMachine::firstMachineItem()
    608608{
    609609    return this;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h

    r73424 r73600  
    3535};
    3636
    37 /* Graphics machine item
     37/* Graphics machine-item
    3838 * for graphics selector model/view architecture: */
    3939class UIChooserItemMachine : public UIChooserItem, public UIVirtualMachineItem
     
    127127    void updateAll(const QString &strId);
    128128    void removeAll(const QString &strId);
    129     UIChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    130     UIChooserItemMachine* firstMachineItem();
     129    UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags);
     130    UIChooserItem *firstMachineItem();
    131131    void sortItems();
    132132
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r73492 r73600  
    3737# include "UIChooserModel.h"
    3838# include "UIChooserItemGroup.h"
     39# include "UIChooserItemGlobal.h"
    3940# include "UIChooserItemMachine.h"
    4041# include "UIExtraDataDefs.h"
     
    207208}
    208209
     210bool UIChooserModel::isGlobalItemSelected() const
     211{
     212    return currentItem() && currentItem()->type() == UIChooserItemType_Global;
     213}
     214
     215bool UIChooserModel::isMachineItemSelected() const
     216{
     217    return currentItem() && currentItem()->type() == UIChooserItemType_Machine;
     218}
     219
    209220UIVirtualMachineItem* UIChooserModel::currentMachineItem() const
    210221{
    211222    /* Return first machine-item of the current-item: */
    212     return currentItem() ? currentItem()->firstMachineItem() : 0;
     223    return   currentItem() && currentItem()->firstMachineItem()
     224           ? currentItem()->firstMachineItem()->toMachineItem()
     225           : 0;
    213226}
    214227
     
    218231    QList<UIChooserItemMachine*> currentMachineItemList;
    219232    UIChooserItemMachine::enumerateMachineItems(currentItems(), currentMachineItemList,
    220                                                  UIChooserItemMachineEnumerationFlag_Unique);
     233                                                UIChooserItemMachineEnumerationFlag_Unique);
    221234
    222235    /* Reintegrate machine-items into valid format: */
     
    982995                /* Add name to busy: */
    983996                busyMachineNames << pItem->name();
    984                 /* Copy or move machine item: */
     997                /* Copy or move machine-item: */
    985998                new UIChooserItemMachine(pNewGroupItem, pItem->toMachineItem());
    986999                delete pItem;
     
    14511464            navigationItems << createNavigationList(pGroupItem);
    14521465    }
     1466    /* Iterate over all the global-items: */
     1467    foreach (UIChooserItem *pGlobalItem, pItem->items(UIChooserItemType_Global))
     1468        navigationItems << pGlobalItem;
    14531469    /* Iterate over all the machine-items: */
    14541470    foreach (UIChooserItem *pMachineItem, pItem->items(UIChooserItemType_Machine))
     
    17501766void UIChooserModel::loadGroupTree()
    17511767{
     1768    /* Create Global item: */
     1769    createGlobalItem(mainRoot());
     1770
    17521771    /* Add all the approved machines we have into the group-tree: */
    17531772    LogRelFlow(("UIChooserModel: Loading VMs...\n"));
     
    19601979void UIChooserModel::createMachineItem(const CMachine &machine, UIChooserItem *pParentItem)
    19611980{
    1962     /* Create corresponding item: */
    1963     new UIChooserItemMachine(/* Parent item and corresponding machine: */
    1964                               pParentItem, machine,
    1965                               /* Which position new group-item should be placed in? */
    1966                               getDesiredPosition(pParentItem, UIChooserItemType_Machine, machine.GetId()));
     1981    /* Create machine-item: */
     1982    new UIChooserItemMachine(pParentItem, machine, getDesiredPosition(pParentItem, UIChooserItemType_Machine, machine.GetId()));
     1983}
     1984
     1985void UIChooserModel::createGlobalItem(UIChooserItem *pParentItem)
     1986{
     1987    /* Create global-item: */
     1988    new UIChooserItemGlobal(pParentItem, 0);
    19671989}
    19681990
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r73424 r73600  
    110110
    111111    /* API: Current-item stuff: */
    112     UIVirtualMachineItem* currentMachineItem() const;
     112    bool isGlobalItemSelected() const;
     113    bool isMachineItemSelected() const;
     114    UIVirtualMachineItem *currentMachineItem() const;
    113115    QList<UIVirtualMachineItem*> currentMachineItems() const;
    114116    UIChooserItem* currentItem() const;
     
    265267    int positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType type, const QString &strName);
    266268    void createMachineItem(const CMachine &machine, UIChooserItem *pParentItem);
     269    void createGlobalItem(UIChooserItem *pParentItem);
    267270
    268271    /* Helpers: Saving stuff: */
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