Changeset 74042 in vbox for trunk/src/VBox
- Timestamp:
- Sep 3, 2018 12:54:45 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/details
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsGroup.cpp
r73424 r74042 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 … … 26 26 /* GUI includes: */ 27 27 # include "UIDetailsGroup.h" 28 # include "UIDetailsModel.h" 28 29 # include "UIDetailsSet.h" 29 # include "UIDetailsModel.h"30 30 # include "UIExtraDataManager.h" 31 # include "UIVirtualMachineItem.h" 31 32 # include "VBoxGlobal.h" 32 # include "UIVirtualMachineItem.h"33 33 34 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 37 37 UIDetailsGroup::UIDetailsGroup(QGraphicsScene *pParent) 38 38 : UIDetailsItem(0) 39 , m_pBuildStep(0) 39 40 , m_iPreviousMinimumWidthHint(0) 40 41 , m_iPreviousMinimumHeightHint(0) 41 , m_pBuildStep(0)42 42 { 43 43 /* Add group to the parent scene: */ … … 89 89 } 90 90 91 void UIDetailsGroup::sltBuildStep(QString strStepId, int iStepNumber) 92 { 93 /* Cleanup build-step: */ 94 delete m_pBuildStep; 95 m_pBuildStep = 0; 96 97 /* Is step id valid? */ 98 if (strStepId != m_strGroupId) 99 return; 100 101 /* Step number feats the bounds: */ 102 if (iStepNumber >= 0 && iStepNumber < m_machineItems.size()) 103 { 104 /* Should we create a new set for this step? */ 105 UIDetailsSet *pSet = 0; 106 if (iStepNumber > m_items.size() - 1) 107 pSet = new UIDetailsSet(this); 108 /* Or use existing? */ 109 else 110 pSet = m_items.at(iStepNumber)->toSet(); 111 112 /* Create next build-step: */ 113 m_pBuildStep = new UIPrepareStep(this, pSet, strStepId, iStepNumber + 1); 114 115 /* Build set: */ 116 pSet->buildSet(m_machineItems[iStepNumber], m_machineItems.size() == 1, model()->settings()); 117 } 118 else 119 { 120 /* Notify listener about build done: */ 121 emit sigBuildDone(); 122 } 123 } 124 125 QVariant UIDetailsGroup::data(int iKey) const 126 { 127 /* Provide other members with required data: */ 128 switch (iKey) 129 { 130 /* Layout hints: */ 131 case GroupData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 6; 132 case GroupData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 133 /* Default: */ 134 default: break; 135 } 136 return QVariant(); 137 } 138 139 void UIDetailsGroup::addItem(UIDetailsItem *pItem) 140 { 141 switch (pItem->type()) 142 { 143 case UIDetailsItemType_Set: m_items.append(pItem); break; 144 default: AssertMsgFailed(("Invalid item type!")); break; 145 } 146 } 147 148 void UIDetailsGroup::removeItem(UIDetailsItem *pItem) 149 { 150 switch (pItem->type()) 151 { 152 case UIDetailsItemType_Set: m_items.removeAt(m_items.indexOf(pItem)); break; 153 default: AssertMsgFailed(("Invalid item type!")); break; 154 } 155 } 156 157 QList<UIDetailsItem*> UIDetailsGroup::items(UIDetailsItemType type /* = UIDetailsItemType_Set */) const 158 { 159 switch (type) 91 QList<UIDetailsItem*> UIDetailsGroup::items(UIDetailsItemType enmType /* = UIDetailsItemType_Set */) const 92 { 93 switch (enmType) 160 94 { 161 95 case UIDetailsItemType_Set: return m_items; … … 164 98 } 165 99 return QList<UIDetailsItem*>(); 166 }167 168 bool UIDetailsGroup::hasItems(UIDetailsItemType type /* = UIDetailsItemType_Set */) const169 {170 switch (type)171 {172 case UIDetailsItemType_Set: return !m_items.isEmpty();173 case UIDetailsItemType_Any: return hasItems(UIDetailsItemType_Set);174 default: AssertMsgFailed(("Invalid item type!")); break;175 }176 return false;177 }178 179 void UIDetailsGroup::clearItems(UIDetailsItemType type /* = UIDetailsItemType_Set */)180 {181 switch (type)182 {183 case UIDetailsItemType_Set: while (!m_items.isEmpty()) { delete m_items.last(); } break;184 case UIDetailsItemType_Any: clearItems(UIDetailsItemType_Set); break;185 default: AssertMsgFailed(("Invalid item type!")); break;186 }187 }188 189 void UIDetailsGroup::prepareConnections()190 {191 /* Prepare group-item connections: */192 connect(this, SIGNAL(sigMinimumWidthHintChanged(int)),193 model(), SIGNAL(sigRootItemMinimumWidthHintChanged(int)));194 connect(this, SIGNAL(sigMinimumHeightHintChanged(int)),195 model(), SIGNAL(sigRootItemMinimumHeightHintChanged(int)));196 }197 198 void UIDetailsGroup::updateGeometry()199 {200 /* Call to base class: */201 UIDetailsItem::updateGeometry();202 203 /* Group-item should notify details-view if minimum-width-hint was changed: */204 int iMinimumWidthHint = minimumWidthHint();205 if (m_iPreviousMinimumWidthHint != iMinimumWidthHint)206 {207 /* Save new minimum-width-hint, notify listener: */208 m_iPreviousMinimumWidthHint = iMinimumWidthHint;209 emit sigMinimumWidthHintChanged(m_iPreviousMinimumWidthHint);210 }211 /* Group-item should notify details-view if minimum-height-hint was changed: */212 int iMinimumHeightHint = minimumHeightHint();213 if (m_iPreviousMinimumHeightHint != iMinimumHeightHint)214 {215 /* Save new minimum-height-hint, notify listener: */216 m_iPreviousMinimumHeightHint = iMinimumHeightHint;217 emit sigMinimumHeightHintChanged(m_iPreviousMinimumHeightHint);218 }219 }220 221 int UIDetailsGroup::minimumWidthHint() const222 {223 /* Prepare variables: */224 int iMargin = data(GroupData_Margin).toInt();225 int iMinimumWidthHint = 0;226 227 /* For each the set we have: */228 bool fHasItems = false;229 foreach (UIDetailsItem *pItem, items())230 {231 /* Ignore which are with no details: */232 if (UIDetailsSet *pSetItem = pItem->toSet())233 if (!pSetItem->hasDetails())234 continue;235 /* And take into account all the others: */236 iMinimumWidthHint = qMax(iMinimumWidthHint, pItem->minimumWidthHint());237 if (!fHasItems)238 fHasItems = true;239 }240 241 /* Add two margins finally: */242 if (fHasItems)243 iMinimumWidthHint += 2 * iMargin;244 245 /* Return result: */246 return iMinimumWidthHint;247 }248 249 int UIDetailsGroup::minimumHeightHint() const250 {251 /* Prepare variables: */252 int iMargin = data(GroupData_Margin).toInt();253 int iSpacing = data(GroupData_Spacing).toInt();254 int iMinimumHeightHint = 0;255 256 /* For each the set we have: */257 bool fHasItems = false;258 foreach (UIDetailsItem *pItem, items())259 {260 /* Ignore which are with no details: */261 if (UIDetailsSet *pSetItem = pItem->toSet())262 if (!pSetItem->hasDetails())263 continue;264 /* And take into account all the others: */265 iMinimumHeightHint += (pItem->minimumHeightHint() + iSpacing);266 if (!fHasItems)267 fHasItems = true;268 }269 /* Minus last spacing: */270 if (fHasItems)271 iMinimumHeightHint -= iSpacing;272 273 /* Add two margins finally: */274 if (fHasItems)275 iMinimumHeightHint += 2 * iMargin;276 277 /* Return result: */278 return iMinimumHeightHint;279 100 } 280 101 … … 306 127 } 307 128 129 void UIDetailsGroup::sltBuildStep(QString strStepId, int iStepNumber) 130 { 131 /* Cleanup build-step: */ 132 delete m_pBuildStep; 133 m_pBuildStep = 0; 134 135 /* Is step id valid? */ 136 if (strStepId != m_strGroupId) 137 return; 138 139 /* Step number feats the bounds: */ 140 if (iStepNumber >= 0 && iStepNumber < m_machineItems.size()) 141 { 142 /* Should we create a new set for this step? */ 143 UIDetailsSet *pSet = 0; 144 if (iStepNumber > m_items.size() - 1) 145 pSet = new UIDetailsSet(this); 146 /* Or use existing? */ 147 else 148 pSet = m_items.at(iStepNumber)->toSet(); 149 150 /* Create next build-step: */ 151 m_pBuildStep = new UIPrepareStep(this, pSet, strStepId, iStepNumber + 1); 152 153 /* Build set: */ 154 pSet->buildSet(m_machineItems[iStepNumber], m_machineItems.size() == 1, model()->settings()); 155 } 156 else 157 { 158 /* Notify listener about build done: */ 159 emit sigBuildDone(); 160 } 161 } 162 163 void UIDetailsGroup::addItem(UIDetailsItem *pItem) 164 { 165 switch (pItem->type()) 166 { 167 case UIDetailsItemType_Set: m_items.append(pItem); break; 168 default: AssertMsgFailed(("Invalid item type!")); break; 169 } 170 } 171 172 void UIDetailsGroup::removeItem(UIDetailsItem *pItem) 173 { 174 switch (pItem->type()) 175 { 176 case UIDetailsItemType_Set: m_items.removeAt(m_items.indexOf(pItem)); break; 177 default: AssertMsgFailed(("Invalid item type!")); break; 178 } 179 } 180 181 bool UIDetailsGroup::hasItems(UIDetailsItemType enmType /* = UIDetailsItemType_Set */) const 182 { 183 switch (enmType) 184 { 185 case UIDetailsItemType_Set: return !m_items.isEmpty(); 186 case UIDetailsItemType_Any: return hasItems(UIDetailsItemType_Set); 187 default: AssertMsgFailed(("Invalid item type!")); break; 188 } 189 return false; 190 } 191 192 void UIDetailsGroup::clearItems(UIDetailsItemType enmType /* = UIDetailsItemType_Set */) 193 { 194 switch (enmType) 195 { 196 case UIDetailsItemType_Set: while (!m_items.isEmpty()) { delete m_items.last(); } break; 197 case UIDetailsItemType_Any: clearItems(UIDetailsItemType_Set); break; 198 default: AssertMsgFailed(("Invalid item type!")); break; 199 } 200 } 201 202 void UIDetailsGroup::updateGeometry() 203 { 204 /* Call to base class: */ 205 UIDetailsItem::updateGeometry(); 206 207 /* Group-item should notify details-view if minimum-width-hint was changed: */ 208 int iMinimumWidthHint = minimumWidthHint(); 209 if (m_iPreviousMinimumWidthHint != iMinimumWidthHint) 210 { 211 /* Save new minimum-width-hint, notify listener: */ 212 m_iPreviousMinimumWidthHint = iMinimumWidthHint; 213 emit sigMinimumWidthHintChanged(m_iPreviousMinimumWidthHint); 214 } 215 /* Group-item should notify details-view if minimum-height-hint was changed: */ 216 int iMinimumHeightHint = minimumHeightHint(); 217 if (m_iPreviousMinimumHeightHint != iMinimumHeightHint) 218 { 219 /* Save new minimum-height-hint, notify listener: */ 220 m_iPreviousMinimumHeightHint = iMinimumHeightHint; 221 emit sigMinimumHeightHintChanged(m_iPreviousMinimumHeightHint); 222 } 223 } 224 225 int UIDetailsGroup::minimumWidthHint() const 226 { 227 /* Prepare variables: */ 228 int iMargin = data(GroupData_Margin).toInt(); 229 int iMinimumWidthHint = 0; 230 231 /* For each the set we have: */ 232 bool fHasItems = false; 233 foreach (UIDetailsItem *pItem, items()) 234 { 235 /* Ignore which are with no details: */ 236 if (UIDetailsSet *pSetItem = pItem->toSet()) 237 if (!pSetItem->hasDetails()) 238 continue; 239 /* And take into account all the others: */ 240 iMinimumWidthHint = qMax(iMinimumWidthHint, pItem->minimumWidthHint()); 241 if (!fHasItems) 242 fHasItems = true; 243 } 244 245 /* Add two margins finally: */ 246 if (fHasItems) 247 iMinimumWidthHint += 2 * iMargin; 248 249 /* Return result: */ 250 return iMinimumWidthHint; 251 } 252 253 int UIDetailsGroup::minimumHeightHint() const 254 { 255 /* Prepare variables: */ 256 int iMargin = data(GroupData_Margin).toInt(); 257 int iSpacing = data(GroupData_Spacing).toInt(); 258 int iMinimumHeightHint = 0; 259 260 /* For each the set we have: */ 261 bool fHasItems = false; 262 foreach (UIDetailsItem *pItem, items()) 263 { 264 /* Ignore which are with no details: */ 265 if (UIDetailsSet *pSetItem = pItem->toSet()) 266 if (!pSetItem->hasDetails()) 267 continue; 268 /* And take into account all the others: */ 269 iMinimumHeightHint += (pItem->minimumHeightHint() + iSpacing); 270 if (!fHasItems) 271 fHasItems = true; 272 } 273 /* Minus last spacing: */ 274 if (fHasItems) 275 iMinimumHeightHint -= iSpacing; 276 277 /* Add two margins finally: */ 278 if (fHasItems) 279 iMinimumHeightHint += 2 * iMargin; 280 281 /* Return result: */ 282 return iMinimumHeightHint; 283 } 284 285 void UIDetailsGroup::prepareConnections() 286 { 287 /* Prepare group-item connections: */ 288 connect(this, SIGNAL(sigMinimumWidthHintChanged(int)), 289 model(), SIGNAL(sigRootItemMinimumWidthHintChanged(int))); 290 connect(this, SIGNAL(sigMinimumHeightHintChanged(int)), 291 model(), SIGNAL(sigRootItemMinimumHeightHintChanged(int))); 292 } 293 294 QVariant UIDetailsGroup::data(int iKey) const 295 { 296 /* Provide other members with required data: */ 297 switch (iKey) 298 { 299 /* Layout hints: */ 300 case GroupData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 6; 301 case GroupData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 302 /* Default: */ 303 default: break; 304 } 305 return QVariant(); 306 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsGroup.h
r73424 r74042 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 __ UIDetailsGroup_h__19 #define __ UIDetailsGroup_h__18 #ifndef ___UIDetailsGroup_h___ 19 #define ___UIDetailsGroup_h___ 20 20 21 21 /* GUI includes: */ … … 23 23 24 24 /* Forward declarations: */ 25 class QGraphicsScene; 25 26 class UIVirtualMachineItem; 26 class QGraphicsScene;27 27 28 /* Details group 29 * for graphics details model/view architecture: */ 28 /** UIDetailsItem extension implementing group item. */ 30 29 class UIDetailsGroup : public UIDetailsItem 31 30 { … … 34 33 signals: 35 34 36 /* Notifiers: Size-hint stuff: */ 37 void sigMinimumWidthHintChanged(int iMinimumWidthHint); 38 void sigMinimumHeightHintChanged(int iMinimumHeightHint); 35 /** @name Layout stuff. 36 * @{ */ 37 /** Notifies listeners about @a iMinimumWidthHint changed. */ 38 void sigMinimumWidthHintChanged(int iMinimumWidthHint); 39 /** Notifies listeners about @a iMinimumHeightHint changed. */ 40 void sigMinimumHeightHintChanged(int iMinimumHeightHint); 41 /** @} */ 39 42 40 43 public: 41 44 42 /* Graphics-item type:*/45 /** RTTI item type. */ 43 46 enum { Type = UIDetailsItemType_Group }; 44 int type() const { return Type; }45 47 46 /* Constructor/destructor: */ 47 UIDetailsGroup(QGraphicsScene *pParent); 48 /** Constructs group item, passing pScene to the base-class. */ 49 UIDetailsGroup(QGraphicsScene *pScene); 50 /** Destructs group item. */ 48 51 ~UIDetailsGroup(); 49 52 50 /* API: Build stuff: */ 51 void buildGroup(const QList<UIVirtualMachineItem*> &machineItems); 52 void rebuildGroup(); 53 void stopBuildingGroup(); 53 /** @name Item stuff. 54 * @{ */ 55 /** Builds group based on passed @a machineItems. */ 56 void buildGroup(const QList<UIVirtualMachineItem*> &machineItems); 57 /** Builds group based on cached machine items. */ 58 void rebuildGroup(); 59 /** Stops currently building group. */ 60 void stopBuildingGroup(); 61 /** @} */ 54 62 55 private slots: 63 /** @name Children stuff. 64 * @{ */ 65 /** Returns children items of certain @a enmType. */ 66 virtual QList<UIDetailsItem*> items(UIDetailsItemType enmType = UIDetailsItemType_Set) const /* override */; 67 /** @} */ 56 68 57 /* Handler: Build stuff: */ 58 void sltBuildStep(QString strStepId, int iStepNumber); 69 /** @name Layout stuff. 70 * @{ */ 71 /** Updates layout. */ 72 virtual void updateLayout() /* override */; 73 /** @} */ 74 75 protected slots: 76 77 /** @name Item stuff. 78 * @{ */ 79 /** Handles request about starting step build. 80 * @param strStepId Brings the step ID. 81 * @param iStepNumber Brings the step number. */ 82 /** @} */ 83 virtual void sltBuildStep(QString strStepId, int iStepNumber) /* override */; 84 85 protected: 86 87 /** @name Item stuff. 88 * @{ */ 89 /** Returns RTTI item type. */ 90 virtual int type() const /* override */ { return Type; } 91 92 /** Returns the description of the item. */ 93 virtual QString description() const /* override */ { return QString(); } 94 /** @} */ 95 96 /** @name Children stuff. 97 * @{ */ 98 /** Adds child @a pItem. */ 99 virtual void addItem(UIDetailsItem *pItem) /* override */; 100 /** Removes child @a pItem. */ 101 virtual void removeItem(UIDetailsItem *pItem) /* override */; 102 103 /** Returns whether there are children items of certain @a enmType. */ 104 virtual bool hasItems(UIDetailsItemType enmType = UIDetailsItemType_Set) const /* override */; 105 /** Clears children items of certain @a enmType. */ 106 virtual void clearItems(UIDetailsItemType enmType = UIDetailsItemType_Set) /* override */; 107 /** @} */ 108 109 /** @name Layout stuff. 110 * @{ */ 111 /** Updates geometry. */ 112 virtual void updateGeometry() /* override */; 113 114 /** Returns minimum width-hint. */ 115 virtual int minimumWidthHint() const /* override */; 116 /** Returns minimum height-hint. */ 117 virtual int minimumHeightHint() const /* override */; 118 /** @} */ 59 119 60 120 private: 61 121 62 /* Data enumerator:*/122 /** Data field types. */ 63 123 enum GroupItemData 64 124 { … … 68 128 }; 69 129 70 /** Returns the description of the item. */ 71 virtual QString description() const /* override */ { return QString(); } 130 /** @name Prepare/cleanup cascade. 131 * @{ */ 132 /** Prepares connections. */ 133 void prepareConnections(); 134 /** @} */ 72 135 73 /* Data provider: */ 74 QVariant data(int iKey) const; 136 /** @name Item stuff. 137 * @{ */ 138 /** Returns abstractly stored data value for certain @a iKey. */ 139 QVariant data(int iKey) const; 140 /** @} */ 75 141 76 /* Hidden API: Children stuff: */ 77 void addItem(UIDetailsItem *pItem); 78 void removeItem(UIDetailsItem *pItem); 79 QList<UIDetailsItem*> items(UIDetailsItemType type = UIDetailsItemType_Set) const; 80 bool hasItems(UIDetailsItemType type = UIDetailsItemType_Set) const; 81 void clearItems(UIDetailsItemType type = UIDetailsItemType_Set); 142 /** @name Item stuff. 143 * @{ */ 144 /** Holds the build step instance. */ 145 UIPrepareStep *m_pBuildStep; 146 /** Holds the generated group ID. */ 147 QString m_strGroupId; 148 /** @} */ 82 149 83 /* Helpers: Prepare stuff: */ 84 void prepareConnections(); 150 /** @name Children stuff. 151 * @{ */ 152 /** Holds the cached machine item list. */ 153 QList<UIVirtualMachineItem*> m_machineItems; 85 154 86 /* Helpers: Layout stuff: */ 87 void updateGeometry(); 88 int minimumWidthHint() const; 89 int minimumHeightHint() const; 90 void updateLayout(); 155 /** Holds the child list (a list of sets). */ 156 QList<UIDetailsItem*> m_items; 157 /** @} */ 91 158 92 /* Variables: */ 93 int m_iPreviousMinimumWidthHint; 94 int m_iPreviousMinimumHeightHint; 95 QList<UIDetailsItem*> m_items; 96 QList<UIVirtualMachineItem*> m_machineItems; 97 UIPrepareStep *m_pBuildStep; 98 QString m_strGroupId; 99 100 /* Friends: */ 101 friend class UIDetailsModel; 159 /** @name Layout stuff. 160 * @{ */ 161 int m_iPreviousMinimumWidthHint; 162 int m_iPreviousMinimumHeightHint; 163 /** @} */ 102 164 }; 103 165 104 #endif /* __UIDetailsGroup_h__ */ 105 166 #endif /* !___UIDetailsGroup_h___ */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsItem.cpp
r74039 r74042 261 261 } 262 262 263 QSizeF UIDetailsItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const263 QSizeF UIDetailsItem::sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint /* = QSizeF() */) const 264 264 { 265 265 /* If Qt::MinimumSize or Qt::PreferredSize requested: */ 266 if ( which == Qt::MinimumSize || which == Qt::PreferredSize)266 if (enmWhich == Qt::MinimumSize || enmWhich == Qt::PreferredSize) 267 267 /* Return wrappers: */ 268 268 return QSizeF(minimumWidthHint(), minimumHeightHint()); 269 269 /* Call to base-class: */ 270 return QIGraphicsWidget::sizeHint( which, constraint);270 return QIGraphicsWidget::sizeHint(enmWhich, constraint); 271 271 } 272 272 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsItem.h
r74039 r74042 103 103 * @{ */ 104 104 /** Updates geometry. */ 105 v oid updateGeometry();105 virtual void updateGeometry() /* override */; 106 106 107 107 /** Updates layout. */ … … 116 116 * @param enmWhich Brings size-hint type. 117 117 * @param constraint Brings size constraint. */ 118 QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const;118 virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */; 119 119 /** @} */ 120 120
Note:
See TracChangeset
for help on using the changeset viewer.