Changeset 73962 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 29, 2018 4:31:50 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp
r73927 r73962 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 … … 30 30 # include "UIChooserItemMachine.h" 31 31 # include "UIChooserModel.h" 32 # include "UIGraphicsToolBar.h"33 32 # include "UIActionPoolSelector.h" 34 # include "UIGraphicsZoomButton.h"35 33 # include "UIIconPool.h" 36 34 # include "UIImageTools.h" … … 43 41 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 44 42 45 46 /* static */47 QString UIChooserItemMachine::className() { return "UIChooserItemMachine"; }48 43 49 44 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent, … … 52 47 : UIChooserItem(pParent, pParent->isTemporary()) 53 48 , UIVirtualMachineItem(machine) 49 , m_iHoverLightness(0) 50 , m_iHighlightLightness(0) 51 , m_iHoverHighlightLightness(0) 52 , m_iFirstRowMaximumWidth(0) 53 , m_iMinimumNameWidth(0) 54 , m_iMaximumNameWidth(0) 55 , m_iMinimumSnapshotNameWidth(0) 56 , m_iMaximumSnapshotNameWidth(0) 54 57 { 55 58 /* Prepare: */ … … 79 82 : UIChooserItem(pParent, pParent->isTemporary()) 80 83 , UIVirtualMachineItem(pCopyFrom->machine()) 84 , m_iHoverLightness(0) 85 , m_iHighlightLightness(0) 86 , m_iHoverHighlightLightness(0) 87 , m_iFirstRowMaximumWidth(0) 88 , m_iMinimumNameWidth(0) 89 , m_iMaximumNameWidth(0) 90 , m_iMinimumSnapshotNameWidth(0) 91 , m_iMaximumSnapshotNameWidth(0) 81 92 { 82 93 /* Prepare: */ … … 130 141 { 131 142 return UIVirtualMachineItem::name(); 132 }133 134 QString UIChooserItemMachine::description() const135 {136 return m_strDescription;137 }138 139 QString UIChooserItemMachine::fullName() const140 {141 /* Get full parent name, append with '/' if not yet appended: */142 AssertMsg(parentItem(), ("Incorrect parent set!"));143 QString strFullParentName = parentItem()->fullName();144 if (!strFullParentName.endsWith('/'))145 strFullParentName.append('/');146 /* Return full item name based on parent prefix: */147 return strFullParentName + name();148 }149 150 QString UIChooserItemMachine::definition() const151 {152 return QString("m=%1").arg(name());153 143 } 154 144 … … 163 153 164 154 /* static */ 155 QString UIChooserItemMachine::className() 156 { 157 return "UIChooserItemMachine"; 158 } 159 160 /* static */ 165 161 void UIChooserItemMachine::enumerateMachineItems(const QList<UIChooserItem*> &il, 166 167 162 QList<UIChooserItemMachine*> &ol, 163 int iEnumerationFlags /* = 0 */) 168 164 { 169 165 /* Enumerate all the passed items: */ … … 180 176 /* Skip if item with same ID is already enumerated but we need unique: */ 181 177 if ((iEnumerationFlags & UIChooserItemMachineEnumerationFlag_Unique) && 182 c ontains(ol, pMachineItem))178 checkIfContains(ol, pMachineItem)) 183 179 continue; 184 180 /* Skip if this item is accessible and we no need it: */ … … 200 196 } 201 197 202 void UIChooserItemMachine::sltHandleWindowRemapped() 203 { 198 void UIChooserItemMachine::retranslateUi() 199 { 200 /* Update description: */ 201 m_strDescription = tr("Virtual Machine"); 202 203 /* Update state text: */ 204 updateStateText(); 205 206 /* Update machine tool-tip: */ 207 updateToolTip(); 208 } 209 210 void UIChooserItemMachine::showEvent(QShowEvent *pEvent) 211 { 212 /* Call to base-class: */ 213 UIChooserItem::showEvent(pEvent); 214 204 215 /* Recache and update pixmaps: */ 205 216 recachePixmap(); … … 207 218 } 208 219 209 QVariant UIChooserItemMachine::data(int iKey) const 210 { 211 /* Provide other members with required data: */ 212 switch (iKey) 213 { 214 /* Layout hints: */ 215 case MachineItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 216 case MachineItemData_MajorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 217 case MachineItemData_MinorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 218 case MachineItemData_TextSpacing: return 0; 219 220 /* Pixmaps: */ 221 case MachineItemData_SettingsButtonPixmap: return UIIconPool::iconSet(":/vm_settings_16px.png"); 222 case MachineItemData_StartButtonPixmap: return UIIconPool::iconSet(":/vm_start_16px.png"); 223 case MachineItemData_PauseButtonPixmap: return UIIconPool::iconSet(":/vm_pause_16px.png"); 224 case MachineItemData_CloseButtonPixmap: return UIIconPool::iconSet(":/exit_16px.png"); 225 226 /* Sizes: */ 227 case MachineItemData_ToolBarSize: return m_pToolBar ? m_pToolBar->minimumSizeHint().toSize() : QSize(0, 0); 228 229 /* Default: */ 230 default: break; 231 } 232 return QVariant(); 233 } 234 235 void UIChooserItemMachine::updatePixmaps() 236 { 237 /* Update pixmap: */ 238 updatePixmap(); 239 240 /* Update state-pixmap: */ 241 updateStatePixmap(); 242 } 243 244 void UIChooserItemMachine::updatePixmap() 245 { 246 /* Get new pixmap and pixmap-size: */ 247 QSize pixmapSize; 248 QPixmap pixmap = osPixmap(&pixmapSize); 249 /* Update linked values: */ 250 if (m_pixmapSize != pixmapSize) 251 { 252 m_pixmapSize = pixmapSize; 220 void UIChooserItemMachine::resizeEvent(QGraphicsSceneResizeEvent *pEvent) 221 { 222 /* Call to base-class: */ 223 UIChooserItem::resizeEvent(pEvent); 224 225 /* What is the new geometry? */ 226 QRectF newGeometry = geometry(); 227 228 /* Should we update visible name? */ 229 if (previousGeometry().width() != newGeometry.width()) 253 230 updateFirstRowMaximumWidth(); 254 updateGeometry(); 255 } 256 if (m_pixmap.toImage() != pixmap.toImage()) 257 { 258 m_pixmap = pixmap; 259 update(); 260 } 261 } 262 263 void UIChooserItemMachine::updateStatePixmap() 264 { 265 /* Determine the icon metric: */ 266 const QStyle *pStyle = QApplication::style(); 267 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 268 /* Get new state-pixmap and state-pixmap size: */ 269 const QIcon stateIcon = machineStateIcon(); 270 AssertReturnVoid(!stateIcon.isNull()); 271 const QSize statePixmapSize = QSize(iIconMetric, iIconMetric); 272 const QPixmap statePixmap = stateIcon.pixmap(gpManager->windowHandle(), statePixmapSize); 273 /* Update linked values: */ 274 if (m_statePixmapSize != statePixmapSize) 275 { 276 m_statePixmapSize = statePixmapSize; 277 updateGeometry(); 278 } 279 if (m_statePixmap.toImage() != statePixmap.toImage()) 280 { 281 m_statePixmap = statePixmap; 282 update(); 283 } 284 } 285 286 void UIChooserItemMachine::updateName() 287 { 288 /* Get new name: */ 289 QString strName = name(); 290 291 /* Is there something changed? */ 292 if (m_strName == strName) 293 return; 294 295 /* Update linked values: */ 296 m_strName = strName; 297 updateMinimumNameWidth(); 298 updateVisibleName(); 299 } 300 301 void UIChooserItemMachine::updateSnapshotName() 302 { 303 /* Get new snapshot-name: */ 304 QString strSnapshotName = snapshotName(); 305 306 /* Is there something changed? */ 307 if (m_strSnapshotName == strSnapshotName) 308 return; 309 310 /* Update linked values: */ 311 m_strSnapshotName = strSnapshotName; 312 updateMinimumSnapshotNameWidth(); 313 updateVisibleSnapshotName(); 314 } 315 316 void UIChooserItemMachine::updateFirstRowMaximumWidth() 317 { 318 /* Prepare variables: */ 319 int iMargin = data(MachineItemData_Margin).toInt(); 320 int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt(); 321 int iToolBarWidth = data(MachineItemData_ToolBarSize).toSize().width(); 322 323 /* Calculate new maximum width for the first row: */ 324 int iFirstRowMaximumWidth = (int)geometry().width(); 325 iFirstRowMaximumWidth -= iMargin; /* left margin */ 326 iFirstRowMaximumWidth -= m_pixmapSize.width(); /* pixmap width */ 327 iFirstRowMaximumWidth -= iMajorSpacing; /* spacing between pixmap and name(s) */ 328 if (m_pToolBar) 329 { 330 iFirstRowMaximumWidth -= iMajorSpacing; /* spacing before toolbar */ 331 iFirstRowMaximumWidth -= iToolBarWidth; /* toolbar width */ 332 } 333 iFirstRowMaximumWidth -= iMargin; /* right margin */ 334 335 /* Is there something changed? */ 336 if (m_iFirstRowMaximumWidth == iFirstRowMaximumWidth) 337 return; 338 339 /* Update linked values: */ 340 m_iFirstRowMaximumWidth = iFirstRowMaximumWidth; 341 updateMaximumNameWidth(); 342 updateMaximumSnapshotNameWidth(); 343 } 344 345 void UIChooserItemMachine::updateMinimumNameWidth() 346 { 347 /* Calculate new minimum name width: */ 348 QPaintDevice *pPaintDevice = model()->paintDevice(); 349 QFontMetrics fm(m_nameFont, pPaintDevice); 350 int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15))); 351 352 /* Is there something changed? */ 353 if (m_iMinimumNameWidth == iMinimumNameWidth) 354 return; 355 356 /* Update linked values: */ 357 m_iMinimumNameWidth = iMinimumNameWidth; 358 updateGeometry(); 359 } 360 361 void UIChooserItemMachine::updateMinimumSnapshotNameWidth() 362 { 363 /* Calculate new minimum snapshot-name width: */ 364 int iMinimumSnapshotNameWidth = 0; 365 /* Is there any snapshot exists? */ 366 if (!m_strSnapshotName.isEmpty()) 367 { 368 QFontMetrics fm(m_snapshotNameFont, model()->paintDevice()); 369 int iBracketWidth = fm.width("()"); /* bracket width */ 370 int iActualTextWidth = fm.width(m_strSnapshotName); /* snapshot-name width */ 371 int iMinimumTextWidth = fm.width("..."); /* ellipsis width */ 372 iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth); 373 } 374 375 /* Is there something changed? */ 376 if (m_iMinimumSnapshotNameWidth == iMinimumSnapshotNameWidth) 377 return; 378 379 /* Update linked values: */ 380 m_iMinimumSnapshotNameWidth = iMinimumSnapshotNameWidth; 381 updateMaximumNameWidth(); 382 updateGeometry(); 383 } 384 385 void UIChooserItemMachine::updateMaximumNameWidth() 386 { 387 /* Calculate new maximum name width: */ 388 int iMaximumNameWidth = m_iFirstRowMaximumWidth; 389 /* Do we have a minimum snapshot-name width? */ 390 if (m_iMinimumSnapshotNameWidth != 0) 391 { 392 /* Prepare variables: */ 393 int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt(); 394 /* Take spacing and snapshot-name into account: */ 395 iMaximumNameWidth -= (iMinorSpacing + m_iMinimumSnapshotNameWidth); 396 } 397 398 /* Is there something changed? */ 399 if (m_iMaximumNameWidth == iMaximumNameWidth) 400 return; 401 402 /* Update linked values: */ 403 m_iMaximumNameWidth = iMaximumNameWidth; 404 updateVisibleName(); 405 } 406 407 void UIChooserItemMachine::updateMaximumSnapshotNameWidth() 408 { 409 /* Prepare variables: */ 410 int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt(); 411 412 /* Calculate new maximum snapshot-name width: */ 413 int iMaximumSnapshotNameWidth = m_iFirstRowMaximumWidth; 414 iMaximumSnapshotNameWidth -= (iMinorSpacing + m_visibleNameSize.width()); 415 416 /* Is there something changed? */ 417 if (m_iMaximumSnapshotNameWidth == iMaximumSnapshotNameWidth) 418 return; 419 420 /* Update linked values: */ 421 m_iMaximumSnapshotNameWidth = iMaximumSnapshotNameWidth; 422 updateVisibleSnapshotName(); 423 } 424 425 void UIChooserItemMachine::updateVisibleName() 426 { 427 /* Prepare variables: */ 428 QPaintDevice *pPaintDevice = model()->paintDevice(); 429 430 /* Calculate new visible name and name-size: */ 431 QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth); 432 QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName); 433 434 /* Update linked values: */ 435 if (m_visibleNameSize != visibleNameSize) 436 { 437 m_visibleNameSize = visibleNameSize; 438 updateMaximumSnapshotNameWidth(); 439 updateGeometry(); 440 } 441 if (m_strVisibleName != strVisibleName) 442 { 443 m_strVisibleName = strVisibleName; 444 update(); 445 } 446 } 447 448 void UIChooserItemMachine::updateVisibleSnapshotName() 449 { 450 /* Prepare variables: */ 451 QPaintDevice *pPaintDevice = model()->paintDevice(); 452 453 /* Calculate new visible snapshot-name: */ 454 int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()"); 455 QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, m_strSnapshotName, 456 m_iMaximumSnapshotNameWidth - iBracketWidth); 457 strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName); 458 QSize visibleSnapshotNameSize = textSize(m_snapshotNameFont, pPaintDevice, strVisibleSnapshotName); 459 460 /* Update linked values: */ 461 if (m_visibleSnapshotNameSize != visibleSnapshotNameSize) 462 { 463 m_visibleSnapshotNameSize = visibleSnapshotNameSize; 464 updateGeometry(); 465 } 466 if (m_strVisibleSnapshotName != strVisibleSnapshotName) 467 { 468 m_strVisibleSnapshotName = strVisibleSnapshotName; 469 update(); 470 } 471 } 472 473 void UIChooserItemMachine::updateStateText() 474 { 475 /* Get new state-text and state-text size: */ 476 QString strStateText = machineStateName(); 477 QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), m_strStateText); 478 479 /* Update linked values: */ 480 if (m_stateTextSize != stateTextSize) 481 { 482 m_stateTextSize = stateTextSize; 483 updateGeometry(); 484 } 485 if (m_strStateText != strStateText) 486 { 487 m_strStateText = strStateText; 488 update(); 489 } 490 } 491 492 void UIChooserItemMachine::retranslateUi() 493 { 494 /* Update description: */ 495 m_strDescription = tr("Virtual Machine"); 496 497 /* Update state text: */ 498 updateStateText(); 499 500 /* Update machine tool-tip: */ 501 updateToolTip(); 231 232 /* Remember the new geometry: */ 233 setPreviousGeometry(newGeometry); 234 } 235 236 void UIChooserItemMachine::mousePressEvent(QGraphicsSceneMouseEvent *pEvent) 237 { 238 /* Call to base-class: */ 239 UIChooserItem::mousePressEvent(pEvent); 240 /* No drag for inaccessible: */ 241 if (!accessible()) 242 pEvent->ignore(); 243 } 244 245 void UIChooserItemMachine::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget* /* pWidget = 0 */) 246 { 247 /* Setup: */ 248 pPainter->setRenderHint(QPainter::Antialiasing); 249 250 /* Paint decorations: */ 251 paintDecorations(pPainter, pOption); 252 253 /* Paint machine info: */ 254 paintMachineInfo(pPainter, pOption); 502 255 } 503 256 … … 510 263 { 511 264 setToolTip(toolTipText()); 265 } 266 267 QString UIChooserItemMachine::description() const 268 { 269 return m_strDescription; 270 } 271 272 QString UIChooserItemMachine::fullName() const 273 { 274 /* Get full parent name, append with '/' if not yet appended: */ 275 AssertMsg(parentItem(), ("Incorrect parent set!")); 276 QString strFullParentName = parentItem()->fullName(); 277 if (!strFullParentName.endsWith('/')) 278 strFullParentName.append('/'); 279 /* Return full item name based on parent prefix: */ 280 return strFullParentName + name(); 281 } 282 283 QString UIChooserItemMachine::definition() const 284 { 285 return QString("m=%1").arg(name()); 512 286 } 513 287 … … 617 391 void UIChooserItemMachine::updateLayout() 618 392 { 619 /* Update tool-bar: */ 620 if (m_pToolBar) 621 { 622 /* Prepare variables: */ 623 QSize size = geometry().size().toSize(); 624 625 /* Prepare variables: */ 626 int iMachineItemWidth = size.width(); 627 int iMachineItemHeight = size.height(); 628 int iToolBarHeight = data(MachineItemData_ToolBarSize).toSize().height(); 629 630 /* Configure tool-bar: */ 631 QSize toolBarSize = m_pToolBar->minimumSizeHint().toSize(); 632 int iToolBarX = iMachineItemWidth - 1 - toolBarSize.width(); 633 int iToolBarY = (iMachineItemHeight - iToolBarHeight) / 2; 634 m_pToolBar->setPos(iToolBarX, iToolBarY); 635 m_pToolBar->resize(toolBarSize); 636 m_pToolBar->updateLayout(); 637 638 /* Configure buttons: */ 639 m_pStartButton->updateAnimation(); 640 m_pSettingsButton->updateAnimation(); 641 m_pCloseButton->updateAnimation(); 642 m_pPauseButton->updateAnimation(); 643 } 393 // Just do nothing .. 644 394 } 645 395 … … 650 400 int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt(); 651 401 int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt(); 652 int iToolBarWidth = data(MachineItemData_ToolBarSize).toSize().width();653 402 654 403 /* Calculating proposed width: */ … … 669 418 iMajorSpacing + 670 419 iRightColumnWidth; 671 if (m_pToolBar)672 iMachineItemWidth += (iMajorSpacing + iToolBarWidth);673 420 iProposedWidth += iMachineItemWidth; 674 421 … … 682 429 int iMargin = data(MachineItemData_Margin).toInt(); 683 430 int iMachineItemTextSpacing = data(MachineItemData_TextSpacing).toInt(); 684 int iToolBarHeight = data(MachineItemData_ToolBarSize).toSize().height();685 431 686 432 /* Calculating proposed height: */ … … 696 442 iBottomLineHeight; 697 443 QList<int> heights; 698 heights << m_pixmapSize.height() << iRightColumnHeight << iToolBarHeight;444 heights << m_pixmapSize.height() << iRightColumnHeight; 699 445 int iMaxHeight = 0; 700 446 foreach (int iHeight, heights) … … 828 574 } 829 575 830 void UIChooserItemMachine::showEvent(QShowEvent *pEvent) 831 { 832 /* Call to base-class: */ 833 UIChooserItem::showEvent(pEvent); 834 576 void UIChooserItemMachine::sltHandleWindowRemapped() 577 { 835 578 /* Recache and update pixmaps: */ 836 579 recachePixmap(); … … 838 581 } 839 582 840 void UIChooserItemMachine::resizeEvent(QGraphicsSceneResizeEvent *pEvent) 841 { 842 /* Call to base-class: */ 843 UIChooserItem::resizeEvent(pEvent); 844 845 /* What is the new geometry? */ 846 QRectF newGeometry = geometry(); 847 848 /* Should we update visible name? */ 849 if (previousGeometry().width() != newGeometry.width()) 583 void UIChooserItemMachine::prepare() 584 { 585 /* Colors: */ 586 #ifdef VBOX_WS_MAC 587 m_iHighlightLightness = 115; 588 m_iHoverLightness = 110; 589 m_iHoverHighlightLightness = 120; 590 #else /* VBOX_WS_MAC */ 591 m_iHighlightLightness = 130; 592 m_iHoverLightness = 155; 593 m_iHoverHighlightLightness = 175; 594 #endif /* !VBOX_WS_MAC */ 595 596 /* Fonts: */ 597 m_nameFont = font(); 598 m_nameFont.setWeight(QFont::Bold); 599 m_snapshotNameFont = font(); 600 m_stateTextFont = font(); 601 602 /* Sizes: */ 603 m_iFirstRowMaximumWidth = 0; 604 m_iMinimumNameWidth = 0; 605 m_iMaximumNameWidth = 0; 606 m_iMinimumSnapshotNameWidth = 0; 607 m_iMaximumSnapshotNameWidth = 0; 608 } 609 610 QVariant UIChooserItemMachine::data(int iKey) const 611 { 612 /* Provide other members with required data: */ 613 switch (iKey) 614 { 615 /* Layout hints: */ 616 case MachineItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 617 case MachineItemData_MajorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 618 case MachineItemData_MinorSpacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 619 case MachineItemData_TextSpacing: return 0; 620 621 /* Pixmaps: */ 622 case MachineItemData_SettingsButtonPixmap: return UIIconPool::iconSet(":/vm_settings_16px.png"); 623 case MachineItemData_StartButtonPixmap: return UIIconPool::iconSet(":/vm_start_16px.png"); 624 case MachineItemData_PauseButtonPixmap: return UIIconPool::iconSet(":/vm_pause_16px.png"); 625 case MachineItemData_CloseButtonPixmap: return UIIconPool::iconSet(":/exit_16px.png"); 626 627 /* Default: */ 628 default: break; 629 } 630 return QVariant(); 631 } 632 633 void UIChooserItemMachine::updatePixmaps() 634 { 635 /* Update pixmap: */ 636 updatePixmap(); 637 638 /* Update state-pixmap: */ 639 updateStatePixmap(); 640 } 641 642 void UIChooserItemMachine::updatePixmap() 643 { 644 /* Get new pixmap and pixmap-size: */ 645 QSize pixmapSize; 646 QPixmap pixmap = osPixmap(&pixmapSize); 647 /* Update linked values: */ 648 if (m_pixmapSize != pixmapSize) 649 { 650 m_pixmapSize = pixmapSize; 850 651 updateFirstRowMaximumWidth(); 851 852 /* Remember the new geometry: */ 853 setPreviousGeometry(newGeometry); 854 } 855 856 void UIChooserItemMachine::mousePressEvent(QGraphicsSceneMouseEvent *pEvent) 857 { 858 /* Call to base-class: */ 859 UIChooserItem::mousePressEvent(pEvent); 860 /* No drag for inaccessible: */ 861 if (!accessible()) 862 pEvent->ignore(); 863 } 864 865 void UIChooserItemMachine::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget* /* pWidget = 0 */) 866 { 867 /* Setup: */ 868 pPainter->setRenderHint(QPainter::Antialiasing); 869 870 /* Paint decorations: */ 871 paintDecorations(pPainter, pOption); 872 873 /* Paint machine info: */ 874 paintMachineInfo(pPainter, pOption); 652 updateGeometry(); 653 } 654 if (m_pixmap.toImage() != pixmap.toImage()) 655 { 656 m_pixmap = pixmap; 657 update(); 658 } 659 } 660 661 void UIChooserItemMachine::updateStatePixmap() 662 { 663 /* Determine the icon metric: */ 664 const QStyle *pStyle = QApplication::style(); 665 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 666 /* Get new state-pixmap and state-pixmap size: */ 667 const QIcon stateIcon = machineStateIcon(); 668 AssertReturnVoid(!stateIcon.isNull()); 669 const QSize statePixmapSize = QSize(iIconMetric, iIconMetric); 670 const QPixmap statePixmap = stateIcon.pixmap(gpManager->windowHandle(), statePixmapSize); 671 /* Update linked values: */ 672 if (m_statePixmapSize != statePixmapSize) 673 { 674 m_statePixmapSize = statePixmapSize; 675 updateGeometry(); 676 } 677 if (m_statePixmap.toImage() != statePixmap.toImage()) 678 { 679 m_statePixmap = statePixmap; 680 update(); 681 } 682 } 683 684 void UIChooserItemMachine::updateName() 685 { 686 /* Get new name: */ 687 QString strName = name(); 688 689 /* Is there something changed? */ 690 if (m_strName == strName) 691 return; 692 693 /* Update linked values: */ 694 m_strName = strName; 695 updateMinimumNameWidth(); 696 updateVisibleName(); 697 } 698 699 void UIChooserItemMachine::updateSnapshotName() 700 { 701 /* Get new snapshot-name: */ 702 QString strSnapshotName = snapshotName(); 703 704 /* Is there something changed? */ 705 if (m_strSnapshotName == strSnapshotName) 706 return; 707 708 /* Update linked values: */ 709 m_strSnapshotName = strSnapshotName; 710 updateMinimumSnapshotNameWidth(); 711 updateVisibleSnapshotName(); 712 } 713 714 void UIChooserItemMachine::updateFirstRowMaximumWidth() 715 { 716 /* Prepare variables: */ 717 int iMargin = data(MachineItemData_Margin).toInt(); 718 int iMajorSpacing = data(MachineItemData_MajorSpacing).toInt(); 719 720 /* Calculate new maximum width for the first row: */ 721 int iFirstRowMaximumWidth = (int)geometry().width(); 722 iFirstRowMaximumWidth -= iMargin; /* left margin */ 723 iFirstRowMaximumWidth -= m_pixmapSize.width(); /* pixmap width */ 724 iFirstRowMaximumWidth -= iMajorSpacing; /* spacing between pixmap and name(s) */ 725 iFirstRowMaximumWidth -= iMargin; /* right margin */ 726 727 /* Is there something changed? */ 728 if (m_iFirstRowMaximumWidth == iFirstRowMaximumWidth) 729 return; 730 731 /* Update linked values: */ 732 m_iFirstRowMaximumWidth = iFirstRowMaximumWidth; 733 updateMaximumNameWidth(); 734 updateMaximumSnapshotNameWidth(); 735 } 736 737 void UIChooserItemMachine::updateMinimumNameWidth() 738 { 739 /* Calculate new minimum name width: */ 740 QPaintDevice *pPaintDevice = model()->paintDevice(); 741 QFontMetrics fm(m_nameFont, pPaintDevice); 742 int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, m_strName, textWidth(m_nameFont, pPaintDevice, 15))); 743 744 /* Is there something changed? */ 745 if (m_iMinimumNameWidth == iMinimumNameWidth) 746 return; 747 748 /* Update linked values: */ 749 m_iMinimumNameWidth = iMinimumNameWidth; 750 updateGeometry(); 751 } 752 753 void UIChooserItemMachine::updateMinimumSnapshotNameWidth() 754 { 755 /* Calculate new minimum snapshot-name width: */ 756 int iMinimumSnapshotNameWidth = 0; 757 /* Is there any snapshot exists? */ 758 if (!m_strSnapshotName.isEmpty()) 759 { 760 QFontMetrics fm(m_snapshotNameFont, model()->paintDevice()); 761 int iBracketWidth = fm.width("()"); /* bracket width */ 762 int iActualTextWidth = fm.width(m_strSnapshotName); /* snapshot-name width */ 763 int iMinimumTextWidth = fm.width("..."); /* ellipsis width */ 764 iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth); 765 } 766 767 /* Is there something changed? */ 768 if (m_iMinimumSnapshotNameWidth == iMinimumSnapshotNameWidth) 769 return; 770 771 /* Update linked values: */ 772 m_iMinimumSnapshotNameWidth = iMinimumSnapshotNameWidth; 773 updateMaximumNameWidth(); 774 updateGeometry(); 775 } 776 777 void UIChooserItemMachine::updateMaximumNameWidth() 778 { 779 /* Calculate new maximum name width: */ 780 int iMaximumNameWidth = m_iFirstRowMaximumWidth; 781 /* Do we have a minimum snapshot-name width? */ 782 if (m_iMinimumSnapshotNameWidth != 0) 783 { 784 /* Prepare variables: */ 785 int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt(); 786 /* Take spacing and snapshot-name into account: */ 787 iMaximumNameWidth -= (iMinorSpacing + m_iMinimumSnapshotNameWidth); 788 } 789 790 /* Is there something changed? */ 791 if (m_iMaximumNameWidth == iMaximumNameWidth) 792 return; 793 794 /* Update linked values: */ 795 m_iMaximumNameWidth = iMaximumNameWidth; 796 updateVisibleName(); 797 } 798 799 void UIChooserItemMachine::updateMaximumSnapshotNameWidth() 800 { 801 /* Prepare variables: */ 802 int iMinorSpacing = data(MachineItemData_MinorSpacing).toInt(); 803 804 /* Calculate new maximum snapshot-name width: */ 805 int iMaximumSnapshotNameWidth = m_iFirstRowMaximumWidth; 806 iMaximumSnapshotNameWidth -= (iMinorSpacing + m_visibleNameSize.width()); 807 808 /* Is there something changed? */ 809 if (m_iMaximumSnapshotNameWidth == iMaximumSnapshotNameWidth) 810 return; 811 812 /* Update linked values: */ 813 m_iMaximumSnapshotNameWidth = iMaximumSnapshotNameWidth; 814 updateVisibleSnapshotName(); 815 } 816 817 void UIChooserItemMachine::updateVisibleName() 818 { 819 /* Prepare variables: */ 820 QPaintDevice *pPaintDevice = model()->paintDevice(); 821 822 /* Calculate new visible name and name-size: */ 823 QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth); 824 QSize visibleNameSize = textSize(m_nameFont, pPaintDevice, strVisibleName); 825 826 /* Update linked values: */ 827 if (m_visibleNameSize != visibleNameSize) 828 { 829 m_visibleNameSize = visibleNameSize; 830 updateMaximumSnapshotNameWidth(); 831 updateGeometry(); 832 } 833 if (m_strVisibleName != strVisibleName) 834 { 835 m_strVisibleName = strVisibleName; 836 update(); 837 } 838 } 839 840 void UIChooserItemMachine::updateVisibleSnapshotName() 841 { 842 /* Prepare variables: */ 843 QPaintDevice *pPaintDevice = model()->paintDevice(); 844 845 /* Calculate new visible snapshot-name: */ 846 int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()"); 847 QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, m_strSnapshotName, 848 m_iMaximumSnapshotNameWidth - iBracketWidth); 849 strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName); 850 QSize visibleSnapshotNameSize = textSize(m_snapshotNameFont, pPaintDevice, strVisibleSnapshotName); 851 852 /* Update linked values: */ 853 if (m_visibleSnapshotNameSize != visibleSnapshotNameSize) 854 { 855 m_visibleSnapshotNameSize = visibleSnapshotNameSize; 856 updateGeometry(); 857 } 858 if (m_strVisibleSnapshotName != strVisibleSnapshotName) 859 { 860 m_strVisibleSnapshotName = strVisibleSnapshotName; 861 update(); 862 } 863 } 864 865 void UIChooserItemMachine::updateStateText() 866 { 867 /* Get new state-text and state-text size: */ 868 QString strStateText = machineStateName(); 869 QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), m_strStateText); 870 871 /* Update linked values: */ 872 if (m_stateTextSize != stateTextSize) 873 { 874 m_stateTextSize = stateTextSize; 875 updateGeometry(); 876 } 877 if (m_strStateText != strStateText) 878 { 879 m_strStateText = strStateText; 880 update(); 881 } 875 882 } 876 883 … … 1111 1118 } 1112 1119 } 1113 1114 /* Tool-bar: */1115 if (m_pToolBar)1116 {1117 /* Show/hide tool-bar: */1118 if (isHovered())1119 {1120 if (!m_pToolBar->isVisible())1121 m_pToolBar->show();1122 }1123 else1124 {1125 if (m_pToolBar->isVisible())1126 m_pToolBar->hide();1127 }1128 }1129 }1130 1131 void UIChooserItemMachine::prepare()1132 {1133 /* Tool-bar/buttons: */1134 m_pToolBar = 0;1135 m_pSettingsButton = 0;1136 m_pStartButton = 0;1137 m_pPauseButton = 0;1138 m_pCloseButton = 0;1139 1140 /* Colors: */1141 #ifdef VBOX_WS_MAC1142 m_iHighlightLightness = 115;1143 m_iHoverLightness = 110;1144 m_iHoverHighlightLightness = 120;1145 #else /* VBOX_WS_MAC */1146 m_iHighlightLightness = 130;1147 m_iHoverLightness = 155;1148 m_iHoverHighlightLightness = 175;1149 #endif /* !VBOX_WS_MAC */1150 1151 /* Fonts: */1152 m_nameFont = font();1153 m_nameFont.setWeight(QFont::Bold);1154 m_snapshotNameFont = font();1155 m_stateTextFont = font();1156 1157 /* Sizes: */1158 m_iFirstRowMaximumWidth = 0;1159 m_iMinimumNameWidth = 0;1160 m_iMaximumNameWidth = 0;1161 m_iMinimumSnapshotNameWidth = 0;1162 m_iMaximumSnapshotNameWidth = 0;1163 1164 /* Other things disabled for now: */1165 return;1166 1167 #if 0 /* disabled for now */1168 /* Create tool-bar: */1169 m_pToolBar = new UIGraphicsToolBar(this, 2, 2);1170 1171 /* Create buttons: */1172 m_pSettingsButton = new UIGraphicsZoomButton(m_pToolBar,1173 data(MachineItemData_SettingsButtonPixmap).value<QIcon>(),1174 UIGraphicsZoomDirection_Top | UIGraphicsZoomDirection_Left);1175 m_pSettingsButton->setIndent(m_pToolBar->toolBarMargin() - 1);1176 m_pToolBar->insertItem(m_pSettingsButton, 0, 0);1177 1178 m_pStartButton = new UIGraphicsZoomButton(m_pToolBar,1179 data(MachineItemData_StartButtonPixmap).value<QIcon>(),1180 UIGraphicsZoomDirection_Top | UIGraphicsZoomDirection_Right);1181 m_pStartButton->setIndent(m_pToolBar->toolBarMargin() - 1);1182 m_pToolBar->insertItem(m_pStartButton, 0, 1);1183 1184 m_pPauseButton = new UIGraphicsZoomButton(m_pToolBar,1185 data(MachineItemData_PauseButtonPixmap).value<QIcon>(),1186 UIGraphicsZoomDirection_Bottom | UIGraphicsZoomDirection_Left);1187 m_pPauseButton->setIndent(m_pToolBar->toolBarMargin() - 1);1188 m_pToolBar->insertItem(m_pPauseButton, 1, 0);1189 1190 m_pCloseButton = new UIGraphicsZoomButton(m_pToolBar,1191 data(MachineItemData_CloseButtonPixmap).value<QIcon>(),1192 UIGraphicsZoomDirection_Bottom | UIGraphicsZoomDirection_Right);1193 m_pCloseButton->setIndent(m_pToolBar->toolBarMargin() - 1);1194 m_pToolBar->insertItem(m_pCloseButton, 1, 1);1195 1196 connect(m_pSettingsButton, SIGNAL(sigButtonClicked()),1197 actionPool()->action(UIActionIndexST_M_Machine_S_Settings), SLOT(trigger()),1198 Qt::QueuedConnection);1199 connect(m_pStartButton, SIGNAL(sigButtonClicked()),1200 actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow), SLOT(trigger()),1201 Qt::QueuedConnection);1202 connect(m_pPauseButton, SIGNAL(sigButtonClicked()),1203 actionPool()->action(UIActionIndexST_M_Machine_T_Pause), SLOT(trigger()),1204 Qt::QueuedConnection);1205 connect(m_pCloseButton, SIGNAL(sigButtonClicked()),1206 actionPool()->action(UIActionIndexST_M_Machine_M_Close_S_PowerOff), SLOT(trigger()),1207 Qt::QueuedConnection);1208 #endif /* disabled for now */1209 1120 } 1210 1121 1211 1122 /* static */ 1212 bool UIChooserItemMachine::c ontains(const QList<UIChooserItemMachine*> &list, UIChooserItemMachine *pItem)1123 bool UIChooserItemMachine::checkIfContains(const QList<UIChooserItemMachine*> &list, UIChooserItemMachine *pItem) 1213 1124 { 1214 1125 /* Check if passed list contains passed machine-item id: */ … … 1219 1130 return false; 1220 1131 } 1221 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h
r73927 r73962 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 __ UIChooserItemMachine_h__19 #define __ UIChooserItemMachine_h__18 #ifndef ___UIChooserItemMachine_h___ 19 #define ___UIChooserItemMachine_h___ 20 20 21 21 /* GUI includes: */ … … 25 25 /* Forward declarations: */ 26 26 class CMachine; 27 class UIGraphicsToolBar; 28 class UIGraphicsZoomButton; 29 30 /* Machine-item enumeration flags: */ 27 28 /** Machine-item enumeration flags. */ 31 29 enum UIChooserItemMachineEnumerationFlag 32 30 { … … 35 33 }; 36 34 37 /* Graphics machine-item 38 * for graphics selector model/view architecture: */ 35 /** UIChooserItem extension implementing machine item. */ 39 36 class UIChooserItemMachine : public UIChooserItem, public UIVirtualMachineItem 40 37 { … … 43 40 public: 44 41 45 /* Class-name used for drag&drop mime-data format: */ 46 static QString className(); 47 48 /* Graphics-item type: */ 42 /** RTTI item type. */ 49 43 enum { Type = UIChooserItemType_Machine }; 50 int type() const { return Type; } 51 52 /* Constructor (new item): */ 53 UIChooserItemMachine(UIChooserItem *pParent, const CMachine &machine, int iPosition = -1); 54 /* Constructor (new item copy): */ 44 45 /** Constructs item with specified @a comMachine and @a iPosition, passing @a pParent to the base-class. */ 46 UIChooserItemMachine(UIChooserItem *pParent, const CMachine &comMachine, int iPosition = -1); 47 /** Constructs temporary item with specified @a iPosition as a @a pCopyFrom, passing @a pParent to the base-class. */ 55 48 UIChooserItemMachine(UIChooserItem *pParent, UIChooserItemMachine *pCopyFrom, int iPosition = -1); 56 /* Destructor: */ 57 ~UIChooserItemMachine(); 58 59 /* API: Basic stuff: */ 60 QString name() const; 61 QString description() const; 62 QString fullName() const; 63 QString definition() const; 64 bool isLockedMachine() const; 65 66 /* API: Machine-item enumeration stuff: */ 67 static void enumerateMachineItems(const QList<UIChooserItem*> &il, 68 QList<UIChooserItemMachine*> &ol, 69 int iEnumerationFlags = 0); 49 /** Destructs machine item. */ 50 virtual ~UIChooserItemMachine() /* override */; 51 52 /** @name Item stuff. 53 * @{ */ 54 /** Returns item name. */ 55 virtual QString name() const /* override */; 56 57 /** Returns whether VM is locked. */ 58 bool isLockedMachine() const; 59 /** @} */ 60 61 /** @name Navigation stuff. 62 * @{ */ 63 /** Class-name used for drag&drop mime-data format. */ 64 static QString className(); 65 66 /** Enumerates machine items from @a il to @a ol using @a iEnumerationFlags. */ 67 static void enumerateMachineItems(const QList<UIChooserItem*> &il, 68 QList<UIChooserItemMachine*> &ol, 69 int iEnumerationFlags = 0); 70 /** @} */ 71 72 protected: 73 74 /** @name Event-handling stuff. 75 * @{ */ 76 /** Handles translation event. */ 77 virtual void retranslateUi() /* override */; 78 79 /** Handles show @a pEvent. */ 80 virtual void showEvent(QShowEvent *pEvent) /* override */; 81 82 /** Handles resize @a pEvent. */ 83 virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */; 84 85 /** Handles mouse press @a pEvent. */ 86 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) /* override */; 87 88 /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */ 89 virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */; 90 /** @} */ 91 92 /** @name Item stuff. 93 * @{ */ 94 /** Returns RTTI item type. */ 95 virtual int type() const /* override */ { return Type; } 96 97 /** Starts item editing. */ 98 virtual void startEditing() /* override */; 99 100 /** Updates item tool-tip. */ 101 virtual void updateToolTip() /* override */; 102 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 111 /** @name Children stuff. 112 * @{ */ 113 /** Adds child @a pItem to certain @a iPosition. */ 114 virtual void addItem(UIChooserItem *pItem, int iPosition) /* override */; 115 /** Removes child @a pItem. */ 116 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 127 /** Updates all children items with specified @a strId. */ 128 virtual void updateAllItems(const QString &strId) /* override */; 129 /** Removes all children items with specified @a strId. */ 130 virtual void removeAllItems(const QString &strId) /* override */; 131 132 /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */ 133 virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags) /* override */; 134 135 /** Searches for a first machine child item. */ 136 virtual UIChooserItem *firstMachineItem() /* override */; 137 138 /** Sorts children items. */ 139 virtual void sortItems() /* override */; 140 /** @} */ 141 142 /** @name Layout stuff. 143 * @{ */ 144 /** Updates layout. */ 145 virtual void updateLayout() /* override */; 146 147 /** Returns minimum width-hint. */ 148 virtual int minimumWidthHint() const /* override */; 149 /** Returns minimum height-hint. */ 150 virtual int minimumHeightHint() const /* override */; 151 152 /** Returns size-hint. 153 * @param enmWhich Brings size-hint type. 154 * @param constraint Brings size constraint. */ 155 virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */; 156 /** @} */ 157 158 /** @name Navigation stuff. 159 * @{ */ 160 /** Returns pixmap item representation. */ 161 virtual QPixmap toPixmap() /* override */; 162 163 /** Returns whether item drop is allowed. 164 * @param pEvent Brings information about drop event. 165 * @param enmPlace Brings the place of drag token to the drop moment. */ 166 virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const /* override */; 167 /** Processes item drop. 168 * @param pEvent Brings information about drop event. 169 * @param pFromWho Brings the item according to which we choose drop position. 170 * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */ 171 virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where) /* override */; 172 /** Reset drag token. */ 173 virtual void resetDragToken() /* override */; 174 175 /** Returns D&D mime data. */ 176 virtual QMimeData *createMimeData() /* override */; 177 /** @} */ 70 178 71 179 private slots: 72 180 73 /** Handles top-level window remaps. */ 74 void sltHandleWindowRemapped(); 181 /** @name Item stuff. 182 * @{ */ 183 /** Handles top-level window remaps. */ 184 void sltHandleWindowRemapped(); 185 /** @} */ 75 186 76 187 private: 77 188 78 /* Data enumerator:*/189 /** Data field types. */ 79 190 enum MachineItemData 80 191 { … … 89 200 MachineItemData_PauseButtonPixmap, 90 201 MachineItemData_CloseButtonPixmap, 91 /* Sizes: */92 MachineItemData_ToolBarSize93 202 }; 94 203 95 /* Data provider: */ 96 QVariant data(int iKey) const; 97 98 /* Helpers: Update stuff: */ 99 void updatePixmaps(); 100 void updatePixmap(); 101 void updateStatePixmap(); 102 void updateName(); 103 void updateSnapshotName(); 104 void updateFirstRowMaximumWidth(); 105 void updateMinimumNameWidth(); 106 void updateMinimumSnapshotNameWidth(); 107 void updateMaximumNameWidth(); 108 void updateMaximumSnapshotNameWidth(); 109 void updateVisibleName(); 110 void updateVisibleSnapshotName(); 111 void updateStateText(); 112 113 /* Helper: Translate stuff: */ 114 void retranslateUi(); 115 116 /* Helpers: Basic stuff: */ 117 void startEditing(); 118 void updateToolTip(); 119 120 /* Helpers: Children stuff: */ 121 void addItem(UIChooserItem *pItem, int iPosition); 122 void removeItem(UIChooserItem *pItem); 123 void setItems(const QList<UIChooserItem*> &items, UIChooserItemType type); 124 QList<UIChooserItem*> items(UIChooserItemType type) const; 125 bool hasItems(UIChooserItemType type) const; 126 void clearItems(UIChooserItemType type); 127 void updateAllItems(const QString &strId); 128 void removeAllItems(const QString &strId); 129 UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags); 130 UIChooserItem *firstMachineItem(); 131 void sortItems(); 132 133 /* Helpers: Layout stuff: */ 134 void updateLayout(); 135 int minimumWidthHint() const; 136 int minimumHeightHint() const; 137 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; 138 139 /* Helpers: Drag and drop stuff: */ 140 QPixmap toPixmap(); 141 bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const; 142 void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where); 143 void resetDragToken(); 144 QMimeData* createMimeData(); 145 146 /** Handles show @a pEvent. */ 147 virtual void showEvent(QShowEvent *pEvent) /* override */; 148 149 /* Handler: Resize handling stuff: */ 150 void resizeEvent(QGraphicsSceneResizeEvent *pEvent); 151 152 /* Handler: Mouse handling stuff: */ 153 void mousePressEvent(QGraphicsSceneMouseEvent *pEvent); 154 155 /* Helpers: Paint stuff: */ 156 void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0); 157 void paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption); 158 void paintBackground(QPainter *pPainter, const QRect &rect); 159 void paintFrameRectangle(QPainter *pPainter, const QRect &rect); 160 void paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption); 161 162 /* Helpers: Prepare stuff: */ 163 void prepare(); 164 165 /* Helper: Machine-item enumeration stuff: */ 166 static bool contains(const QList<UIChooserItemMachine*> &list, 167 UIChooserItemMachine *pItem); 168 169 /* Variables: */ 170 UIGraphicsToolBar *m_pToolBar; 171 UIGraphicsZoomButton *m_pSettingsButton; 172 UIGraphicsZoomButton *m_pStartButton; 173 UIGraphicsZoomButton *m_pPauseButton; 174 UIGraphicsZoomButton *m_pCloseButton; 175 int m_iHighlightLightness; 176 int m_iHoverLightness; 177 int m_iHoverHighlightLightness; 178 /* Cached values: */ 179 QFont m_nameFont; 180 QFont m_snapshotNameFont; 181 QFont m_stateTextFont; 182 QPixmap m_pixmap; 183 QPixmap m_statePixmap; 184 QString m_strName; 185 QString m_strDescription; 186 QString m_strVisibleName; 187 QString m_strSnapshotName; 188 QString m_strVisibleSnapshotName; 189 QString m_strStateText; 190 QSize m_pixmapSize; 191 QSize m_statePixmapSize; 192 QSize m_visibleNameSize; 193 QSize m_visibleSnapshotNameSize; 194 QSize m_stateTextSize; 195 int m_iFirstRowMaximumWidth; 196 int m_iMinimumNameWidth; 197 int m_iMaximumNameWidth; 198 int m_iMinimumSnapshotNameWidth; 199 int m_iMaximumSnapshotNameWidth; 204 /** @name Prepare/cleanup cascade. 205 * @{ */ 206 /** Prepares all. */ 207 void prepare(); 208 /** @} */ 209 210 /** @name Item stuff. 211 * @{ */ 212 /** Returns abstractly stored data value for certain @a iKey. */ 213 QVariant data(int iKey) const; 214 /** @} */ 215 216 /** @name Layout stuff. 217 * @{ */ 218 /** Updates pixmaps. */ 219 void updatePixmaps(); 220 /** Updates pixmap. */ 221 void updatePixmap(); 222 /** Updates state pixmap. */ 223 void updateStatePixmap(); 224 /** Updates name. */ 225 void updateName(); 226 /** Updates snapshot name. */ 227 void updateSnapshotName(); 228 /** Updates first row maximum width. */ 229 void updateFirstRowMaximumWidth(); 230 /** Updates minimum name width. */ 231 void updateMinimumNameWidth(); 232 /** Updates minimum snapshot name width. */ 233 void updateMinimumSnapshotNameWidth(); 234 /** Updates maximum name width. */ 235 void updateMaximumNameWidth(); 236 /** Updates maximum snapshot name width. */ 237 void updateMaximumSnapshotNameWidth(); 238 /** Updates visible name. */ 239 void updateVisibleName(); 240 /** Updates visible snapshot name. */ 241 void updateVisibleSnapshotName(); 242 /** Updates state text. */ 243 void updateStateText(); 244 /** @} */ 245 246 /** @name Painting stuff. 247 * @{ */ 248 /** Paints decorations using specified @a pPainter and certain @a pOptions. */ 249 void paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption); 250 /** Paints background using specified @a pPainter and certain @a rect. */ 251 void paintBackground(QPainter *pPainter, const QRect &rect); 252 /** Paints frame rectangle using specified @a pPainter and certain @a rect. */ 253 void paintFrameRectangle(QPainter *pPainter, const QRect &rect); 254 /** Paints machine info using specified @a pPainter and certain @a pOptions. */ 255 void paintMachineInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption); 256 /** @} */ 257 258 /** @name Navigation stuff. 259 * @{ */ 260 /** Returns whether machine items @a list contains passed @a pItem. */ 261 static bool checkIfContains(const QList<UIChooserItemMachine*> &list, 262 UIChooserItemMachine *pItem); 263 /** @} */ 264 265 /** @name Item stuff. 266 * @{ */ 267 /** Holds item hover lightness. */ 268 int m_iHoverLightness; 269 /** Holds item highlight lightness. */ 270 int m_iHighlightLightness; 271 /** Holds item hover highlight lightness. */ 272 int m_iHoverHighlightLightness; 273 274 /** Holds item pixmap. */ 275 QPixmap m_pixmap; 276 /** Holds item state pixmap. */ 277 QPixmap m_statePixmap; 278 279 /** Holds item name. */ 280 QString m_strName; 281 /** Holds item description. */ 282 QString m_strDescription; 283 /** Holds item visible name. */ 284 QString m_strVisibleName; 285 /** Holds item snapshot name. */ 286 QString m_strSnapshotName; 287 /** Holds item visible snapshot name. */ 288 QString m_strVisibleSnapshotName; 289 /** Holds item state text. */ 290 QString m_strStateText; 291 292 /** Holds item name font. */ 293 QFont m_nameFont; 294 /** Holds item snapshot name font. */ 295 QFont m_snapshotNameFont; 296 /** Holds item state text font. */ 297 QFont m_stateTextFont; 298 /** @} */ 299 300 /** @name Layout stuff. 301 * @{ */ 302 /** Holds pixmap size. */ 303 QSize m_pixmapSize; 304 /** Holds state pixmap size. */ 305 QSize m_statePixmapSize; 306 /** Holds visible name size. */ 307 QSize m_visibleNameSize; 308 /** Holds visible snapshot name size. */ 309 QSize m_visibleSnapshotNameSize; 310 /** Holds state text size. */ 311 QSize m_stateTextSize; 312 313 /** Holds first row maximum width. */ 314 int m_iFirstRowMaximumWidth; 315 /** Holds minimum name width. */ 316 int m_iMinimumNameWidth; 317 /** Holds maximum name width. */ 318 int m_iMaximumNameWidth; 319 /** Holds minimum snapshot name width. */ 320 int m_iMinimumSnapshotNameWidth; 321 /** Holds maximum snapshot name width. */ 322 int m_iMaximumSnapshotNameWidth; 323 /** @} */ 200 324 }; 201 325 202 #endif /* __UIChooserItemMachine_h__ */ 203 326 #endif /* !___UIChooserItemMachine_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.