Changeset 43784 in vbox
- Timestamp:
- Oct 31, 2012 1:37:54 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp
r43783 r43784 226 226 } 227 227 228 void UIGChooserItemGroup::sltHandleGeometryChange() 229 { 230 /* Which is new geometry? */ 231 QRectF newGeometry = geometry(); 232 233 /* Should we update visible name? */ 234 if (m_previousGeometry.width() != newGeometry.width()) 235 recacheVisibleName(); 236 237 /* Remember new geometry: */ 238 m_previousGeometry = newGeometry; 239 } 240 228 241 void UIGChooserItemGroup::sltNameEditingFinished() 229 242 { … … 251 264 /* Set new name / update model: */ 252 265 m_strName = strNewName; 266 recacheVisibleName(); 253 267 model()->saveGroupSettings(); 254 268 } … … 328 342 case GroupItemData_MinorSpacing: return 3; 329 343 /* Texts: */ 330 case GroupItemData_Name: 331 { 332 /* Prepare variables: */ 333 int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt(); 334 int iMajorSpacing = data(GroupItemData_MajorSpacing).toInt(); 335 int iToggleButtonWidth = data(GroupItemData_ToggleButtonSize).toSize().width(); 336 int iEnterButtonWidth = data(GroupItemData_EnterButtonSize).toSize().width(); 337 int iExitButtonWidth = data(GroupItemData_ExitButtonSize).toSize().width(); 338 int iGroupPixmapWidth = data(GroupItemData_GroupPixmapSize).toSize().width(); 339 int iMachinePixmapWidth = data(GroupItemData_MachinePixmapSize).toSize().width(); 340 int iGroupCountTextWidth = data(GroupItemData_GroupCountTextSize).toSize().width(); 341 int iMachineCountTextWidth = data(GroupItemData_MachineCountTextSize).toSize().width(); 342 int iMaximumWidth = (int)geometry().width(); 343 QString strGroupCountText = data(GroupItemData_GroupCountText).toString(); 344 QString strMachineCountText = data(GroupItemData_MachineCountText).toString(); 345 346 /* Calculate name width: */ 347 iMaximumWidth -= 2 * iHorizontalMargin; 348 if (isRoot()) 349 iMaximumWidth -= (iExitButtonWidth + iMajorSpacing); 350 else 351 { 352 iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing); 353 if (isHovered()) 354 iMaximumWidth -= (iEnterButtonWidth + iMajorSpacing); 355 } 356 if (isHovered() && !strGroupCountText.isEmpty()) 357 iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth); 358 if (isHovered() && !strMachineCountText.isEmpty()) 359 iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth); 360 return compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth); 361 } 344 case GroupItemData_Name: return m_strVisibleName; 362 345 case GroupItemData_GroupCountText: return m_groupItems.isEmpty() ? QString() : QString::number(m_groupItems.size()); 363 346 case GroupItemData_MachineCountText: return m_machineItems.isEmpty() ? QString() : QString::number(m_machineItems.size()); … … 479 462 m_machinesPixmap = QPixmap(":/machine_16px.png"); 480 463 464 /* Geometry change handler: */ 465 connect(this, SIGNAL(geometryChanged()), this, SLOT(sltHandleGeometryChange())); 466 481 467 /* Non root item only: */ 482 468 if (!isRoot()) … … 523 509 foreach (UIGChooserItem *pMachineItem, pFrom->items(UIGChooserItemType_Machine)) 524 510 new UIGChooserItemMachine(pTo, pMachineItem->toMachineItem()); 511 } 512 513 void UIGChooserItemGroup::recacheVisibleName() 514 { 515 /* Prepare variables: */ 516 int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt(); 517 int iMajorSpacing = data(GroupItemData_MajorSpacing).toInt(); 518 int iToggleButtonWidth = data(GroupItemData_ToggleButtonSize).toSize().width(); 519 int iEnterButtonWidth = data(GroupItemData_EnterButtonSize).toSize().width(); 520 int iExitButtonWidth = data(GroupItemData_ExitButtonSize).toSize().width(); 521 int iGroupPixmapWidth = data(GroupItemData_GroupPixmapSize).toSize().width(); 522 int iMachinePixmapWidth = data(GroupItemData_MachinePixmapSize).toSize().width(); 523 int iGroupCountTextWidth = data(GroupItemData_GroupCountTextSize).toSize().width(); 524 int iMachineCountTextWidth = data(GroupItemData_MachineCountTextSize).toSize().width(); 525 int iMaximumWidth = geometry().width(); 526 527 /* Calculate name width: */ 528 iMaximumWidth -= 2 * iHorizontalMargin; 529 if (isRoot()) 530 { 531 iMaximumWidth -= (iExitButtonWidth + iMajorSpacing); 532 } 533 else 534 { 535 iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing); 536 if (isHovered()) 537 iMaximumWidth -= iEnterButtonWidth; 538 } 539 if (isHovered()) 540 { 541 iMaximumWidth -= iMajorSpacing; 542 if (iGroupCountTextWidth != 0) 543 iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth); 544 if (iMachineCountTextWidth != 0) 545 iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth); 546 } 547 548 /* Recache name: */ 549 m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth); 550 update(); 525 551 } 526 552 … … 1273 1299 void UIGChooserItemGroup::hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) 1274 1300 { 1301 /* Skip if hovered: */ 1302 if (isHovered()) 1303 return; 1304 1275 1305 /* Prepare variables: */ 1276 1306 QPoint pos = pEvent->pos().toPoint(); … … 1278 1308 int iHeaderHeight = data(GroupItemData_FullHeaderSize).toSize().height(); 1279 1309 int iFullHeaderHeight = 2 * iMargin + iHeaderHeight; 1280 /* Check if group should be highlighted: */ 1281 if ((pos.y() < iFullHeaderHeight) && !isHovered()) 1282 { 1283 setHovered(true); 1284 emit sigHoverEnter(); 1285 } 1310 /* Skip if hovered part out of the header: */ 1311 if (pos.y() >= iFullHeaderHeight) 1312 return; 1313 1314 /* Call to base-class: */ 1315 UIGChooserItem::hoverMoveEvent(pEvent); 1316 1317 /* Update visible name: */ 1318 recacheVisibleName(); 1319 } 1320 1321 void UIGChooserItemGroup::hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) 1322 { 1323 /* Skip if not hovered: */ 1324 if (!isHovered()) 1325 return; 1326 1327 /* Call to base-class: */ 1328 UIGChooserItem::hoverLeaveEvent(pEvent); 1329 1330 /* Update visible name: */ 1331 recacheVisibleName(); 1286 1332 } 1287 1333 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h
r43783 r43784 83 83 84 84 private slots: 85 86 /* Handler: Geometry change stuff: */ 87 void sltHandleGeometryChange(); 85 88 86 89 /* Handler: Name editing stuff: */ … … 129 132 static void copyContent(UIGChooserItemGroup *pFrom, UIGChooserItemGroup *pTo); 130 133 134 /* Helper: Recache stuff: */ 135 void recacheVisibleName(); 136 131 137 /* Helper: Translate stuff: */ 132 138 void retranslateUi(); … … 173 179 /* Helper: Event handling stuff: */ 174 180 void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent); 181 void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent); 175 182 176 183 /* Helpers: Paint stuff: */ … … 204 211 int m_iBlackoutDarkness; 205 212 /* Cached values: */ 213 QRectF m_previousGeometry; 214 QString m_strVisibleName; 206 215 QFont m_nameFont; 207 216 QFont m_infoFont;
Note:
See TracChangeset
for help on using the changeset viewer.