VirtualBox

Changeset 73954 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 29, 2018 2:53:36 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: VirtualBox Manager UI: Large cleanup for UIChooserItemGlobal, doxygen + style fixes.

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

Legend:

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

    r73927 r73954  
    2121
    2222/* Qt includes: */
     23# include <QGraphicsSceneMouseEvent>
    2324# include <QPainter>
    2425# include <QStyleOptionGraphicsItem>
    25 # include <QGraphicsSceneMouseEvent>
    2626
    2727/* GUI includes: */
     
    3030# include "UIChooserModel.h"
    3131# include "UIIconPool.h"
    32 //# include "UIImageTools.h"
    3332# include "UIVirtualBoxManager.h"
    3433
     
    3938                                         int iPosition /* = -1 */)
    4039    : UIChooserItem(pParent, pParent->isTemporary())
     40    , m_iHoverLightness(0)
     41    , m_iHighlightLightness(0)
     42    , m_iHoverHighlightLightness(0)
     43    , m_iMinimumNameWidth(0)
     44    , m_iMaximumNameWidth(0)
    4145{
    4246    /* Prepare: */
     
    6367                                         int iPosition /* = -1 */)
    6468    : UIChooserItem(pParent, pParent->isTemporary())
     69    , m_iHoverLightness(0)
     70    , m_iHighlightLightness(0)
     71    , m_iHoverHighlightLightness(0)
     72    , m_iMinimumNameWidth(0)
     73    , m_iMaximumNameWidth(0)
    6574{
    6675    /* Prepare: */
     
    109118}
    110119
    111 QString UIChooserItemGlobal::name() const
    112 {
    113     return m_strName;
    114 }
    115 
    116 QString UIChooserItemGlobal::description() const
    117 {
    118     return m_strDescription;
    119 }
    120 
    121 QString UIChooserItemGlobal::fullName() const
    122 {
    123     return m_strName;
    124 }
    125 
    126 QString UIChooserItemGlobal::definition() const
    127 {
    128     return QString("n=%1").arg(name());
    129 }
    130 
    131 void UIChooserItemGlobal::sltHandleWindowRemapped()
    132 {
    133     updatePixmap();
    134 }
    135 
    136 QVariant UIChooserItemGlobal::data(int iKey) const
    137 {
    138     /* Provide other members with required data: */
    139     switch (iKey)
    140     {
    141         /* Layout hints: */
    142         case GlobalItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
    143         case GlobalItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
    144 
    145         /* Default: */
    146         default: break;
    147     }
    148     return QVariant();
    149 }
    150 
    151 void 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 
    161     /* Update linked values: */
    162     if (m_pixmapSize != pixmapSize)
    163     {
    164         m_pixmapSize = pixmapSize;
    165         updateMaximumNameWidth();
    166         updateGeometry();
    167     }
    168     if (m_pixmap.toImage() != pixmap.toImage())
    169     {
    170         m_pixmap = pixmap;
    171         update();
    172     }
    173 }
    174 
    175 void UIChooserItemGlobal::updateMinimumNameWidth()
    176 {
    177     /* Calculate new minimum name width: */
    178     QPaintDevice *pPaintDevice = model()->paintDevice();
    179     const QFontMetrics fm(m_nameFont, pPaintDevice);
    180     const int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15)));
    181 
    182     /* Is there something changed? */
    183     if (m_iMinimumNameWidth == iMinimumNameWidth)
    184         return;
    185 
    186     /* Update linked values: */
    187     m_iMinimumNameWidth = iMinimumNameWidth;
    188     updateGeometry();
    189 }
    190 
    191 void UIChooserItemGlobal::updateMaximumNameWidth()
    192 {
    193     /* Prepare variables: */
    194     const int iMargin = data(GlobalItemData_Margin).toInt();
    195     const int iSpacing = data(GlobalItemData_Spacing).toInt();
    196 
    197     /* Calculate new maximum name width: */
    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 */
    203 
    204     /* Is there something changed? */
    205     if (m_iMaximumNameWidth == iMaximumNameWidth)
    206         return;
    207 
    208     /* Update linked values: */
    209     m_iMaximumNameWidth = iMaximumNameWidth;
    210     updateVisibleName();
    211 }
    212 
    213 void UIChooserItemGlobal::updateVisibleName()
    214 {
    215     /* Prepare variables: */
    216     QPaintDevice *pPaintDevice = model()->paintDevice();
    217 
    218     /* Calculate new visible name and name-size: */
    219     const QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
    220     const QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName);
    221 
    222     /* Update linked values: */
    223     if (m_visibleNameSize != visibleNameSize)
    224     {
    225         m_visibleNameSize = visibleNameSize;
    226         updateGeometry();
    227     }
    228     if (m_strVisibleName != strVisibleName)
    229     {
    230         m_strVisibleName = strVisibleName;
    231         update();
    232     }
    233 }
    234 
    235120void UIChooserItemGlobal::retranslateUi()
    236121{
     
    247132}
    248133
     134void UIChooserItemGlobal::showEvent(QShowEvent *pEvent)
     135{
     136    /* Call to base-class: */
     137    UIChooserItem::showEvent(pEvent);
     138
     139    /* Update pixmaps: */
     140    updatePixmap();
     141}
     142
     143void UIChooserItemGlobal::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
     144{
     145    /* Call to base-class: */
     146    UIChooserItem::resizeEvent(pEvent);
     147
     148    /* What is the new geometry? */
     149    const QRectF newGeometry = geometry();
     150
     151    /* Should we update visible name? */
     152    if (previousGeometry().width() != newGeometry.width())
     153        updateMaximumNameWidth();
     154
     155    /* Remember the new geometry: */
     156    setPreviousGeometry(newGeometry);
     157}
     158
     159void UIChooserItemGlobal::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
     160{
     161    /* Call to base-class: */
     162    UIChooserItem::mousePressEvent(pEvent);
     163    /* No drag at all: */
     164    pEvent->ignore();
     165}
     166
     167void UIChooserItemGlobal::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget * /* pWidget = 0 */)
     168{
     169    /* Setup: */
     170    pPainter->setRenderHint(QPainter::Antialiasing);
     171
     172    /* Paint decorations: */
     173    paintDecorations(pPainter, pOption);
     174
     175    /* Paint global info: */
     176    paintGlobalInfo(pPainter, pOption);
     177}
     178
    249179void UIChooserItemGlobal::startEditing()
    250180{
     
    257187}
    258188
    259 void UIChooserItemGlobal::addItem(UIChooserItem*, int)
     189QString UIChooserItemGlobal::name() const
     190{
     191    return m_strName;
     192}
     193
     194QString UIChooserItemGlobal::description() const
     195{
     196    return m_strDescription;
     197}
     198
     199QString UIChooserItemGlobal::fullName() const
     200{
     201    return m_strName;
     202}
     203
     204QString UIChooserItemGlobal::definition() const
     205{
     206    return QString("n=%1").arg(name());
     207}
     208
     209void UIChooserItemGlobal::addItem(UIChooserItem *, int)
    260210{
    261211    AssertMsgFailed(("Global graphics item do NOT support children!"));
    262212}
    263213
    264 void UIChooserItemGlobal::removeItem(UIChooserItem*)
     214void UIChooserItemGlobal::removeItem(UIChooserItem *)
    265215{
    266216    AssertMsgFailed(("Global graphics item do NOT support children!"));
    267217}
    268218
    269 void UIChooserItemGlobal::setItems(const QList<UIChooserItem*>&, UIChooserItemType)
     219void UIChooserItemGlobal::setItems(const QList<UIChooserItem*> &, UIChooserItemType)
    270220{
    271221    AssertMsgFailed(("Global graphics item do NOT support children!"));
     
    321271{
    322272    AssertMsgFailed(("Global graphics item do NOT support children!"));
     273}
     274
     275void UIChooserItemGlobal::updateLayout()
     276{
     277    // Just do nothing ..
     278}
     279
     280QSizeF UIChooserItemGlobal::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
     281{
     282    /* If Qt::MinimumSize requested: */
     283    if (which == Qt::MinimumSize)
     284        return QSizeF(minimumWidthHint(), minimumHeightHint());
     285    /* Else call to base-class: */
     286    return UIChooserItem::sizeHint(which, constraint);
    323287}
    324288
     
    358322    /* Return result: */
    359323    return iProposedHeight;
    360 }
    361 
    362 QSizeF UIChooserItemGlobal::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    363 {
    364     /* If Qt::MinimumSize requested: */
    365     if (which == Qt::MinimumSize)
    366         return QSizeF(minimumWidthHint(), minimumHeightHint());
    367     /* Else call to base-class: */
    368     return UIChooserItem::sizeHint(which, constraint);
    369324}
    370325
     
    403358}
    404359
    405 void UIChooserItemGlobal::showEvent(QShowEvent *pEvent)
    406 {
    407     /* Call to base-class: */
    408     UIChooserItem::showEvent(pEvent);
    409 
    410     /* Update pixmaps: */
     360void UIChooserItemGlobal::sltHandleWindowRemapped()
     361{
    411362    updatePixmap();
    412363}
    413364
    414 void UIChooserItemGlobal::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
    415 {
    416     /* Call to base-class: */
    417     UIChooserItem::resizeEvent(pEvent);
    418 
    419     /* What is the new geometry? */
    420     const QRectF newGeometry = geometry();
    421 
    422     /* Should we update visible name? */
    423     if (previousGeometry().width() != newGeometry.width())
     365void UIChooserItemGlobal::prepare()
     366{
     367    /* Colors: */
     368#ifdef VBOX_WS_MAC
     369    m_iHighlightLightness = 115;
     370    m_iHoverLightness = 110;
     371    m_iHoverHighlightLightness = 120;
     372#else /* VBOX_WS_MAC */
     373    m_iHighlightLightness = 130;
     374    m_iHoverLightness = 155;
     375    m_iHoverHighlightLightness = 175;
     376#endif /* !VBOX_WS_MAC */
     377
     378    /* Fonts: */
     379    m_nameFont = font();
     380    m_nameFont.setWeight(QFont::Bold);
     381
     382    /* Sizes: */
     383    m_iMinimumNameWidth = 0;
     384    m_iMaximumNameWidth = 0;
     385}
     386
     387QVariant UIChooserItemGlobal::data(int iKey) const
     388{
     389    /* Provide other members with required data: */
     390    switch (iKey)
     391    {
     392        /* Layout hints: */
     393        case GlobalItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;
     394        case GlobalItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;
     395
     396        /* Default: */
     397        default: break;
     398    }
     399    return QVariant();
     400}
     401
     402void UIChooserItemGlobal::updatePixmap()
     403{
     404    /* Acquire new metric, then compose pixmap-size: */
     405    const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     406    const QSize pixmapSize = QSize(iMetric, iMetric);
     407
     408    /* Create new icon, then acquire pixmap: */
     409    const QIcon icon = UIIconPool::iconSet(":/tools_global_32px.png");
     410    const QPixmap pixmap = icon.pixmap(gpManager->windowHandle(), pixmapSize);
     411
     412    /* Update linked values: */
     413    if (m_pixmapSize != pixmapSize)
     414    {
     415        m_pixmapSize = pixmapSize;
    424416        updateMaximumNameWidth();
    425 
    426     /* Remember the new geometry: */
    427     setPreviousGeometry(newGeometry);
    428 }
    429 
    430 void UIChooserItemGlobal::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
    431 {
    432     /* Call to base-class: */
    433     UIChooserItem::mousePressEvent(pEvent);
    434     /* No drag at all: */
    435     pEvent->ignore();
    436 }
    437 
    438 void UIChooserItemGlobal::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget * /* pWidget = 0 */)
    439 {
    440     /* Setup: */
    441     pPainter->setRenderHint(QPainter::Antialiasing);
    442 
    443     /* Paint decorations: */
    444     paintDecorations(pPainter, pOption);
    445 
    446     /* Paint machine info: */
    447     paintMachineInfo(pPainter, pOption);
     417        updateGeometry();
     418    }
     419    if (m_pixmap.toImage() != pixmap.toImage())
     420    {
     421        m_pixmap = pixmap;
     422        update();
     423    }
     424}
     425
     426void UIChooserItemGlobal::updateMinimumNameWidth()
     427{
     428    /* Calculate new minimum name width: */
     429    QPaintDevice *pPaintDevice = model()->paintDevice();
     430    const QFontMetrics fm(m_nameFont, pPaintDevice);
     431    const int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15)));
     432
     433    /* Is there something changed? */
     434    if (m_iMinimumNameWidth == iMinimumNameWidth)
     435        return;
     436
     437    /* Update linked values: */
     438    m_iMinimumNameWidth = iMinimumNameWidth;
     439    updateGeometry();
     440}
     441
     442void UIChooserItemGlobal::updateMaximumNameWidth()
     443{
     444    /* Prepare variables: */
     445    const int iMargin = data(GlobalItemData_Margin).toInt();
     446    const int iSpacing = data(GlobalItemData_Spacing).toInt();
     447
     448    /* Calculate new maximum name width: */
     449    int iMaximumNameWidth = (int)geometry().width();
     450    iMaximumNameWidth -= iMargin; /* left margin */
     451    iMaximumNameWidth -= m_pixmapSize.width(); /* pixmap width */
     452    iMaximumNameWidth -= iSpacing; /* spacing between pixmap and name */
     453    iMaximumNameWidth -= iMargin; /* right margin */
     454
     455    /* Is there something changed? */
     456    if (m_iMaximumNameWidth == iMaximumNameWidth)
     457        return;
     458
     459    /* Update linked values: */
     460    m_iMaximumNameWidth = iMaximumNameWidth;
     461    updateVisibleName();
     462}
     463
     464void UIChooserItemGlobal::updateVisibleName()
     465{
     466    /* Prepare variables: */
     467    QPaintDevice *pPaintDevice = model()->paintDevice();
     468
     469    /* Calculate new visible name and name-size: */
     470    const QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
     471    const QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName);
     472
     473    /* Update linked values: */
     474    if (m_visibleNameSize != visibleNameSize)
     475    {
     476        m_visibleNameSize = visibleNameSize;
     477        updateGeometry();
     478    }
     479    if (m_strVisibleName != strVisibleName)
     480    {
     481        m_strVisibleName = strVisibleName;
     482        update();
     483    }
    448484}
    449485
     
    512548}
    513549
    514 void UIChooserItemGlobal::paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
     550void UIChooserItemGlobal::paintGlobalInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
    515551{
    516552    /* Prepare variables: */
     
    581617    }
    582618}
    583 
    584 void UIChooserItemGlobal::prepare()
    585 {
    586     /* Colors: */
    587 #ifdef VBOX_WS_MAC
    588     m_iHighlightLightness = 115;
    589     m_iHoverLightness = 110;
    590     m_iHoverHighlightLightness = 120;
    591 #else /* VBOX_WS_MAC */
    592     m_iHighlightLightness = 130;
    593     m_iHoverLightness = 155;
    594     m_iHoverHighlightLightness = 175;
    595 #endif /* !VBOX_WS_MAC */
    596 
    597     /* Fonts: */
    598     m_nameFont = font();
    599     m_nameFont.setWeight(QFont::Bold);
    600 
    601     /* Sizes: */
    602     m_iMinimumNameWidth = 0;
    603     m_iMaximumNameWidth = 0;
    604 }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h

    r73927 r73954  
    1616 */
    1717
    18 #ifndef __UIChooserItemGlobal_h__
    19 #define __UIChooserItemGlobal_h__
     18#ifndef ___UIChooserItemGlobal_h___
     19#define ___UIChooserItemGlobal_h___
    2020
    2121/* GUI includes: */
     
    2323
    2424/* Forward declarations: */
     25class QMimeData;
     26class QPainter;
     27class QStyleOptionGraphicsItem;
    2528class UIGraphicsToolBar;
    2629class UIGraphicsZoomButton;
    2730
    28 /* Machine-item enumeration flags: */
    29 enum UIChooserItemGlobalEnumerationFlag
    30 {
    31     UIChooserItemGlobalEnumerationFlag_Unique       = RT_BIT(0),
    32     UIChooserItemGlobalEnumerationFlag_Inaccessible = RT_BIT(1)
    33 };
    34 
    35 /* Graphics global-item
    36  * for graphics selector model/view architecture: */
     31/** UIChooserItem extension implementing global item. */
    3732class UIChooserItemGlobal : public UIChooserItem
    3833{
     
    4136public:
    4237
    43     /* Graphics-item type: */
     38    /** RTTI item type. */
    4439    enum { Type = UIChooserItemType_Global };
    45     int type() const { return Type; }
    46 
    47     /* Constructor (new item): */
     40
     41    /** Constructs item with specified @a iPosition, passing @a pParent to the base-class. */
    4842    UIChooserItemGlobal(UIChooserItem *pParent, int iPosition = -1);
    49     /* Constructor (new item copy): */
     43    /** Constructs temporary item with specified @a iPosition as a @a pCopyFrom, passing @a pParent to the base-class. */
    5044    UIChooserItemGlobal(UIChooserItem *pParent, UIChooserItemGlobal *pCopyFrom, int iPosition = -1);
    51     /* Destructor: */
    52     ~UIChooserItemGlobal();
    53 
    54     /* API: Basic stuff: */
    55     QString name() const;
    56     QString description() const;
    57     QString fullName() const;
    58     QString definition() const;
     45    /** Destructs global item. */
     46    virtual ~UIChooserItemGlobal() /* override */;
     47
     48protected:
     49
     50    /** @name Event-handling stuff.
     51      * @{ */
     52        /** Handles translation event. */
     53        virtual void retranslateUi() /* override */;
     54
     55        /** Handles show @a pEvent. */
     56        virtual void showEvent(QShowEvent *pEvent) /* override */;
     57
     58        /** Handles resize @a pEvent. */
     59        virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
     60
     61        /** Handles mouse press @a pEvent. */
     62        virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) /* override */;
     63
     64        /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
     65        virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
     66    /** @} */
     67
     68    /** @name Item stuff.
     69      * @{ */
     70        /** Returns RTTI item type. */
     71        virtual int type() const /* override */ { return Type; }
     72
     73        /** Starts item editing. */
     74        virtual void startEditing() /* override */;
     75
     76        /** Updates item tool-tip. */
     77        virtual void updateToolTip() /* override */;
     78
     79        /** Returns item name. */
     80        virtual QString name() const /* override */;
     81        /** Returns item description. */
     82        virtual QString description() const /* override */;
     83        /** Returns item full-name. */
     84        virtual QString fullName() const /* override */;
     85        /** Returns item definition. */
     86        virtual QString definition() const /* override */;
     87    /** @} */
     88
     89    /** @name Children stuff.
     90      * @{ */
     91        /** Adds child @a pItem to certain @a iPosition. */
     92        virtual void addItem(UIChooserItem *pItem, int iPosition) /* override */;
     93        /** Removes child @a pItem. */
     94        virtual void removeItem(UIChooserItem *pItem) /* override */;
     95
     96        /** Replaces children @a items of certain @a enmType. */
     97        virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;
     98        /** Returns children items of certain @a enmType. */
     99        virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
     100        /** Returns whether there are children items of certain @a enmType. */
     101        virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
     102        /** Clears children items of certain @a enmType. */
     103        virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;
     104
     105        /** Updates all children items with specified @a strId. */
     106        virtual void updateAllItems(const QString &strId) /* override */;
     107        /** Removes all children items with specified @a strId. */
     108        virtual void removeAllItems(const QString &strId) /* override */;
     109
     110        /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
     111        virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags) /* override */;
     112
     113        /** Searches for a first machine child item. */
     114        virtual UIChooserItem *firstMachineItem() /* override */;
     115
     116        /** Sorts children items. */
     117        virtual void sortItems() /* override */;
     118    /** @} */
     119
     120    /** @name Layout stuff.
     121      * @{ */
     122        /** Updates layout. */
     123        virtual void updateLayout() /* override */;
     124
     125        /** Returns minimum width-hint. */
     126        virtual int minimumWidthHint() const /* override */;
     127        /** Returns minimum height-hint. */
     128        virtual int minimumHeightHint() const /* override */;
     129
     130        /** Returns size-hint.
     131          * @param  enmWhich    Brings size-hint type.
     132          * @param  constraint  Brings size constraint. */
     133        virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
     134    /** @} */
     135
     136    /** @name Navigation stuff.
     137      * @{ */
     138        /** Returns pixmap item representation. */
     139        virtual QPixmap toPixmap() /* override */;
     140
     141        /** Returns whether item drop is allowed.
     142          * @param  pEvent    Brings information about drop event.
     143          * @param  enmPlace  Brings the place of drag token to the drop moment. */
     144        virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const /* override */;
     145        /** Processes item drop.
     146          * @param  pEvent    Brings information about drop event.
     147          * @param  pFromWho  Brings the item according to which we choose drop position.
     148          * @param  enmPlace  Brings the place of drag token to the drop moment (according to item mentioned above). */
     149        virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where) /* override */;
     150        /** Reset drag token. */
     151        virtual void resetDragToken() /* override */;
     152
     153        /** Returns D&D mime data. */
     154        virtual QMimeData *createMimeData() /* override */;
     155    /** @} */
    59156
    60157private slots:
    61158
    62     /** Handles top-level window remaps. */
    63     void sltHandleWindowRemapped();
     159    /** @name Item stuff.
     160      * @{ */
     161        /** Handles top-level window remaps. */
     162        void sltHandleWindowRemapped();
     163    /** @} */
    64164
    65165private:
    66166
    67     /* Data enumerator: */
     167    /** Data field types. */
    68168    enum GlobalItemData
    69169    {
     
    73173    };
    74174
    75     /* Data provider: */
    76     QVariant data(int iKey) const;
    77 
    78     /* Helpers: Update stuff: */
    79     void updatePixmap();
    80     void updateMinimumNameWidth();
    81     void updateMaximumNameWidth();
    82     void updateVisibleName();
    83 
    84     /* Helper: Translate stuff: */
    85     void retranslateUi();
    86 
    87     /* Helpers: Basic stuff: */
    88     void startEditing();
    89     void updateToolTip();
    90 
    91     /* Helpers: Children stuff: */
    92     void addItem(UIChooserItem *pItem, int iPosition);
    93     void removeItem(UIChooserItem *pItem);
    94     void setItems(const QList<UIChooserItem*> &items, UIChooserItemType type);
    95     QList<UIChooserItem*> items(UIChooserItemType type) const;
    96     bool hasItems(UIChooserItemType type) const;
    97     void clearItems(UIChooserItemType type);
    98     void updateAllItems(const QString &strId);
    99     void removeAllItems(const QString &strId);
    100     UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    101     UIChooserItem *firstMachineItem();
    102     void sortItems();
    103 
    104     /* Helpers: Layout stuff: */
    105     void updateLayout() {}
    106     int minimumWidthHint() const;
    107     int minimumHeightHint() const;
    108     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
    109 
    110     /* Helpers: Drag and drop stuff: */
    111     QPixmap toPixmap();
    112     bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const;
    113     void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where);
    114     void resetDragToken();
    115     QMimeData *createMimeData();
    116 
    117     /** Handles show @a pEvent. */
    118     virtual void showEvent(QShowEvent *pEvent) /* override */;
    119 
    120     /* Handler: Resize handling stuff: */
    121     void resizeEvent(QGraphicsSceneResizeEvent *pEvent);
    122 
    123     /* Handler: Mouse handling stuff: */
    124     void mousePressEvent(QGraphicsSceneMouseEvent *pEvent);
    125 
    126     /* Helpers: Paint stuff: */
    127     void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0);
    128     void paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption);
    129     void paintBackground(QPainter *pPainter, const QRect &rect);
    130     void paintFrameRectangle(QPainter *pPainter, const QRect &rect);
    131     void paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption);
    132 
    133     /* Helpers: Prepare stuff: */
    134     void prepare();
    135 
    136     /* Helper: Machine-item enumeration stuff: */
    137     static bool contains(const QList<UIChooserItemGlobal*> &list,
    138                          UIChooserItemGlobal *pItem);
    139 
    140     /* Variables: */
    141     int m_iHighlightLightness;
    142     int m_iHoverLightness;
    143     int m_iHoverHighlightLightness;
    144     /* Cached values: */
    145     QFont m_nameFont;
    146     QPixmap m_pixmap;
    147     QString m_strName;
    148     QString m_strDescription;
    149     QString m_strVisibleName;
    150     QSize m_pixmapSize;
    151     QSize m_visibleNameSize;
    152     int m_iMinimumNameWidth;
    153     int m_iMaximumNameWidth;
     175    /** @name Prepare/cleanup cascade.
     176      * @{ */
     177        /** Prepares all. */
     178        void prepare();
     179    /** @} */
     180
     181    /** @name Item stuff.
     182      * @{ */
     183        /** Returns abstractly stored data value for certain @a iKey. */
     184        QVariant data(int iKey) const;
     185    /** @} */
     186
     187    /** @name Layout stuff.
     188      * @{ */
     189        /** Updates pixmap. */
     190        void updatePixmap();
     191        /** Updates minimum name width. */
     192        void updateMinimumNameWidth();
     193        /** Updates maximum name width. */
     194        void updateMaximumNameWidth();
     195        /** Updates visible name. */
     196        void updateVisibleName();
     197    /** @} */
     198
     199    /** @name Painting stuff.
     200      * @{ */
     201        /** Paints decorations using specified @a pPainter and certain @a pOptions. */
     202        void paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions);
     203        /** Paints background using specified @a pPainter and certain @a rect. */
     204        void paintBackground(QPainter *pPainter, const QRect &rect);
     205        /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
     206        void paintFrameRectangle(QPainter *pPainter, const QRect &rect);
     207        /** Paints global info using specified @a pPainter and certain @a pOptions. */
     208        void paintGlobalInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions);
     209    /** @} */
     210
     211    /** @name Item stuff.
     212      * @{ */
     213        /** Holds item hover lightness. */
     214        int  m_iHoverLightness;
     215        /** Holds item highlight lightness. */
     216        int  m_iHighlightLightness;
     217        /** Holds item hover highlight lightness. */
     218        int  m_iHoverHighlightLightness;
     219
     220        /** Holds item pixmap. */
     221        QPixmap  m_pixmap;
     222
     223        /** Holds item name. */
     224        QString  m_strName;
     225        /** Holds item description. */
     226        QString  m_strDescription;
     227        /** Holds item visible name. */
     228        QString  m_strVisibleName;
     229
     230        /** Holds item name font. */
     231        QFont  m_nameFont;
     232    /** @} */
     233
     234    /** @name Layout stuff.
     235      * @{ */
     236        /** Holds pixmap size. */
     237        QSize  m_pixmapSize;
     238        /** Holds visible name size. */
     239        QSize  m_visibleNameSize;
     240
     241        /** Holds minimum name width. */
     242        int  m_iMinimumNameWidth;
     243        /** Holds maximum name width. */
     244        int  m_iMaximumNameWidth;
     245    /** @} */
    154246};
    155247
    156 #endif /* __UIChooserItemGlobal_h__ */
     248#endif /* !___UIChooserItemGlobal_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h

    r73948 r73954  
    6161    enum { Type = UIChooserItemType_Group };
    6262
    63     /** Constructs main-root item passing pScene to the base-class. */
     63    /** Constructs main-root item, passing pScene to the base-class. */
    6464    UIChooserItemGroup(QGraphicsScene *pScene);
    65     /** Constructs temporary @a fMainRoot item as a @a pCopyFrom passing pScene to the base-class. */
     65    /** Constructs temporary @a fMainRoot item as a @a pCopyFrom, passing pScene to the base-class. */
    6666    UIChooserItemGroup(QGraphicsScene *pScene, UIChooserItemGroup *pCopyFrom, bool fMainRoot);
    67     /** Constructs non-root item with specified @a strName and @a iPosition, @a fOpened if requested. */
     67    /** Constructs non-root item with specified @a strName and @a iPosition, @a fOpened if requested, passing pParent to the base-class. */
    6868    UIChooserItemGroup(UIChooserItem *pParent, const QString &strName, bool fOpened = false, int iPosition  = -1);
    69     /** Constructs temporary non-root item with specified @a iPosition as a @a pCopyFrom. */
     69    /** Constructs temporary non-root item with specified @a iPosition as a @a pCopyFrom, passing pParent to the base-class. */
    7070    UIChooserItemGroup(UIChooserItem *pParent, UIChooserItemGroup *pCopyFrom, int iPosition = -1);
    7171    /** Destructs group item. */
    72     ~UIChooserItemGroup();
     72    virtual ~UIChooserItemGroup() /* override */;
    7373
    7474    /** @name Item 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