- Timestamp:
- Nov 10, 2017 12:27:15 PM (7 years ago)
- 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 21 21 22 22 /* Qt includes: */ 23 # include <QApplication> 23 24 # include <QPainter> 25 # include <QStyle> 24 26 # include <QGraphicsSceneMouseEvent> 25 27 … … 33 35 : QIGraphicsWidget(pParent) 34 36 , m_icon(icon) 35 , m_buttonType(UIGraphicsButtonType_Iconified)36 37 , m_fParentSelected(false) 37 38 { … … 42 43 UIGraphicsButton::UIGraphicsButton(QIGraphicsWidget *pParent, UIGraphicsButtonType buttonType) 43 44 : QIGraphicsWidget(pParent) 44 , m_buttonType(buttonType)45 45 , m_fParentSelected(false) 46 46 { … … 61 61 switch (iKey) 62 62 { 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; 66 72 default: break; 67 73 } … … 93 99 QSize iconSize = data(GraphicsButton_IconSize).toSize(); 94 100 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)); 178 103 } 179 104 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h
r69500 r69640 87 87 /* Variables: */ 88 88 QIcon m_icon; 89 UIGraphicsButtonType m_buttonType;90 89 bool m_fParentSelected; 91 90 };
Note:
See TracChangeset
for help on using the changeset viewer.