VirtualBox

Changeset 69640 in vbox for trunk


Ignore:
Timestamp:
Nov 10, 2017 12:27:15 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8694: Selector UI: HiDPI support for graphics-button used in chooser/details; also a bit of cleanup there.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.cpp

    r69500 r69640  
    2121
    2222/* Qt includes: */
     23# include <QApplication>
    2324# include <QPainter>
     25# include <QStyle>
    2426# include <QGraphicsSceneMouseEvent>
    2527
     
    3335    : QIGraphicsWidget(pParent)
    3436    , m_icon(icon)
    35     , m_buttonType(UIGraphicsButtonType_Iconified)
    3637    , m_fParentSelected(false)
    3738{
     
    4243UIGraphicsButton::UIGraphicsButton(QIGraphicsWidget *pParent, UIGraphicsButtonType buttonType)
    4344    : QIGraphicsWidget(pParent)
    44     , m_buttonType(buttonType)
    4545    , m_fParentSelected(false)
    4646{
     
    6161    switch (iKey)
    6262    {
    63         case GraphicsButton_Margin: return 0;
    64         case GraphicsButton_IconSize: return m_icon.isNull() ? QSize(16, 16) : m_icon.availableSizes().first();
    65         case GraphicsButton_Icon: return m_icon;
     63        case GraphicsButton_Margin:
     64            return 0;
     65        case GraphicsButton_IconSize:
     66        {
     67            const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     68            return QSize(iMetric, iMetric);
     69        }
     70        case GraphicsButton_Icon:
     71            return m_icon;
    6672        default: break;
    6773    }
     
    9399    QSize iconSize = data(GraphicsButton_IconSize).toSize();
    94100
    95     /* Which type button has: */
    96     switch (m_buttonType)
    97     {
    98         case UIGraphicsButtonType_Iconified:
    99         {
    100             /* Just draw the pixmap: */
    101             pPainter->drawPixmap(QRect(QPoint(iMargin, iMargin), iconSize), icon.pixmap(iconSize));
    102             break;
    103         }
    104         case UIGraphicsButtonType_DirectArrow:
    105         {
    106             /* Prepare variables: */
    107             QPalette pal = palette();
    108             QColor buttonColor = pal.color(m_fParentSelected ? QPalette::HighlightedText : QPalette::Mid);
    109 #ifdef VBOX_WS_MAC
    110             /* Mac is using only light standard highlight colors, keeping highlight-text color always black.
    111              * User can choose a darker (non-standard) highlight color but it will be his visibility problem.
    112              * I think using highlight-text color (black) for arrow-buttons is too ugly,
    113              * so the corresponding color will be received from the highlight color: */
    114             if (m_fParentSelected)
    115                 buttonColor = pal.color(QPalette::Highlight).darker(150);
    116 #endif /* VBOX_WS_MAC */
    117 
    118             /* Setup: */
    119             pPainter->setRenderHint(QPainter::Antialiasing);
    120             QPen pen = pPainter->pen();
    121             pen.setColor(buttonColor);
    122             pen.setWidth(2);
    123             pen.setCapStyle(Qt::RoundCap);
    124 
    125             /* Draw path: */
    126             QPainterPath circlePath;
    127             circlePath.moveTo(iMargin, iMargin);
    128             circlePath.lineTo(iMargin + iconSize.width() / 2, iMargin);
    129             circlePath.arcTo(QRectF(circlePath.currentPosition(), iconSize).translated(-iconSize.width() / 2, 0), 90, -180);
    130             circlePath.lineTo(iMargin, iMargin + iconSize.height());
    131             circlePath.closeSubpath();
    132             pPainter->strokePath(circlePath, pen);
    133 
    134             /* Draw triangle: */
    135             QPainterPath linePath;
    136             linePath.moveTo(iMargin + 5, iMargin + 5);
    137             linePath.lineTo(iMargin + iconSize.height() - 5, iMargin + iconSize.width() / 2);
    138             linePath.lineTo(iMargin + 5, iMargin + iconSize.width() - 5);
    139             pPainter->strokePath(linePath, pen);
    140             break;
    141         }
    142         case UIGraphicsButtonType_RoundArrow:
    143         {
    144             /* Prepare variables: */
    145             QPalette pal = palette();
    146             QColor buttonColor = pal.color(m_fParentSelected ? QPalette::HighlightedText : QPalette::Mid);
    147 #ifdef VBOX_WS_MAC
    148             /* Mac is using only light standard highlight colors, keeping highlight-text color always black.
    149              * User can choose a darker (non-standard) highlight color but it will be his visibility problem.
    150              * I think using highlight-text color (black) for arrow-buttons is too ugly,
    151              * so the corresponding color will be received from the highlight color: */
    152             if (m_fParentSelected)
    153                 buttonColor = pal.color(QPalette::Highlight).darker(150);
    154 #endif /* VBOX_WS_MAC */
    155 
    156             /* Setup: */
    157             pPainter->setRenderHint(QPainter::Antialiasing);
    158             QPen pen = pPainter->pen();
    159             pen.setColor(buttonColor);
    160             pen.setWidth(2);
    161             pen.setCapStyle(Qt::RoundCap);
    162 
    163             /* Draw circle: */
    164             QPainterPath circlePath;
    165             circlePath.moveTo(iMargin, iMargin);
    166             circlePath.addEllipse(QRectF(circlePath.currentPosition(), iconSize));
    167             pPainter->strokePath(circlePath, pen);
    168 
    169             /* Draw triangle: */
    170             QPainterPath linePath;
    171             linePath.moveTo(iMargin + 5, iMargin + 5);
    172             linePath.lineTo(iMargin + iconSize.height() - 5, iMargin + iconSize.width() / 2);
    173             linePath.lineTo(iMargin + 5, iMargin + iconSize.width() - 5);
    174             pPainter->strokePath(linePath, pen);
    175             break;
    176         }
    177     }
     101    /* Just draw the pixmap: */
     102    pPainter->drawPixmap(QRect(QPoint(iMargin, iMargin), iconSize), icon.pixmap(iconSize));
    178103}
    179104
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h

    r69500 r69640  
    8787    /* Variables: */
    8888    QIcon m_icon;
    89     UIGraphicsButtonType m_buttonType;
    9089    bool m_fParentSelected;
    9190};
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette