Changeset 77596 in vbox for trunk/src/VBox
- Timestamp:
- Mar 7, 2019 1:24:43 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp
r77567 r77596 289 289 } 290 290 291 UIChooserItemGroup *UIChooserItem::toGroupItem() 292 { 293 UIChooserItemGroup *pItem = qgraphicsitem_cast<UIChooserItemGroup*>(this); 294 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemGroup!")); 295 return pItem; 296 } 297 298 UIChooserItemGlobal *UIChooserItem::toGlobalItem() 299 { 300 UIChooserItemGlobal *pItem = qgraphicsitem_cast<UIChooserItemGlobal*>(this); 301 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemGlobal!")); 302 return pItem; 303 } 304 305 UIChooserItemMachine *UIChooserItem::toMachineItem() 306 { 307 UIChooserItemMachine *pItem = qgraphicsitem_cast<UIChooserItemMachine*>(this); 308 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemMachine!")); 309 return pItem; 310 } 311 312 UIChooserModel *UIChooserItem::model() const 313 { 314 UIChooserModel *pModel = qobject_cast<UIChooserModel*>(QIGraphicsWidget::scene()->parent()); 315 AssertMsg(pModel, ("Incorrect graphics scene parent set!")); 316 return pModel; 317 } 318 319 UIActionPool *UIChooserItem::actionPool() const 320 { 321 return model()->actionPool(); 322 } 323 291 324 void UIChooserItem::setFavorite(bool fFavorite) 292 325 { … … 294 327 if (m_pParent) 295 328 m_pParent->toGroupItem()->updateFavorites(); 296 }297 298 UIChooserItemGroup *UIChooserItem::toGroupItem()299 {300 UIChooserItemGroup *pItem = qgraphicsitem_cast<UIChooserItemGroup*>(this);301 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemGroup!"));302 return pItem;303 }304 305 UIChooserItemGlobal *UIChooserItem::toGlobalItem()306 {307 UIChooserItemGlobal *pItem = qgraphicsitem_cast<UIChooserItemGlobal*>(this);308 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemGlobal!"));309 return pItem;310 }311 312 UIChooserItemMachine *UIChooserItem::toMachineItem()313 {314 UIChooserItemMachine *pItem = qgraphicsitem_cast<UIChooserItemMachine*>(this);315 AssertMsg(pItem, ("Trying to cast invalid item type to UIChooserItemMachine!"));316 return pItem;317 }318 319 UIChooserModel *UIChooserItem::model() const320 {321 UIChooserModel *pModel = qobject_cast<UIChooserModel*>(QIGraphicsWidget::scene()->parent());322 AssertMsg(pModel, ("Incorrect graphics scene parent set!"));323 return pModel;324 }325 326 UIActionPool *UIChooserItem::actionPool() const327 {328 return model()->actionPool();329 329 } 330 330 … … 349 349 { 350 350 m_iLevel = iLevel; 351 } 352 353 bool UIChooserItem::isHovered() const 354 { 355 return m_fHovered; 351 356 } 352 357 … … 360 365 } 361 366 362 bool UIChooserItem::isHovered() const363 {364 return m_fHovered;365 }366 367 367 void UIChooserItem::updateGeometry() 368 368 { … … 405 405 } 406 406 407 UIChooserItemDragToken UIChooserItem::dragTokenPlace() const 408 { 409 return m_enmDragTokenPlace; 410 } 411 407 412 void UIChooserItem::setDragTokenPlace(UIChooserItemDragToken enmPlace) 408 413 { … … 413 418 update(); 414 419 } 415 }416 417 UIChooserItemDragToken UIChooserItem::dragTokenPlace() const418 {419 return m_enmDragTokenPlace;420 420 } 421 421 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h
r77567 r77596 83 83 /** @name Item stuff. 84 84 * @{ */ 85 /** Returns parent 85 /** Returns parent reference. */ 86 86 UIChooserItem *parentItem() const { return m_pParent; } 87 /** Returns whether item is favorite. */88 bool isFavorite() const { return m_fFavorite; }89 90 /** Defines whether item is @a fFavorite. */91 virtual void setFavorite(bool fFavorite);92 93 /** Returns whether item is root. */94 bool isRoot() const { return !m_pParent; }95 87 96 88 /** Casts item to group one. */ … … 106 98 UIActionPool *actionPool() const; 107 99 100 /** Returns whether item is root. */ 101 bool isRoot() const { return !m_pParent; } 102 103 /** Returns item name. */ 104 virtual QString name() const = 0; 105 /** Returns item full-name. */ 106 virtual QString fullName() const = 0; 107 /** Returns item description. */ 108 virtual QString description() const = 0; 109 /** Returns item definition. */ 110 virtual QString definition() const = 0; 111 112 /** Returns whether item is favorite. */ 113 bool isFavorite() const { return m_fFavorite; } 114 /** Defines whether item is @a fFavorite. */ 115 virtual void setFavorite(bool fFavorite); 116 108 117 /** Returns a level of item. */ 109 118 int level() const; … … 111 120 void setLevel(int iLevel); 112 121 122 /** Returns whether item is hovered. */ 123 bool isHovered() const; 124 /** Defines whether item is @a fHovered. */ 125 void setHovered(bool fHovered); 126 113 127 /** Starts item editing. */ 114 128 virtual void startEditing() = 0; … … 116 130 /** Updates item tool-tip. */ 117 131 virtual void updateToolTip() = 0; 118 119 /** Returns item name. */120 virtual QString name() const = 0;121 /** Returns item description. */122 virtual QString description() const = 0;123 /** Returns item full-name. */124 virtual QString fullName() const = 0;125 /** Returns item definition. */126 virtual QString definition() const = 0;127 128 /** Defines whether item is @a fHovered. */129 void setHovered(bool fHovered);130 /** Returns whether item is hovered. */131 bool isHovered() const;132 132 133 133 /** Installs event-filter for @a pSource object. … … 138 138 /** @name Children stuff. 139 139 * @{ */ 140 /** Returns whether there are children items of certain @a enmType. */ 141 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const = 0; 142 /** Returns children items of certain @a enmType. */ 143 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const = 0; 144 145 /** Replaces children @a items of certain @a enmType. */ 146 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) = 0; 147 /** Clears children items of certain @a enmType. */ 148 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) = 0; 149 140 150 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ 141 151 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) = 0; 142 152 /** Removes child @a pItem. */ 143 153 virtual void removeItem(UIChooserItem *pItem) = 0; 144 145 /** Replaces children @a items of certain @a enmType. */146 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) = 0;147 /** Returns children items of certain @a enmType. */148 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;149 /** Returns whether there are children items of certain @a enmType. */150 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;151 /** Clears children items of certain @a enmType. */152 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) = 0;153 154 154 155 /** Updates all children items with specified @a uId. */ … … 203 204 virtual void resetDragToken() = 0; 204 205 206 /** Returns drag token place. */ 207 UIChooserItemDragToken dragTokenPlace() const; 205 208 /** Defines drag token @a enmPlace. */ 206 209 void setDragTokenPlace(UIChooserItemDragToken enmPlace); 207 /** Returns drag token place. */208 UIChooserItemDragToken dragTokenPlace() const;209 210 /** @} */ 210 211 … … 233 234 /** @name Item stuff. 234 235 * @{ */ 236 /** Returns item's default animation value. */ 237 int defaultValue() const { return m_iDefaultValue; } 235 238 /** Defines item's default animation @a iValue. */ 236 239 void setDefaultValue(int iValue) { m_iDefaultValue = iValue; update(); } 237 /** Returns item's default animation value. */ 238 int defaultValue() const { return m_iDefaultValue; }239 240 241 /** Returns item's hovered animation value. */ 242 int hoveredValue() const { return m_iHoveredValue; } 240 243 /** Defines item's hovered animation @a iValue. */ 241 244 void setHoveredValue(int iValue) { m_iHoveredValue = iValue; update(); } 242 /** Returns item's hovered animation value. */ 243 int hoveredValue() const { return m_iHoveredValue; }244 245 246 /** Returns item's animated value. */ 247 int animatedValue() const { return m_iAnimatedValue; } 245 248 /** Defines item's animated @a iValue. */ 246 249 void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); } 247 /** Returns item's animated value. */248 int animatedValue() const { return m_iAnimatedValue; }249 250 /** @} */ 250 251 251 252 /** @name Layout stuff. 252 253 * @{ */ 254 /** Returns previous geometry. */ 255 const QRectF &previousGeometry() const { return m_previousGeometry; } 253 256 /** Defines previous @a geometry. */ 254 257 void setPreviousGeometry(const QRectF &geometry) { m_previousGeometry = geometry; } 255 /** Returns previous geometry. */256 const QRectF &previousGeometry() const { return m_previousGeometry; }257 258 258 259 /** Returns @a strText size calculated on the basis of certain @a font and @a pPaintDevice. */ … … 303 304 304 305 /** Holds the item level according to root. */ 305 int 306 int m_iLevel; 306 307 307 308 /** Holds whether item is hovered. */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp
r77567 r77596 74 74 { 75 75 cleanup(); 76 }77 78 void UIChooserItemGlobal::setFavorite(bool fFavorite)79 {80 /* Call to base-class: */81 UIChooserItem::setFavorite(fFavorite);82 83 /* Update pin-pixmap: */84 updatePinPixmap();85 76 } 86 77 … … 124 115 } 125 116 117 int UIChooserItemGlobal::heightHint() const 118 { 119 return m_iHeightHint; 120 } 121 126 122 void UIChooserItemGlobal::setHeightHint(int iHint) 127 123 { … … 132 128 updateGeometry(); 133 129 model()->updateLayout(); 134 }135 136 int UIChooserItemGlobal::heightHint() const137 {138 return m_iHeightHint;139 130 } 140 131 … … 199 190 } 200 191 192 QString UIChooserItemGlobal::name() const 193 { 194 return m_strName; 195 } 196 197 QString UIChooserItemGlobal::fullName() const 198 { 199 return m_strName; 200 } 201 202 QString UIChooserItemGlobal::description() const 203 { 204 return m_strDescription; 205 } 206 207 QString UIChooserItemGlobal::definition() const 208 { 209 return QString("n=%1").arg("GLOBAL"); 210 } 211 212 void UIChooserItemGlobal::setFavorite(bool fFavorite) 213 { 214 /* Call to base-class: */ 215 UIChooserItem::setFavorite(fFavorite); 216 217 /* Update pin-pixmap: */ 218 updatePinPixmap(); 219 } 220 201 221 void UIChooserItemGlobal::startEditing() 202 222 { … … 209 229 } 210 230 211 QString UIChooserItemGlobal::name() const212 { 213 return m_strName;214 } 215 216 Q String UIChooserItemGlobal::description() const217 { 218 return m_strDescription;219 } 220 221 QString UIChooserItemGlobal::fullName() const 222 { 223 return m_strName;224 } 225 226 QString UIChooserItemGlobal::definition() const 227 { 228 return QString("n=%1").arg("GLOBAL");231 bool UIChooserItemGlobal::hasItems(UIChooserItemType) const 232 { 233 AssertMsgFailedReturn(("Global graphics item do NOT support children!"), false); 234 } 235 236 QList<UIChooserItem*> UIChooserItemGlobal::items(UIChooserItemType) const 237 { 238 AssertMsgFailedReturn(("Global graphics item do NOT support children!"), QList<UIChooserItem*>()); 239 } 240 241 void UIChooserItemGlobal::setItems(const QList<UIChooserItem*> &, UIChooserItemType) 242 { 243 AssertMsgFailed(("Global graphics item do NOT support children!")); 244 } 245 246 void UIChooserItemGlobal::clearItems(UIChooserItemType) 247 { 248 AssertMsgFailed(("Global graphics item do NOT support children!")); 229 249 } 230 250 … … 235 255 236 256 void UIChooserItemGlobal::removeItem(UIChooserItem *) 237 {238 AssertMsgFailed(("Global graphics item do NOT support children!"));239 }240 241 void UIChooserItemGlobal::setItems(const QList<UIChooserItem*> &, UIChooserItemType)242 {243 AssertMsgFailed(("Global graphics item do NOT support children!"));244 }245 246 QList<UIChooserItem*> UIChooserItemGlobal::items(UIChooserItemType) const247 {248 AssertMsgFailedReturn(("Global graphics item do NOT support children!"), QList<UIChooserItem*>());249 }250 251 bool UIChooserItemGlobal::hasItems(UIChooserItemType) const252 {253 AssertMsgFailedReturn(("Global graphics item do NOT support children!"), false);254 }255 256 void UIChooserItemGlobal::clearItems(UIChooserItemType)257 257 { 258 258 AssertMsgFailed(("Global graphics item do NOT support children!")); … … 298 298 { 299 299 // Just do nothing .. 300 }301 302 QSizeF UIChooserItemGlobal::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const303 {304 /* If Qt::MinimumSize requested: */305 if (which == Qt::MinimumSize)306 return QSizeF(minimumWidthHint(), minimumHeightHint());307 /* Else call to base-class: */308 return UIChooserItem::sizeHint(which, constraint);309 300 } 310 301 … … 363 354 /* Return result: */ 364 355 return iProposedHeight; 356 } 357 358 QSizeF UIChooserItemGlobal::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const 359 { 360 /* If Qt::MinimumSize requested: */ 361 if (which == Qt::MinimumSize) 362 return QSizeF(minimumWidthHint(), minimumHeightHint()); 363 /* Else call to base-class: */ 364 return UIChooserItem::sizeHint(which, constraint); 365 365 } 366 366 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h
r77567 r77596 32 32 class UIGraphicsZoomButton; 33 33 34 34 35 /** UIChooserItem extension implementing global item. */ 35 36 class UIChooserItemGlobal : public UIChooserItem … … 39 40 public: 40 41 41 /** RTTI item type. */42 /** RTTI required for qgraphicsitem_cast. */ 42 43 enum { Type = UIChooserItemType_Global }; 43 44 … … 51 52 /** @name Item stuff. 52 53 * @{ */ 53 /** Defines whether item is @a fFavorite. */54 virtual void setFavorite(bool fFavorite) /* override */;55 56 54 /** Returns whether passed @a position belongs to tool button area. */ 57 55 bool isToolButtonArea(const QPoint &position, int iMarginMultiplier = 1) const; … … 62 60 /** @name Layout stuff. 63 61 * @{ */ 62 /** Returns height hint. */ 63 int heightHint() const; 64 64 /** Defines height @a iHint. */ 65 65 void setHeightHint(int iHint); 66 /** Returns height hint. */67 int heightHint() const;68 66 /** @} */ 69 67 … … 93 91 virtual int type() const /* override */ { return Type; } 94 92 93 /** Returns item name. */ 94 virtual QString name() const /* override */; 95 /** Returns item full-name. */ 96 virtual QString fullName() const /* override */; 97 /** Returns item description. */ 98 virtual QString description() const /* override */; 99 /** Returns item definition. */ 100 virtual QString definition() const /* override */; 101 102 /** Defines whether item is @a fFavorite. */ 103 virtual void setFavorite(bool fFavorite) /* override */; 104 95 105 /** Starts item editing. */ 96 106 virtual void startEditing() /* override */; … … 98 108 /** Updates item tool-tip. */ 99 109 virtual void updateToolTip() /* override */; 100 101 /** Returns item name. */102 virtual QString name() const /* override */;103 /** Returns item description. */104 virtual QString description() const /* override */;105 /** Returns item full-name. */106 virtual QString fullName() const /* override */;107 /** Returns item definition. */108 virtual QString definition() const /* override */;109 110 /** @} */ 110 111 111 112 /** @name Children stuff. 112 113 * @{ */ 114 /** Returns whether there are children items of certain @a enmType. */ 115 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 116 /** Returns children items of certain @a enmType. */ 117 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 118 119 /** Replaces children @a items of certain @a enmType. */ 120 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */; 121 /** Clears children items of certain @a enmType. */ 122 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */; 123 113 124 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ 114 125 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) /* override */; 115 126 /** Removes child @a pItem. */ 116 127 virtual void removeItem(UIChooserItem *pItem) /* override */; 117 118 /** Replaces children @a items of certain @a enmType. */119 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;120 /** Returns children items of certain @a enmType. */121 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;122 /** Returns whether there are children items of certain @a enmType. */123 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;124 /** Clears children items of certain @a enmType. */125 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;126 128 127 129 /** Updates all children items with specified @a uId. */ … … 295 297 }; 296 298 299 297 300 #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGlobal_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp
r77567 r77596 221 221 } 222 222 223 bool UIChooserItemGroup::isClosed() const 224 { 225 return m_fClosed && !isRoot(); 226 } 227 223 228 void UIChooserItemGroup::close(bool fAnimated /* = true */) 224 229 { … … 227 232 } 228 233 229 bool UIChooserItemGroup::is Closed() const230 { 231 return m_fClosed && !isRoot();234 bool UIChooserItemGroup::isOpened() const 235 { 236 return !m_fClosed || isRoot(); 232 237 } 233 238 … … 236 241 AssertMsg(!isRoot(), ("Can't open root-item!")); 237 242 m_pToggleButton->setToggled(true, fAnimated); 238 }239 240 bool UIChooserItemGroup::isOpened() const241 {242 return !m_fClosed || isRoot();243 }244 245 void UIChooserItemGroup::installEventFilterHelper(QObject *pSource)246 {247 /* The only object which need's that filter for now is scroll-area: */248 pSource->installEventFilter(m_pScrollArea);249 }250 251 /* static */252 QString UIChooserItemGroup::className()253 {254 return "UIChooserItemGroup";255 }256 257 void UIChooserItemGroup::makeSureItemIsVisible(UIChooserItem *pItem)258 {259 /* Make sure item exists: */260 AssertPtrReturnVoid(pItem);261 262 /* Convert child rectangle to local coordinates for this group. This also263 * works for a child at any sub-level, doesn't necessary of this group. */264 const QPointF positionInScene = pItem->mapToScene(QPointF(0, 0));265 const QPointF positionInGroup = mapFromScene(positionInScene);266 const QRectF itemRectInGroup = QRectF(positionInGroup, pItem->size());267 m_pScrollArea->makeSureRectIsVisible(itemRectInGroup);268 243 } 269 244 … … 291 266 /* Relayout model: */ 292 267 model()->updateLayout(); 268 } 269 270 /* static */ 271 QString UIChooserItemGroup::className() 272 { 273 return "UIChooserItemGroup"; 293 274 } 294 275 … … 388 369 /* Paint header: */ 389 370 paintHeader(pPainter, rectangle); 371 } 372 373 QString UIChooserItemGroup::name() const 374 { 375 return m_strName; 376 } 377 378 QString UIChooserItemGroup::fullName() const 379 { 380 /* Return "/" for root item: */ 381 if (isRoot()) 382 return "/"; 383 384 /* Get full parent name, append with '/' if not yet appended: */ 385 AssertMsg(parentItem(), ("Incorrect parent set!")); 386 QString strFullParentName = parentItem()->fullName(); 387 if (!strFullParentName.endsWith('/')) 388 strFullParentName.append('/'); 389 /* Return full item name based on parent prefix: */ 390 return strFullParentName + name(); 391 } 392 393 QString UIChooserItemGroup::description() const 394 { 395 return m_strDescription; 396 } 397 398 QString UIChooserItemGroup::definition() const 399 { 400 return QString("g=%1").arg(name()); 390 401 } 391 402 … … 475 486 } 476 487 477 QString UIChooserItemGroup::name() const 478 { 479 return m_strName; 480 } 481 482 QString UIChooserItemGroup::description() const 483 { 484 return m_strDescription; 485 } 486 487 QString UIChooserItemGroup::fullName() const 488 { 489 /* Return "/" for root item: */ 490 if (isRoot()) 491 return "/"; 492 493 /* Get full parent name, append with '/' if not yet appended: */ 494 AssertMsg(parentItem(), ("Incorrect parent set!")); 495 QString strFullParentName = parentItem()->fullName(); 496 if (!strFullParentName.endsWith('/')) 497 strFullParentName.append('/'); 498 /* Return full item name based on parent prefix: */ 499 return strFullParentName + name(); 500 } 501 502 QString UIChooserItemGroup::definition() const 503 { 504 return QString("g=%1").arg(name()); 488 void UIChooserItemGroup::installEventFilterHelper(QObject *pSource) 489 { 490 /* The only object which need's that filter for now is scroll-area: */ 491 pSource->installEventFilter(m_pScrollArea); 492 } 493 494 bool UIChooserItemGroup::hasItems(UIChooserItemType type /* = UIChooserItemType_Any */) const 495 { 496 switch (type) 497 { 498 case UIChooserItemType_Any: 499 return hasItems(UIChooserItemType_Global) || hasItems(UIChooserItemType_Group) || hasItems(UIChooserItemType_Machine); 500 case UIChooserItemType_Global: 501 return !m_globalItems.isEmpty(); 502 case UIChooserItemType_Group: 503 return !m_groupItems.isEmpty(); 504 case UIChooserItemType_Machine: 505 return !m_machineItems.isEmpty(); 506 } 507 return false; 508 } 509 510 QList<UIChooserItem*> UIChooserItemGroup::items(UIChooserItemType type /* = UIChooserItemType_Any */) const 511 { 512 switch (type) 513 { 514 case UIChooserItemType_Any: return items(UIChooserItemType_Global) + items(UIChooserItemType_Group) + items(UIChooserItemType_Machine); 515 case UIChooserItemType_Global: return m_globalItems; 516 case UIChooserItemType_Group: return m_groupItems; 517 case UIChooserItemType_Machine: return m_machineItems; 518 default: break; 519 } 520 return QList<UIChooserItem*>(); 521 } 522 523 void UIChooserItemGroup::setItems(const QList<UIChooserItem*> &items, UIChooserItemType type) 524 { 525 /* Check item type: */ 526 switch (type) 527 { 528 case UIChooserItemType_Global: m_globalItems = items; break; 529 case UIChooserItemType_Group: m_groupItems = items; break; 530 case UIChooserItemType_Machine: m_machineItems = items; break; 531 default: AssertMsgFailed(("Invalid item type!")); break; 532 } 533 534 /* Update linked values: */ 535 updateLayoutSpacings(); 536 updateItemCountInfo(); 537 updateToolTip(); 538 updateGeometry(); 539 } 540 541 void UIChooserItemGroup::clearItems(UIChooserItemType type /* = UIChooserItemType_Any */) 542 { 543 switch (type) 544 { 545 case UIChooserItemType_Any: 546 { 547 clearItems(UIChooserItemType_Global); 548 clearItems(UIChooserItemType_Group); 549 clearItems(UIChooserItemType_Machine); 550 break; 551 } 552 case UIChooserItemType_Global: 553 { 554 while (!m_globalItems.isEmpty()) { delete m_globalItems.last(); } 555 AssertMsg(m_globalItems.isEmpty(), ("Global items cleanup failed!")); 556 break; 557 } 558 case UIChooserItemType_Group: 559 { 560 while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); } 561 AssertMsg(m_groupItems.isEmpty(), ("Group items cleanup failed!")); 562 break; 563 } 564 case UIChooserItemType_Machine: 565 { 566 while (!m_machineItems.isEmpty()) { delete m_machineItems.last(); } 567 AssertMsg(m_machineItems.isEmpty(), ("Machine items cleanup failed!")); 568 break; 569 } 570 } 571 572 /* Update linked values: */ 573 updateLayoutSpacings(); 574 updateItemCountInfo(); 575 updateToolTip(); 576 updateGeometry(); 505 577 } 506 578 … … 612 684 } 613 685 614 void UIChooserItemGroup::setItems(const QList<UIChooserItem*> &items, UIChooserItemType type)615 {616 /* Check item type: */617 switch (type)618 {619 case UIChooserItemType_Global: m_globalItems = items; break;620 case UIChooserItemType_Group: m_groupItems = items; break;621 case UIChooserItemType_Machine: m_machineItems = items; break;622 default: AssertMsgFailed(("Invalid item type!")); break;623 }624 625 /* Update linked values: */626 updateLayoutSpacings();627 updateItemCountInfo();628 updateToolTip();629 updateGeometry();630 }631 632 QList<UIChooserItem*> UIChooserItemGroup::items(UIChooserItemType type /* = UIChooserItemType_Any */) const633 {634 switch (type)635 {636 case UIChooserItemType_Any: return items(UIChooserItemType_Global) + items(UIChooserItemType_Group) + items(UIChooserItemType_Machine);637 case UIChooserItemType_Global: return m_globalItems;638 case UIChooserItemType_Group: return m_groupItems;639 case UIChooserItemType_Machine: return m_machineItems;640 default: break;641 }642 return QList<UIChooserItem*>();643 }644 645 bool UIChooserItemGroup::hasItems(UIChooserItemType type /* = UIChooserItemType_Any */) const646 {647 switch (type)648 {649 case UIChooserItemType_Any:650 return hasItems(UIChooserItemType_Global) || hasItems(UIChooserItemType_Group) || hasItems(UIChooserItemType_Machine);651 case UIChooserItemType_Global:652 return !m_globalItems.isEmpty();653 case UIChooserItemType_Group:654 return !m_groupItems.isEmpty();655 case UIChooserItemType_Machine:656 return !m_machineItems.isEmpty();657 }658 return false;659 }660 661 void UIChooserItemGroup::clearItems(UIChooserItemType type /* = UIChooserItemType_Any */)662 {663 switch (type)664 {665 case UIChooserItemType_Any:666 {667 clearItems(UIChooserItemType_Global);668 clearItems(UIChooserItemType_Group);669 clearItems(UIChooserItemType_Machine);670 break;671 }672 case UIChooserItemType_Global:673 {674 while (!m_globalItems.isEmpty()) { delete m_globalItems.last(); }675 AssertMsg(m_globalItems.isEmpty(), ("Global items cleanup failed!"));676 break;677 }678 case UIChooserItemType_Group:679 {680 while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); }681 AssertMsg(m_groupItems.isEmpty(), ("Group items cleanup failed!"));682 break;683 }684 case UIChooserItemType_Machine:685 {686 while (!m_machineItems.isEmpty()) { delete m_machineItems.last(); }687 AssertMsg(m_machineItems.isEmpty(), ("Machine items cleanup failed!"));688 break;689 }690 }691 692 /* Update linked values: */693 updateLayoutSpacings();694 updateItemCountInfo();695 updateToolTip();696 updateGeometry();697 }698 699 686 void UIChooserItemGroup::updateAllItems(const QUuid &uId) 700 687 { … … 928 915 /* Else call to base-class: */ 929 916 return UIChooserItem::sizeHint(enmWhich, constraint); 917 } 918 919 void UIChooserItemGroup::makeSureItemIsVisible(UIChooserItem *pItem) 920 { 921 /* Make sure item exists: */ 922 AssertPtrReturnVoid(pItem); 923 924 /* Convert child rectangle to local coordinates for this group. This also 925 * works for a child at any sub-level, doesn't necessary of this group. */ 926 const QPointF positionInScene = pItem->mapToScene(QPointF(0, 0)); 927 const QPointF positionInGroup = mapFromScene(positionInScene); 928 const QRectF itemRectInGroup = QRectF(positionInGroup, pItem->size()); 929 m_pScrollArea->makeSureRectIsVisible(itemRectInGroup); 930 930 } 931 931 … … 1350 1350 } 1351 1351 1352 QVariant UIChooserItemGroup::data(int iKey) const 1353 { 1354 /* Provide other members with required data: */ 1355 switch (iKey) 1356 { 1357 /* Layout hints: */ 1358 case GroupItemData_HorizonalMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 1359 case GroupItemData_VerticalMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 1360 case GroupItemData_HeaderSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 1361 case GroupItemData_ChildrenSpacing: return 1; 1362 case GroupItemData_ParentIndent: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 3; 1363 1364 /* Default: */ 1365 default: break; 1366 } 1367 return QVariant(); 1368 } 1369 1370 int UIChooserItemGroup::additionalHeight() const 1371 { 1372 return m_iAdditionalHeight; 1373 } 1374 1375 void UIChooserItemGroup::setAdditionalHeight(int iAdditionalHeight) 1376 { 1377 m_iAdditionalHeight = iAdditionalHeight; 1378 updateGeometry(); 1379 model()->updateLayout(); 1380 } 1381 1382 void UIChooserItemGroup::updateAnimationParameters() 1383 { 1384 /* Only for item with button: */ 1385 if (!m_pToggleButton) 1386 return; 1387 1388 /* Recalculate animation parameters: */ 1389 QSizeF openedSize = minimumSizeHintForGroup(true); 1390 QSizeF closedSize = minimumSizeHintForGroup(false); 1391 int iAdditionalHeight = (int)(openedSize.height() - closedSize.height()); 1392 m_pToggleButton->setAnimationRange(0, iAdditionalHeight); 1393 } 1394 1395 void UIChooserItemGroup::updateToggleButtonToolTip() 1396 { 1397 /* Only for item with button: */ 1398 if (!m_pToggleButton) 1399 return; 1400 1401 /* Update toggle-button tool-tip: */ 1402 m_pToggleButton->setToolTip(isOpened() ? tr("Collapse group") : tr("Expand group")); 1403 } 1404 1352 1405 /* static */ 1353 1406 void UIChooserItemGroup::copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo) … … 1362 1415 foreach (UIChooserItem *pMachineItem, pFrom->items(UIChooserItemType_Machine)) 1363 1416 new UIChooserItemMachine(pTo, pMachineItem->toMachineItem()); 1364 }1365 1366 QVariant UIChooserItemGroup::data(int iKey) const1367 {1368 /* Provide other members with required data: */1369 switch (iKey)1370 {1371 /* Layout hints: */1372 case GroupItemData_HorizonalMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4;1373 case GroupItemData_VerticalMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;1374 case GroupItemData_HeaderSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2;1375 case GroupItemData_ChildrenSpacing: return 1;1376 case GroupItemData_ParentIndent: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 3;1377 1378 /* Default: */1379 default: break;1380 }1381 return QVariant();1382 }1383 1384 void UIChooserItemGroup::setAdditionalHeight(int iAdditionalHeight)1385 {1386 m_iAdditionalHeight = iAdditionalHeight;1387 updateGeometry();1388 model()->updateLayout();1389 }1390 1391 int UIChooserItemGroup::additionalHeight() const1392 {1393 return m_iAdditionalHeight;1394 }1395 1396 void UIChooserItemGroup::updateAnimationParameters()1397 {1398 /* Only for item with button: */1399 if (!m_pToggleButton)1400 return;1401 1402 /* Recalculate animation parameters: */1403 QSizeF openedSize = minimumSizeHintForGroup(true);1404 QSizeF closedSize = minimumSizeHintForGroup(false);1405 int iAdditionalHeight = (int)(openedSize.height() - closedSize.height());1406 m_pToggleButton->setAnimationRange(0, iAdditionalHeight);1407 }1408 1409 void UIChooserItemGroup::updateToggleButtonToolTip()1410 {1411 /* Only for item with button: */1412 if (!m_pToggleButton)1413 return;1414 1415 /* Update toggle-button tool-tip: */1416 m_pToggleButton->setToolTip(isOpened() ? tr("Collapse group") : tr("Expand group"));1417 1417 } 1418 1418 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h
r77567 r77596 62 62 public: 63 63 64 /** RTTI item type. */64 /** RTTI required for qgraphicsitem_cast. */ 65 65 enum { Type = UIChooserItemType_Group }; 66 66 … … 79 79 void setName(const QString &strName); 80 80 81 /** Returns whether group is closed. */ 82 bool isClosed() const; 81 83 /** Closes group in @a fAnimated way if requested. */ 82 84 void close(bool fAnimated = true); 83 /** Returns whether group is closed. */ 84 bool isClosed() const;85 85 86 /** Returns whether group is opened. */ 87 bool isOpened() const; 86 88 /** Opens group in @a fAnimated way if requested. */ 87 89 void open(bool fAnimated = true); 88 /** Returns whether group is opened. */ 89 bool isOpened() const; 90 91 /** Installs event-filter for @a pSource object. */ 92 virtual void installEventFilterHelper(QObject *pSource) /* override */; 90 /** @} */ 91 92 /** @name Children stuff. 93 * @{ */ 94 /** Updates positions of favorite items. */ 95 void updateFavorites(); 93 96 /** @} */ 94 97 … … 97 100 /** Class-name used for drag&drop mime-data format. */ 98 101 static QString className(); 99 100 /** Makes sure passed child @a pItem is visible. */101 virtual void makeSureItemIsVisible(UIChooserItem *pItem) /* override */;102 /** @} */103 104 /** @name Children stuff.105 * @{ */106 /** Updates positions of favorite items. */107 void updateFavorites();108 102 /** @} */ 109 103 … … 135 129 virtual int type() const /* override */ { return Type; } 136 130 131 /** Returns item name. */ 132 virtual QString name() const /* override */; 133 /** Returns item full-name. */ 134 virtual QString fullName() const /* override */; 135 /** Returns item description. */ 136 virtual QString description() const /* override */; 137 /** Returns item definition. */ 138 virtual QString definition() const /* override */; 139 137 140 /** Starts item editing. */ 138 141 virtual void startEditing() /* override */; … … 141 144 virtual void updateToolTip() /* override */; 142 145 143 /** Returns item name. */ 144 virtual QString name() const /* override */; 145 /** Returns item description. */ 146 virtual QString description() const /* override */; 147 /** Returns item full-name. */ 148 virtual QString fullName() const /* override */; 149 /** Returns item definition. */ 150 virtual QString definition() const /* override */; 146 /** Installs event-filter for @a pSource object. */ 147 virtual void installEventFilterHelper(QObject *pSource) /* override */; 151 148 /** @} */ 152 149 153 150 /** @name Children stuff. 154 151 * @{ */ 152 /** Returns whether there are children items of certain @a enmType. */ 153 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 154 /** Returns children items of certain @a enmType. */ 155 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 156 157 /** Replaces children @a items of certain @a enmType. */ 158 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */; 159 /** Clears children items of certain @a enmType. */ 160 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */; 161 155 162 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ 156 163 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) /* override */; … … 158 165 virtual void removeItem(UIChooserItem *pItem) /* override */; 159 166 160 /** Replaces children @a items of certain @a enmType. */161 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;162 /** Returns children items of certain @a enmType. */163 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;164 /** Returns whether there are children items of certain @a enmType. */165 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;166 /** Clears children items of certain @a enmType. */167 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;168 169 167 /** Updates all children items with specified @a uId. */ 170 168 virtual void updateAllItems(const QUuid &uId) /* override */; … … 203 201 /** @name Navigation stuff. 204 202 * @{ */ 203 /** Makes sure passed child @a pItem is visible. */ 204 virtual void makeSureItemIsVisible(UIChooserItem *pItem) /* override */; 205 205 206 /** Returns pixmap item representation. */ 206 207 virtual QPixmap toPixmap() /* override */; … … 260 261 /** Prepares all. */ 261 262 void prepare(); 262 263 /** Copies group contents @a pFrom one item @a pTo another. */264 static void copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo);265 263 /** @} */ 266 264 … … 273 271 int headerDarkness() const { return m_iHeaderDarkness; } 274 272 273 /** Returns additional height. */ 274 int additionalHeight() const; 275 275 /** Defines @a iAdditionalHeight. */ 276 276 void setAdditionalHeight(int iAdditionalHeight); 277 /** Returns additional height. */278 int additionalHeight() const;279 277 280 278 /** Updates animation parameters. */ … … 286 284 /** @name Children stuff. 287 285 * @{ */ 286 /** Copies group contents @a pFrom one item @a pTo another. */ 287 static void copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo); 288 288 289 /** Returns whether group contains machine with @a uId. */ 289 290 bool isContainsMachine(const QUuid &uId) const; … … 326 327 /** @name Item stuff. 327 328 * @{ */ 329 /** Holds the cached name. */ 330 QString m_strName; 331 /** Holds the cached description. */ 332 QString m_strDescription; 333 /** Holds the cached visible name. */ 334 QString m_strVisibleName; 335 /** Holds the cached group children info. */ 336 QString m_strInfoGroups; 337 /** Holds the cached machine children info. */ 338 QString m_strInfoMachines; 339 328 340 /** Holds whether group is closed. */ 329 341 bool m_fClosed; … … 334 346 int m_iHeaderDarkness; 335 347 336 /** Holds the cached name. */ 337 QString m_strName; 338 /** Holds the cached description. */ 339 QString m_strDescription; 340 /** Holds the cached visible name. */ 341 QString m_strVisibleName; 348 /** Holds group children pixmap. */ 349 QPixmap m_groupsPixmap; 350 /** Holds machine children pixmap. */ 351 QPixmap m_machinesPixmap; 342 352 343 353 /** Holds the name font. */ 344 354 QFont m_nameFont; 355 /** Holds the info font. */ 356 QFont m_infoFont; 345 357 346 358 /** Holds the group toggle button instance. */ … … 382 394 /** Holds the machine children list. */ 383 395 QList<UIChooserItem*> m_machineItems; 384 385 /** Holds group children pixmap. */386 QPixmap m_groupsPixmap;387 /** Holds machine children pixmap. */388 QPixmap m_machinesPixmap;389 390 /** Holds the cached group children info. */391 QString m_strInfoGroups;392 /** Holds the cached machine children info. */393 QString m_strInfoMachines;394 395 /** Holds the children info font. */396 QFont m_infoFont;397 396 /** @} */ 398 397 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp
r77567 r77596 87 87 { 88 88 cleanup(); 89 }90 91 QString UIChooserItemMachine::name() const92 {93 return UIVirtualMachineItem::name();94 89 } 95 90 … … 224 219 } 225 220 226 void UIChooserItemMachine::startEditing() 227 { 228 AssertMsgFailed(("Machine graphics item do NOT support editing yet!")); 229 } 230 231 void UIChooserItemMachine::updateToolTip() 232 { 233 setToolTip(toolTipText()); 234 } 235 236 QString UIChooserItemMachine::description() const 237 { 238 return m_strDescription; 221 QString UIChooserItemMachine::name() const 222 { 223 return UIVirtualMachineItem::name(); 239 224 } 240 225 … … 250 235 } 251 236 237 QString UIChooserItemMachine::description() const 238 { 239 return m_strDescription; 240 } 241 252 242 QString UIChooserItemMachine::definition() const 253 243 { … … 255 245 } 256 246 257 void UIChooserItemMachine::addItem(UIChooserItem*, bool, int) 247 void UIChooserItemMachine::startEditing() 248 { 249 AssertMsgFailed(("Machine graphics item do NOT support editing yet!")); 250 } 251 252 void UIChooserItemMachine::updateToolTip() 253 { 254 setToolTip(toolTipText()); 255 } 256 257 bool UIChooserItemMachine::hasItems(UIChooserItemType) const 258 258 { 259 259 AssertMsgFailed(("Machine graphics item do NOT support children!")); 260 } 261 262 void UIChooserItemMachine::removeItem(UIChooserItem*) 263 { 264 AssertMsgFailed(("Machine graphics item do NOT support children!")); 265 } 266 267 void UIChooserItemMachine::setItems(const QList<UIChooserItem*>&, UIChooserItemType) 268 { 269 AssertMsgFailed(("Machine graphics item do NOT support children!")); 260 return false; 270 261 } 271 262 … … 276 267 } 277 268 278 bool UIChooserItemMachine::hasItems(UIChooserItemType) const 269 void UIChooserItemMachine::setItems(const QList<UIChooserItem*>&, UIChooserItemType) 279 270 { 280 271 AssertMsgFailed(("Machine graphics item do NOT support children!")); 281 return false;282 272 } 283 273 284 274 void UIChooserItemMachine::clearItems(UIChooserItemType) 275 { 276 AssertMsgFailed(("Machine graphics item do NOT support children!")); 277 } 278 279 void UIChooserItemMachine::addItem(UIChooserItem*, bool, int) 280 { 281 AssertMsgFailed(("Machine graphics item do NOT support children!")); 282 } 283 284 void UIChooserItemMachine::removeItem(UIChooserItem*) 285 285 { 286 286 AssertMsgFailed(("Machine graphics item do NOT support children!")); -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h
r77593 r77596 39 39 public: 40 40 41 /** RTTI item type. */41 /** RTTI required for qgraphicsitem_cast. */ 42 42 enum { Type = UIChooserItemType_Machine }; 43 43 … … 51 51 /** @name Item stuff. 52 52 * @{ */ 53 /** Returns item name. */54 virtual QString name() const /* override */;55 56 53 /** Returns whether VM is locked. */ 57 54 bool isLockedMachine() const; … … 97 94 virtual int type() const /* override */ { return Type; } 98 95 96 /** Returns item name. */ 97 virtual QString name() const /* override */; 98 /** Returns item full-name. */ 99 virtual QString fullName() const /* override */; 100 /** Returns item description. */ 101 virtual QString description() const /* override */; 102 /** Returns item definition. */ 103 virtual QString definition() const /* override */; 104 99 105 /** Starts item editing. */ 100 106 virtual void startEditing() /* override */; … … 103 109 virtual void updateToolTip() /* override */; 104 110 105 /** Returns item description. */106 virtual QString description() const /* override */;107 /** Returns item full-name. */108 virtual QString fullName() const /* override */;109 /** Returns item definition. */110 virtual QString definition() const /* override */;111 111 /** @} */ 112 112 113 113 /** @name Children stuff. 114 114 * @{ */ 115 /** Returns whether there are children items of certain @a enmType. */ 116 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 117 /** Returns children items of certain @a enmType. */ 118 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */; 119 120 /** Replaces children @a items of certain @a enmType. */ 121 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */; 122 /** Clears children items of certain @a enmType. */ 123 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */; 124 115 125 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ 116 126 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) /* override */; 117 127 /** Removes child @a pItem. */ 118 128 virtual void removeItem(UIChooserItem *pItem) /* override */; 119 120 /** Replaces children @a items of certain @a enmType. */121 virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;122 /** Returns children items of certain @a enmType. */123 virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;124 /** Returns whether there are children items of certain @a enmType. */125 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;126 /** Clears children items of certain @a enmType. */127 virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;128 129 129 130 /** Updates all children items with specified @a uId. */ … … 346 347 }; 347 348 349 348 350 #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemMachine_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77430 r77596 1017 1017 { 1018 1018 /* Machine name: */ 1019 QString strMachineName = pItem->name();1019 QString strMachineName = ((UIChooserItem*)pItem)->name(); 1020 1020 /* We should reload this machine: */ 1021 1021 sltReloadMachine(pItem->id());
Note:
See TracChangeset
for help on using the changeset viewer.