Changeset 74083 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Sep 5, 2018 1:08:01 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/details
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetails.cpp
r73424 r74083 66 66 setAutoFillBackground(true); 67 67 QPalette pal = qApp->palette(); 68 pal.setColor(QPalette::Window, pal.color(QPalette::Active, QPalette::Window)); 68 const QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110); 69 pal.setColor(QPalette::Base, bodyColor); 69 70 setPalette(pal); 70 71 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.cpp
r74082 r74083 47 47 , m_pSet(pParent) 48 48 , m_enmType(enmType) 49 , m_i CornerRadius(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2)50 , m_i HeaderDarkness(110)49 , m_iLightnessToneStart(155) 50 , m_iLightnessToneFinal(175) 51 51 , m_fHovered(false) 52 52 , m_fNameHovered(false) … … 55 55 , m_pHoveringAnimationBackward(0) 56 56 , m_iAnimationDuration(300) 57 , m_iDefaultValue( 100)58 , m_iHoveredValue( 90)57 , m_iDefaultValue(0) 58 , m_iHoveredValue(255) 59 59 , m_iAnimatedValue(m_iDefaultValue) 60 60 , m_pButton(0) … … 227 227 updateButtonVisibility(); 228 228 229 /* Configure painter shape: */ 230 configurePainterShape(pPainter, pOptions, m_iCornerRadius); 231 232 /* Paint decorations: */ 233 paintDecorations(pPainter, pOptions); 234 229 /* Paint background: */ 230 paintBackground(pPainter, pOptions); 231 /* Paint frame rectangle: */ 232 paintFrameRect(pPainter, pOptions); 235 233 /* Paint element info: */ 236 234 paintElementInfo(pPainter, pOptions); … … 648 646 } 649 647 650 void UIDetailsElement::paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) 651 { 652 /* Paint background: */ 653 paintBackground(pPainter, pOptions); 654 } 655 656 void UIDetailsElement::paintElementInfo(QPainter *pPainter, const QStyleOptionGraphicsItem*) 648 void UIDetailsElement::paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) const 649 { 650 /* Save painter: */ 651 pPainter->save(); 652 653 /* Prepare variables: */ 654 const int iMargin = data(ElementData_Margin).toInt(); 655 const int iHeadHeight = 2 * iMargin + m_iMinimumHeaderHeight; 656 const QRect optionRect = pOptions->rect; 657 const QRect headRect = QRect(optionRect.topLeft(), QSize(optionRect.width(), iHeadHeight)); 658 const QRect fullRect = m_fAnimationRunning 659 ? QRect(optionRect.topLeft(), QSize(optionRect.width(), iHeadHeight + m_iAdditionalHeight)) 660 : optionRect; 661 662 /* Acquire palette: */ 663 const QPalette pal = palette(); 664 665 /* Paint default background: */ 666 const QColor defaultColor = pal.color(QPalette::Active, QPalette::Mid); 667 const QColor dcTone1 = defaultColor.lighter(m_iLightnessToneFinal); 668 const QColor dcTone2 = defaultColor.lighter(m_iLightnessToneStart); 669 QLinearGradient gradientDefault(fullRect.topLeft(), fullRect.bottomLeft()); 670 gradientDefault.setColorAt(0, dcTone1); 671 gradientDefault.setColorAt(1, dcTone2); 672 pPainter->fillRect(fullRect, gradientDefault); 673 674 /* If element is hovered: */ 675 if (m_fHovered) 676 { 677 /* Paint hovered background: */ 678 const QColor hoveredColor = pal.color(QPalette::Active, QPalette::Highlight); 679 QColor hcTone1 = hoveredColor.lighter(m_iLightnessToneFinal); 680 QColor hcTone2 = hoveredColor.lighter(m_iLightnessToneStart); 681 hcTone1.setAlpha(m_iAnimatedValue); 682 hcTone2.setAlpha(m_iAnimatedValue); 683 QLinearGradient gradientHovered(headRect.topLeft(), headRect.bottomLeft()); 684 gradientHovered.setColorAt(0, hcTone1); 685 gradientHovered.setColorAt(1, hcTone2); 686 pPainter->fillRect(headRect, gradientHovered); 687 } 688 689 /* Restore painter: */ 690 pPainter->restore(); 691 } 692 693 void UIDetailsElement::paintFrameRect(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) const 694 { 695 /* Save painter: */ 696 pPainter->save(); 697 698 /* Paint frame: */ 699 const QPalette pal = palette(); 700 const QColor frameColor = pal.color(QPalette::Active, QPalette::Mid); 701 pPainter->setPen(frameColor.lighter(m_iLightnessToneStart)); 702 pPainter->drawRect(pOptions->rect); 703 704 /* Restore painter: */ 705 pPainter->restore(); 706 } 707 708 void UIDetailsElement::paintElementInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *) const 657 709 { 658 710 /* Initialize some necessary variables: */ 659 int iMargin = data(ElementData_Margin).toInt();660 int iSpacing = data(ElementData_Spacing).toInt();711 const int iMargin = data(ElementData_Margin).toInt(); 712 const int iSpacing = data(ElementData_Spacing).toInt(); 661 713 662 714 /* Calculate attributes: */ 663 int iPixmapHeight = m_pixmapSize.height();664 int iNameHeight = m_nameSize.height();665 int iMaximumHeight = qMax(iPixmapHeight, iNameHeight);715 const int iPixmapHeight = m_pixmapSize.height(); 716 const int iNameHeight = m_nameSize.height(); 717 const int iMaximumHeight = qMax(iPixmapHeight, iNameHeight); 666 718 667 719 /* Prepare color: */ 668 QPalette pal = palette();669 QColor buttonTextColor = pal.color(QPalette::Active, QPalette::ButtonText);670 QColor linkTextColor = pal.color(QPalette::Active, QPalette::Link);720 const QPalette pal = palette(); 721 const QColor buttonTextColor = pal.color(QPalette::Active, QPalette::ButtonText); 722 const QColor linkTextColor = pal.color(QPalette::Active, QPalette::Link); 671 723 672 724 /* Paint pixmap: */ … … 701 753 } 702 754 703 void UIDetailsElement::paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions)704 {705 /* Save painter: */706 pPainter->save();707 708 /* Prepare variables: */709 int iMargin = data(ElementData_Margin).toInt();710 int iHeaderHeight = 2 * iMargin + m_iMinimumHeaderHeight;711 QRect optionRect = pOptions->rect;712 QRect fullRect = !m_fAnimationRunning ? optionRect :713 QRect(optionRect.topLeft(), QSize(optionRect.width(), iHeaderHeight + m_iAdditionalHeight));714 int iFullHeight = fullRect.height();715 716 /* Prepare color: */717 QPalette pal = palette();718 QColor headerColor = pal.color(QPalette::Active, QPalette::Button);719 QColor strokeColor = pal.color(QPalette::Active, QPalette::Mid);720 QColor bodyColor = pal.color(QPalette::Active, QPalette::Base);721 722 /* Add clipping: */723 QPainterPath path;724 path.moveTo(m_iCornerRadius, 0);725 path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, 0), 90, 90);726 path.lineTo(path.currentPosition().x(), iFullHeight - m_iCornerRadius);727 path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(0, -m_iCornerRadius), 180, 90);728 path.lineTo(fullRect.width() - m_iCornerRadius, path.currentPosition().y());729 path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, -2 * m_iCornerRadius), 270, 90);730 path.lineTo(path.currentPosition().x(), m_iCornerRadius);731 path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-2 * m_iCornerRadius, -m_iCornerRadius), 0, 90);732 path.closeSubpath();733 pPainter->setClipPath(path);734 735 /* Calculate top rectangle: */736 QRect tRect = fullRect;737 tRect.setBottom(tRect.top() + iHeaderHeight);738 /* Calculate bottom rectangle: */739 QRect bRect = fullRect;740 bRect.setTop(tRect.bottom());741 742 /* Prepare top gradient: */743 QLinearGradient tGradient(tRect.bottomLeft(), tRect.topLeft());744 tGradient.setColorAt(0, headerColor.darker(headerDarkness()));745 tGradient.setColorAt(1, headerColor.darker(animatedValue()));746 747 /* Paint all the stuff: */748 pPainter->fillRect(tRect, tGradient);749 pPainter->fillRect(bRect, bodyColor);750 751 /* Stroke path: */752 pPainter->setClipping(false);753 pPainter->strokePath(path, strokeColor);754 755 /* Restore painter: */756 pPainter->restore();757 }758 759 /* static */760 void UIDetailsElement::configurePainterShape(QPainter *pPainter,761 const QStyleOptionGraphicsItem *pOptions,762 int iRadius)763 {764 /* Rounded corners? */765 if (iRadius)766 {767 /* Setup clipping: */768 QPainterPath roundedPath;769 roundedPath.addRoundedRect(pOptions->rect, iRadius, iRadius);770 pPainter->setRenderHint(QPainter::Antialiasing);771 pPainter->setClipPath(roundedPath);772 }773 }774 775 /* static */776 void UIDetailsElement::paintFrameRect(QPainter *pPainter, const QRect &rect, int iRadius)777 {778 pPainter->save();779 QPalette pal = QApplication::palette();780 QColor base = pal.color(QPalette::Active, QPalette::Window);781 pPainter->setPen(base.darker(160));782 if (iRadius)783 pPainter->drawRoundedRect(rect, iRadius, iRadius);784 else785 pPainter->drawRect(rect);786 pPainter->restore();787 }788 789 755 /* static */ 790 756 void UIDetailsElement::paintPixmap(QPainter *pPainter, const QRect &rect, const QPixmap &pixmap) … … 795 761 /* static */ 796 762 void UIDetailsElement::paintText(QPainter *pPainter, QPoint point, 797 const QFont &font, QPaintDevice *pPaintDevice,798 const QString &strText, const QColor &color)763 const QFont &font, QPaintDevice *pPaintDevice, 764 const QString &strText, const QColor &color) 799 765 { 800 766 /* Prepare variables: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.h
r74082 r74083 248 248 void updateIcon(); 249 249 250 /** Returns header darkness. */251 int headerDarkness() const { return m_iHeaderDarkness; }252 253 250 /** Defines animated @a iValue. */ 254 251 void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); } … … 277 274 /** @name Painting stuff. 278 275 * @{ */ 279 /** Paints decorations using specified @a pPainter and certain @a pOptions. */ 280 void paintDecorations(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions); 276 /** Paints background using specified @a pPainter and certain @a pOptions. */ 277 void paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) const; 278 /** Paints frame rectangle using passed @a pPainter and certain @a pOptions. */ 279 void paintFrameRect(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) const; 281 280 /** Paints element info using specified @a pPainter and certain @a pOptions. */ 282 void paintElementInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions); 283 /** Paints background using specified @a pPainter and certain @a pOptions. */ 284 void paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions); 285 286 /** Configures painting shape using passed @a pPainter, @a pOptions and spified @a iRadius. */ 287 static void configurePainterShape(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, int iRadius); 288 /** Paints frame @a rect using passed @a pPainter and spified @a iRadius. */ 289 static void paintFrameRect(QPainter *pPainter, const QRect &rect, int iRadius); 281 void paintElementInfo(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions) const; 282 290 283 /** Paints @a pixmap using passed @a pPainter and spified @a rect. */ 291 284 static void paintPixmap(QPainter *pPainter, const QRect &rect, const QPixmap &pixmap); … … 308 301 QString m_strName; 309 302 310 /** Holds the corner radius. */311 int m_iCornerRadius;312 /** Holds the header darkness. */313 int m_iHeaderDarkness;314 315 303 /** Holds the name font. */ 316 304 QFont m_nameFont; 317 305 /** Holds the text font. */ 318 306 QFont m_textFont; 307 308 /** Holds the start lightness tone. */ 309 int m_iLightnessToneStart; 310 /** Holds the final lightness tone. */ 311 int m_iLightnessToneFinal; 319 312 320 313 /** Holds whether element is hovered. */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsView.cpp
r73424 r74083 182 182 /* Setup palette: */ 183 183 QPalette pal = qApp->palette(); 184 pal.setColor(QPalette::Base, pal.color(QPalette::Active, QPalette::Window)); 184 const QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110); 185 pal.setColor(QPalette::Base, bodyColor); 185 186 setPalette(pal); 186 187 }
Note:
See TracChangeset
for help on using the changeset viewer.