Changeset 75529 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 16, 2018 5:46:04 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/details
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsModel.cpp
r75526 r75529 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 29 29 /* GUI includes: */ 30 # include "UIConverter.h" 30 31 # include "UIDetails.h" 31 32 # include "UIDetailsModel.h" … … 34 35 # include "UIExtraDataManager.h" 35 36 # include "VBoxGlobal.h" 36 # include "UIConverter.h"37 37 38 38 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 39 39 40 41 /********************************************************************************************************************************* 42 * Class UIDetailsModel implementation. * 43 *********************************************************************************************************************************/ 40 44 41 45 UIDetailsModel::UIDetailsModel(UIDetails *pParent) … … 54 58 } 55 59 56 QGraphicsScene *UIDetailsModel::scene() const60 QGraphicsScene *UIDetailsModel::scene() const 57 61 { 58 62 return m_pScene; 59 63 } 60 64 61 QGraphicsView *UIDetailsModel::paintDevice() const62 { 63 if ( !m_pScene ||m_pScene->views().isEmpty())64 return 0;65 return m_pScene->views().first();66 } 67 68 QGraphicsItem *UIDetailsModel::itemAt(const QPointF &position) const65 QGraphicsView *UIDetailsModel::paintDevice() const 66 { 67 if (m_pScene && !m_pScene->views().isEmpty()) 68 return m_pScene->views().first(); 69 return 0; 70 } 71 72 QGraphicsItem *UIDetailsModel::itemAt(const QPointF &position) const 69 73 { 70 74 return scene()->itemAt(position, QTransform()); … … 97 101 void UIDetailsModel::sltHandleViewResize() 98 102 { 99 /* Relayout: */100 103 updateLayout(); 101 104 } … … 125 128 { 126 129 m_pRoot->rebuildGroup(); 130 } 131 132 bool UIDetailsModel::eventFilter(QObject *pObject, QEvent *pEvent) 133 { 134 /* Handle allowed context-menu events: */ 135 if (pObject == scene() && pEvent->type() == QEvent::GraphicsSceneContextMenu) 136 return processContextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(pEvent)); 137 138 /* Call to base-class: */ 139 return QObject::eventFilter(pObject, pEvent); 127 140 } 128 141 … … 165 178 } 166 179 167 void UIDetailsModel::sltToggleAnimationFinished(DetailsElementType type, bool fToggled)180 void UIDetailsModel::sltToggleAnimationFinished(DetailsElementType enmType, bool fToggled) 168 181 { 169 182 /* Cleanup animation callback: */ … … 177 190 { 178 191 UIDetailsElement *pElement = pElementItem->toElement(); 179 if (pElement->elementType() == type)192 if (pElement->elementType() == enmType) 180 193 pElement->markAnimationFinished(); 181 194 } … … 185 198 186 199 /* Update element open/close status: */ 187 if (m_categories.contains( type))188 m_categories[ type] = fToggled;200 if (m_categories.contains(enmType)) 201 m_categories[enmType] = fToggled; 189 202 } 190 203 … … 193 206 /* Which item was toggled? */ 194 207 QAction *pAction = qobject_cast<QAction*>(sender()); 195 DetailsElementType type = pAction->data().value<DetailsElementType>();208 DetailsElementType enmType = pAction->data().value<DetailsElementType>(); 196 209 197 210 /* Toggle element visibility status: */ 198 if (m_categories.contains( type))199 m_categories.remove( type);211 if (m_categories.contains(enmType)) 212 m_categories.remove(enmType); 200 213 else 201 m_categories[ type] = true;214 m_categories[enmType] = true; 202 215 203 216 /* Rebuild group: */ … … 256 269 cleanupRoot(); 257 270 cleanupScene(); 258 }259 260 bool UIDetailsModel::eventFilter(QObject *pObject, QEvent *pEvent)261 {262 /* Ignore if no scene object: */263 if (pObject != scene())264 return QObject::eventFilter(pObject, pEvent);265 266 /* Ignore if no context-menu event: */267 if (pEvent->type() != QEvent::GraphicsSceneContextMenu)268 return QObject::eventFilter(pObject, pEvent);269 270 /* Process context menu event: */271 return processContextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(pEvent));272 271 } 273 272 … … 284 283 for (int iType = DetailsElementType_General; iType <= DetailsElementType_Description; ++iType) 285 284 { 286 DetailsElementType currentElementType = (DetailsElementType)iType;287 QAction *pAction = contextMenu.addAction(gpConverter->toString( currentElementType), this, SLOT(sltElementTypeToggled()));285 const DetailsElementType enmCurrentElementType = (DetailsElementType)iType; 286 QAction *pAction = contextMenu.addAction(gpConverter->toString(enmCurrentElementType), this, SLOT(sltElementTypeToggled())); 288 287 pAction->setCheckable(true); 289 pAction->setChecked(m_categories.contains( currentElementType));290 pAction->setData(QVariant::fromValue( currentElementType));288 pAction->setChecked(m_categories.contains(enmCurrentElementType)); 289 pAction->setData(QVariant::fromValue(enmCurrentElementType)); 291 290 } 292 291 /* Exec context-menu: */ … … 297 296 } 298 297 299 UIDetailsElementAnimationCallback::UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType type, bool fToggled) 298 299 /********************************************************************************************************************************* 300 * Class UIDetailsElementAnimationCallback implementation. * 301 *********************************************************************************************************************************/ 302 303 UIDetailsElementAnimationCallback::UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType enmType, bool fToggled) 300 304 : QObject(pParent) 301 , m_ type(type)305 , m_enmType(enmType) 302 306 , m_fToggled(fToggled) 303 307 { 304 308 } 305 309 306 void UIDetailsElementAnimationCallback::addNotifier(UIDetails Item*pItem)310 void UIDetailsElementAnimationCallback::addNotifier(UIDetailsElement *pItem) 307 311 { 308 312 /* Connect notifier: */ 309 connect(pItem, SIGNAL(sigToggleElementFinished()), this, SLOT(sltAnimationFinished())); 313 connect(pItem, &UIDetailsElement::sigToggleElementFinished, 314 this, &UIDetailsElementAnimationCallback::sltAnimationFinished); 310 315 /* Remember notifier: */ 311 316 m_notifiers << pItem; … … 315 320 { 316 321 /* Determine notifier: */ 317 UIDetails Item *pItem = qobject_cast<UIDetailsItem*>(sender());322 UIDetailsElement *pItem = qobject_cast<UIDetailsElement*>(sender()); 318 323 /* Disconnect notifier: */ 319 disconnect(pItem, SIGNAL(sigToggleElementFinished()), this, SLOT(sltAnimationFinished())); 324 disconnect(pItem, &UIDetailsElement::sigToggleElementFinished, 325 this, &UIDetailsElementAnimationCallback::sltAnimationFinished); 320 326 /* Remove notifier: */ 321 327 m_notifiers.removeAll(pItem); 322 328 /* Check if we finished: */ 323 329 if (m_notifiers.isEmpty()) 324 emit sigAllAnimationFinished(m_type, m_fToggled); 325 } 326 330 emit sigAllAnimationFinished(m_enmType, m_fToggled); 331 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsModel.h
r75526 r75529 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UIDetailsModel_h__19 #define __ UIDetailsModel_h__18 #ifndef ___UIDetailsModel_h___ 19 #define ___UIDetailsModel_h___ 20 20 21 21 /* Qt includes: */ 22 #include <QMap> 22 23 #include <QObject> 23 24 #include <QPointer> 24 #include <QMap>25 25 #include <QSet> 26 26 … … 37 37 class QGraphicsView; 38 38 class UIVirtualMachineItem; 39 class UIDetails; 40 class UIDetailsElement; 39 41 class UIDetailsElementAnimationCallback; 40 42 class UIDetailsGroup; 41 43 class UIDetailsItem; 42 class UIDetails; 43 44 /* Graphics details-model:*/44 45 46 /** QObject sub-class used as graphics details model. */ 45 47 class UIDetailsModel : public QObject 46 48 { … … 49 51 signals: 50 52 51 /* Notifiers: Root-item stuff: */ 52 void sigRootItemMinimumWidthHintChanged(int iRootItemMinimumWidthHint); 53 void sigRootItemMinimumHeightHintChanged(int iRootItemMinimumHeightHint); 54 55 /* Notifier: Link processing stuff: */ 53 /** Notifies listeners about model root item @a iMinimumWidthHint changed. */ 54 void sigRootItemMinimumWidthHintChanged(int iMinimumWidthHint); 55 /** Notifies listeners about model root item @a iMinimumHeightHint changed. */ 56 void sigRootItemMinimumHeightHintChanged(int iMinimumHeightHint); 57 58 /** Notifies listeners about element link clicked. 59 * @param strCategory Brings details element category. 60 * @param strControl Brings settings control to select. 61 * @param uId Brings ID of the machine details referring. */ 56 62 void sigLinkClicked(const QString &strCategory, const QString &strControl, const QUuid &uId); 57 63 58 64 public: 59 65 60 /** Constructs a details -model passing @a pParent to the base-class.66 /** Constructs a details model passing @a pParent to the base-class. 61 67 * @param pParent Brings the details container to embed into. */ 62 68 UIDetailsModel(UIDetails *pParent); 63 /** Destructs a details-model. */ 64 ~UIDetailsModel(); 65 66 /* API: Scene stuff: */ 67 QGraphicsScene* scene() const; 68 QGraphicsView* paintDevice() const; 69 QGraphicsItem* itemAt(const QPointF &position) const; 70 71 /** Returns the details reference. */ 69 /** Destructs a details model. */ 70 virtual ~UIDetailsModel() /* override */; 71 72 /** Returns graphics scene this model belongs to. */ 73 QGraphicsScene *scene() const; 74 /** Returns paint device this model belongs to. */ 75 QGraphicsView *paintDevice() const; 76 77 /** Returns graphics item as certain @a position. */ 78 QGraphicsItem *itemAt(const QPointF &position) const; 79 80 /** Returns the details pane reference. */ 72 81 UIDetails *details() const { return m_pDetails; } 73 82 … … 75 84 UIDetailsItem *root() const; 76 85 77 /* API: Layout stuff:*/86 /** Updates layout by positioning items manually. */ 78 87 void updateLayout(); 79 88 80 /* API: Current-item(s) stuff:*/89 /** Defines virtual machine @a items for this model to reflect. */ 81 90 void setItems(const QList<UIVirtualMachineItem*> &items); 82 91 … … 86 95 public slots: 87 96 88 /* Handler: Details-view stuff:*/97 /** Handle details view resize. */ 89 98 void sltHandleViewResize(); 90 99 91 /* Handlers: Chooser stuff:*/100 /** Handles chooser pane signal about item sliding started. */ 92 101 void sltHandleSlidingStarted(); 102 /** Handles chooser pane signal about group toggle started. */ 93 103 void sltHandleToggleStarted(); 104 /** Handles chooser pane signal about group toggle finished. */ 94 105 void sltHandleToggleFinished(); 95 106 … … 99 110 void sltHandleExtraDataOptionsChange(DetailsElementType enmType); 100 111 112 protected: 113 114 /** Preprocesses any Qt @a pEvent for passed @a pObject. */ 115 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 116 101 117 private slots: 102 118 103 /* Handlers: Element-items stuff:*/119 /** Handles request to start toggle details element of certain @a enmType, making element @a fToggled. */ 104 120 void sltToggleElements(DetailsElementType type, bool fToggled); 121 /** Handles sigal about details element of certain @a enmType toggling finished, making element @a fToggled. */ 105 122 void sltToggleAnimationFinished(DetailsElementType type, bool fToggled); 123 124 /** Handles request about toggling visibility. */ 106 125 void sltElementTypeToggled(); 107 126 … … 129 148 /** @} */ 130 149 131 /* Handler: Event-filter: */ 132 bool eventFilter(QObject *pObject, QEvent *pEvent); 133 134 /* Handler: Context-menu stuff: */ 150 /** Performs handling for allowed context menu @a pEvent. */ 135 151 bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent); 136 152 … … 138 154 UIDetails *m_pDetails; 139 155 140 /* Variables: */ 141 QGraphicsScene *m_pScene; 142 UIDetailsGroup *m_pRoot; 156 /** Holds the graphics scene reference. */ 157 QGraphicsScene *m_pScene; 158 /** Holds the root element instance. */ 159 UIDetailsGroup *m_pRoot; 160 /** Holds the element animation callback instance. */ 143 161 UIDetailsElementAnimationCallback *m_pAnimationCallback; 144 162 … … 147 165 }; 148 166 149 /* Details-element animation callback: */ 167 168 /** QObject sub-class used as details element animation callback. */ 150 169 class UIDetailsElementAnimationCallback : public QObject 151 170 { … … 154 173 signals: 155 174 156 /* Notifier: Complete stuff: */ 157 void sigAllAnimationFinished(DetailsElementType type, bool fToggled); 175 /** Notifies listeners about all animations finished. 176 * @param enmType Brings the type of element item which was animated. 177 * @param fToggled Brigns whether elements being toggled to be closed or opened. */ 178 void sigAllAnimationFinished(DetailsElementType enmType, bool fToggled); 158 179 159 180 public: 160 181 161 /* Constructor: */ 162 UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType type, bool fToggled); 163 164 /* API: Notifiers stuff: */ 165 void addNotifier(UIDetailsItem *pItem); 182 /** Constructors details element animation callback passing @a pParent to the base-class. 183 * @param enmType Brings the type of element item which was animated. 184 * @param fToggled Brigns whether elements being toggled to be closed or opened. */ 185 UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType enmType, bool fToggled); 186 187 /** Adds notifier for a certain details @a pItem. */ 188 void addNotifier(UIDetailsElement *pItem); 166 189 167 190 private slots: 168 191 169 /* Handler: Progress stuff:*/192 /** Handles a signal about animation finnished. */ 170 193 void sltAnimationFinished(); 171 194 172 195 private: 173 196 174 /* Variables: */ 175 QList<UIDetailsItem*> m_notifiers; 176 DetailsElementType m_type; 177 bool m_fToggled; 197 /** Holds the list of elements which notifies this callback about completion. */ 198 QList<UIDetailsElement*> m_notifiers; 199 /** Holds the type of element item which was animated. */ 200 DetailsElementType m_enmType; 201 /** Holds whether elements being toggled to be closed or opened. */ 202 bool m_fToggled; 178 203 }; 179 204 180 #endif /* __UIDetailsModel_h__ */ 181 205 206 #endif /* !___UIDetailsModel_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.