- Timestamp:
- Nov 28, 2012 2:24:00 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.cpp
r43982 r43984 19 19 20 20 /* Qt includes: */ 21 #include <QApplication>22 21 #include <QGraphicsView> 23 22 #include <QStateMachine> … … 41 40 , m_type(type) 42 41 , m_iCornerRadius(10) 42 , m_iMinimumHeaderWidth(0) 43 , m_iMinimumHeaderHeight(0) 43 44 , m_fClosed(!fOpened) 44 45 , m_pButton(0) … … 93 94 /* Prepare variables: */ 94 95 int iMargin = data(ElementData_Margin).toInt(); 95 int iHeaderWidth = data(ElementData_HeaderSize).toSize().width();96 96 int iTextWidth = data(ElementData_TextWidth).toInt(); 97 98 /* Calculating proposed width: */99 97 int iProposedWidth = 0; 100 98 101 99 /* Maximum width: */ 102 iProposedWidth = qMax( iHeaderWidth, iTextWidth);100 iProposedWidth = qMax(m_iMinimumHeaderWidth, iTextWidth); 103 101 104 102 /* And 4 margins: 2 left and 2 right: */ … … 161 159 case ElementData_Margin: return 5; 162 160 case ElementData_Spacing: return 10; 163 /* Pixmaps: */164 case ElementData_Pixmap: return m_icon;165 /* Fonts: */166 case ElementData_NameFont:167 {168 QFont nameFont = qApp->font();169 nameFont.setWeight(QFont::Bold);170 return nameFont;171 }172 case ElementData_TextFont:173 {174 QFont textFont = qApp->font();175 return textFont;176 }177 /* Sizes: */178 case ElementData_PixmapSize:179 return m_icon.isNull() ? QSize(0, 0) : m_icon.availableSizes().at(0);180 case ElementData_NameSize:181 {182 QFontMetrics fm(data(ElementData_NameFont).value<QFont>(), model()->paintDevice());183 return QSize(fm.width(m_strName), fm.height());184 }185 case ElementData_ButtonSize: return m_pButton->minimumSizeHint();186 case ElementData_HeaderSize:187 {188 /* Prepare variables: */189 int iMargin = data(ElementData_Margin).toInt();190 int iSpacing = data(ElementData_Spacing).toInt();191 QSize pixmapSize = data(ElementData_PixmapSize).toSize();192 QSize nameSize = data(ElementData_NameSize).toSize();193 QSize buttonSize = data(ElementData_ButtonSize).toSize();194 /* Header width: */195 int iHeaderWidth = iMargin + pixmapSize.width() + iSpacing +196 nameSize.width() + iSpacing + buttonSize.width();197 /* Header height: */198 int iHeaderHeight = qMax(pixmapSize.height(), nameSize.height());199 iHeaderHeight = qMax(iHeaderHeight, buttonSize.height());200 /* Return value: */201 return QSize(iHeaderWidth, iHeaderHeight);202 }203 161 case ElementData_TextWidth: 204 162 { … … 206 164 int iSpacing = data(ElementData_Spacing).toInt(); 207 165 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 208 QFontMetrics fm( data(ElementData_TextFont).value<QFont>(), model()->paintDevice());166 QFontMetrics fm(m_textFont, model()->paintDevice()); 209 167 210 168 /* Search for the maximum line widths: */ … … 251 209 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 252 210 int iMaximumTextWidth = (int)geometry().width() - 3 * iMargin - iSpacing; 253 QFont textFont = data(ElementData_TextFont).value<QFont>();254 211 QPaintDevice *pPaintDevice = model()->paintDevice(); 255 QFontMetrics fm( textFont, pPaintDevice);212 QFontMetrics fm(m_textFont, pPaintDevice); 256 213 257 214 /* Search for the maximum line widths: */ … … 296 253 { 297 254 bool fRightColumnPresent = !line.second.isEmpty(); 298 QTextLayout *pTextLayout = prepareTextLayout( textFont, pPaintDevice,255 QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice, 299 256 fRightColumnPresent ? line.first + ":" : line.first, 300 257 iLeftColumnWidth, iLeftColumnHeight); … … 306 263 if (!line.second.isEmpty()) 307 264 { 308 QTextLayout *pTextLayout = prepareTextLayout( textFont, pPaintDevice, line.second,265 QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice, line.second, 309 266 iRightColumnWidth, iRightColumnHeight); 310 267 delete pTextLayout; … … 325 282 } 326 283 284 void UIGDetailsElement::updateMinimumHeaderWidth() 285 { 286 /* Prepare variables: */ 287 int iSpacing = data(ElementData_Spacing).toInt(); 288 289 /* Update minimum-header-width: */ 290 m_iMinimumHeaderWidth = m_pixmapSize.width() + 291 iSpacing + m_nameSize.width() + 292 iSpacing + m_buttonSize.width(); 293 } 294 295 void UIGDetailsElement::updateMinimumHeaderHeight() 296 { 297 /* Update minimum-header-height: */ 298 m_iMinimumHeaderHeight = qMax(m_pixmapSize.height(), m_nameSize.height()); 299 m_iMinimumHeaderHeight = qMax(m_iMinimumHeaderHeight, m_buttonSize.height()); 300 } 301 327 302 void UIGDetailsElement::setIcon(const QIcon &icon) 328 303 { 329 m_icon = icon; 304 /* Cache icon: */ 305 m_pixmapSize = icon.isNull() ? QSize(0, 0) : icon.availableSizes().first(); 306 m_pixmap = icon.pixmap(m_pixmapSize); 307 308 /* Update linked values: */ 309 updateMinimumHeaderWidth(); 310 updateMinimumHeaderHeight(); 330 311 } 331 312 332 313 void UIGDetailsElement::setName(const QString &strName) 333 314 { 315 /* Cache name: */ 334 316 m_strName = strName; 317 QFontMetrics fm(m_nameFont, model()->paintDevice()); 318 m_nameSize = QSize(fm.width(m_strName), fm.height()); 319 320 /* Update linked values: */ 321 updateMinimumHeaderWidth(); 322 updateMinimumHeaderHeight(); 335 323 } 336 324 … … 392 380 void UIGDetailsElement::prepareElement() 393 381 { 382 /* Initialization: */ 383 m_nameFont = font(); 384 m_nameFont.setWeight(QFont::Bold); 385 m_textFont = font(); 386 394 387 /* Create highlight machine: */ 395 388 m_pHighlightMachine = new QStateMachine(this); … … 435 428 connect(m_pButton, SIGNAL(sigRotationStart()), this, SLOT(sltElementToggleStart())); 436 429 connect(m_pButton, SIGNAL(sigRotationFinish(bool)), this, SLOT(sltElementToggleFinish(bool))); 430 m_buttonSize = m_pButton->minimumSizeHint().toSize(); 437 431 } 438 432 … … 445 439 QSize size = geometry().size().toSize(); 446 440 int iMargin = data(ElementData_Margin).toInt(); 447 QSize buttonSize = data(ElementData_ButtonSize).toSize(); 448 int iButtonWidth = buttonSize.width(); 449 int iButtonHeight = buttonSize.height(); 450 int iFullHeaderHeight = data(ElementData_HeaderSize).toSize().height(); 441 int iButtonWidth = m_buttonSize.width(); 442 int iButtonHeight = m_buttonSize.height(); 451 443 452 444 /* Layout button: */ 453 445 int iButtonX = size.width() - 2 * iMargin - iButtonWidth; 454 int iButtonY = iButtonHeight == iFullHeaderHeight ? iMargin :455 iMargin + ( iFullHeaderHeight - iButtonHeight) / 2;446 int iButtonY = iButtonHeight == m_iMinimumHeaderHeight ? iMargin : 447 iMargin + (m_iMinimumHeaderHeight - iButtonHeight) / 2; 456 448 m_pButton->setPos(iButtonX, iButtonY); 457 449 } … … 471 463 /* Prepare variables: */ 472 464 int iMargin = data(ElementData_Margin).toInt(); 473 int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();474 465 int iTextHeight = data(ElementData_TextHeight).toInt(); 475 476 /* Calculating proposed height: */477 466 int iProposedHeight = 0; 478 467 … … 481 470 482 471 /* Header height: */ 483 iProposedHeight += iHeaderHeight;472 iProposedHeight += m_iMinimumHeaderHeight; 484 473 485 474 /* Element is opened? */ … … 495 484 iProposedHeight += m_iAdditionalHeight; 496 485 497 /* Return result: */486 /* Return value: */ 498 487 return iProposedHeight; 499 488 } … … 538 527 int iMargin = data(ElementData_Margin).toInt(); 539 528 int iSpacing = data(ElementData_Spacing).toInt(); 540 QSize pixmapSize = data(ElementData_PixmapSize).toSize();541 QSize nameSize = data(ElementData_NameSize).toSize();542 int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();543 529 544 530 /* Calculate attributes: */ 545 int iPixmapHeight = pixmapSize.height();546 int iNameHeight = nameSize.height();531 int iPixmapHeight = m_pixmapSize.height(); 532 int iNameHeight = m_nameSize.height(); 547 533 int iMaximumHeight = qMax(iPixmapHeight, iNameHeight); 548 534 … … 560 546 pPainter, 561 547 /* Rectangle to paint in: */ 562 QRect(QPoint(iMachinePixmapX, iMachinePixmapY), pixmapSize),548 QRect(QPoint(iMachinePixmapX, iMachinePixmapY), m_pixmapSize), 563 549 /* Pixmap to paint: */ 564 data(ElementData_Pixmap).value<QIcon>().pixmap(pixmapSize));550 m_pixmap); 565 551 566 552 /* Paint name: */ 567 553 int iMachineNameX = iMachinePixmapX + 568 pixmapSize.width() +554 m_pixmapSize.width() + 569 555 iSpacing; 570 556 int iMachineNameY = iNameHeight == iMaximumHeight ? … … 573 559 pPainter, 574 560 /* Rectangle to paint in: */ 575 QRect(QPoint(iMachineNameX, iMachineNameY), nameSize),561 QRect(QPoint(iMachineNameX, iMachineNameY), m_nameSize), 576 562 /* Font to paint text: */ 577 data(ElementData_NameFont).value<QFont>(),563 m_nameFont, 578 564 /* Text to paint: */ 579 565 m_strName, … … 591 577 int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt(); 592 578 int iMaximumTextWidth = geometry().width() - 3 * iMargin - iSpacing; 593 QFont textFont = data(ElementData_TextFont).value<QFont>();594 579 QPaintDevice *pPaintDevice = model()->paintDevice(); 595 QFontMetrics fm( textFont, pPaintDevice);580 QFontMetrics fm(m_textFont, pPaintDevice); 596 581 597 582 /* Search for the maximum line widths: */ … … 629 614 /* Where to paint? */ 630 615 int iMachineTextX = iMachinePixmapX; 631 int iMachineTextY = iMargin + iHeaderHeight + 2 * iMargin;616 int iMachineTextY = iMargin + m_iMinimumHeaderHeight + 2 * iMargin; 632 617 633 618 /* For each the line: */ … … 639 624 { 640 625 bool fRightColumnPresent = !line.second.isEmpty(); 641 QTextLayout *pTextLayout = prepareTextLayout( textFont, pPaintDevice,626 QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice, 642 627 fRightColumnPresent ? line.first + ":" : line.first, 643 628 iLeftColumnWidth, iLeftColumnHeight); … … 650 635 if (!line.second.isEmpty()) 651 636 { 652 QTextLayout *pTextLayout = prepareTextLayout( textFont, pPaintDevice,637 QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice, 653 638 line.second, iRightColumnWidth, iRightColumnHeight); 654 639 pTextLayout->draw(pPainter, QPointF(iMachineTextX + iLeftColumnWidth + iSpacing, iMachineTextY)); … … 672 657 /* Prepare variables: */ 673 658 int iMargin = data(ElementData_Margin).toInt(); 674 int iHeaderContentHeight = data(ElementData_HeaderSize).toSize().height(); 675 int iHeaderHeight = 2 * iMargin + iHeaderContentHeight; 659 int iHeaderHeight = 2 * iMargin + m_iMinimumHeaderHeight; 676 660 QRect optionRect = pOption->rect; 677 661 QRect fullRect = !m_fAnimationRunning ? optionRect : … … 792 776 int iMargin = data(ElementData_Margin).toInt(); 793 777 int iSpacing = data(ElementData_Spacing).toInt(); 794 int iPixmapWidth = data(ElementData_PixmapSize).toSize().width(); 795 QSize nameSize = data(ElementData_NameSize).toSize(); 796 int iNameHeight = nameSize.height(); 797 int iHeaderHeight = data(ElementData_HeaderSize).toSize().height(); 798 int iMachineNameX = 2 * iMargin + iPixmapWidth + iSpacing; 799 int iMachineNameY = iNameHeight == iHeaderHeight ? 800 iMargin : iMargin + (iHeaderHeight - iNameHeight) / 2; 778 int iNameHeight = m_nameSize.height(); 779 int iMachineNameX = 2 * iMargin + m_pixmapSize.width() + iSpacing; 780 int iMachineNameY = iNameHeight == m_iMinimumHeaderHeight ? 781 iMargin : iMargin + (m_iMinimumHeaderHeight - iNameHeight) / 2; 801 782 802 783 /* Simulate hyperlink hovering: */ 803 784 QPoint point = pEvent->pos().toPoint(); 804 bool fNameHovered = QRect(QPoint(iMachineNameX, iMachineNameY), nameSize).contains(point);785 bool fNameHovered = QRect(QPoint(iMachineNameX, iMachineNameY), m_nameSize).contains(point); 805 786 if (m_fNameHoveringAccessible && m_fNameHovered != fNameHovered) 806 787 { -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h
r43982 r43984 109 109 ElementData_Margin, 110 110 ElementData_Spacing, 111 /* Pixmaps: */112 ElementData_Pixmap,113 /* Fonts: */114 ElementData_NameFont,115 ElementData_TextFont,116 111 /* Sizes: */ 117 ElementData_PixmapSize,118 ElementData_NameSize,119 ElementData_ButtonSize,120 ElementData_HeaderSize,121 112 ElementData_TextWidth, 122 113 ElementData_TextHeight, … … 127 118 QVariant data(int iKey) const; 128 119 120 /* Helpers: Update stuff: */ 121 void updateMinimumHeaderWidth(); 122 void updateMinimumHeaderHeight(); 123 129 124 /* API: Icon stuff: */ 130 125 void setIcon(const QIcon &icon); … … 141 136 142 137 /* Helpers: Layout stuff: */ 138 int minimumHeaderWidth() const { return m_iMinimumHeaderWidth; } 139 int minimumHeaderHeight() const { return m_iMinimumHeaderHeight; } 143 140 void updateLayout(); 144 141 … … 196 193 UIGDetailsSet *m_pSet; 197 194 DetailsElementType m_type; 198 Q Icon m_icon;195 QPixmap m_pixmap; 199 196 QString m_strName; 200 197 UITextTable m_text; 201 198 int m_iCornerRadius; 199 QFont m_nameFont; 200 QFont m_textFont; 201 QSize m_pixmapSize; 202 QSize m_nameSize; 203 QSize m_buttonSize; 204 int m_iMinimumHeaderWidth; 205 int m_iMinimumHeaderHeight; 202 206 203 207 /* Variables: Toggle stuff: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElements.cpp
r43982 r43984 169 169 /* Prepare variables: */ 170 170 int iMargin = data(ElementData_Margin).toInt(); 171 int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();172 171 /* Prepare layout: */ 173 172 QGraphicsLinearLayout *pLayout = new QGraphicsLinearLayout; 174 pLayout->setContentsMargins(iMargin, 2 * iMargin + iHeaderHeight, iMargin, iMargin);173 pLayout->setContentsMargins(iMargin, 2 * iMargin + minimumHeaderHeight(), iMargin, iMargin); 175 174 setLayout(pLayout); 176 175 … … 185 184 /* Prepare variables: */ 186 185 int iMargin = data(ElementData_Margin).toInt(); 187 int iHeaderWidth = data(ElementData_HeaderSize).toSize().width();188 186 189 187 /* Calculating proposed width: */ … … 191 189 192 190 /* Maximum between header width and preview width: */ 193 iProposedWidth += qMax( iHeaderWidth, m_pPreview->minimumSizeHint().toSize().width());191 iProposedWidth += qMax(minimumHeaderWidth(), m_pPreview->minimumSizeHint().toSize().width()); 194 192 195 193 /* Two margins: */ … … 204 202 /* Prepare variables: */ 205 203 int iMargin = data(ElementData_Margin).toInt(); 206 int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();207 204 208 205 /* Calculating proposed height: */ … … 213 210 214 211 /* Header height: */ 215 iProposedHeight += iHeaderHeight;212 iProposedHeight += minimumHeaderHeight(); 216 213 217 214 /* Element is opened? */
Note:
See TracChangeset
for help on using the changeset viewer.