Changeset 94995 in vbox
- Timestamp:
- May 12, 2022 3:04:23 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 151423
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/extensions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIToolBar.cpp
r94985 r94995 23 23 # include <QApplication> 24 24 # include <QPainter> 25 # include <QPainterPath> 25 26 #endif 26 27 … … 37 38 #ifdef VBOX_WS_MAC 38 39 , m_fEmulateUnifiedToolbar(false) 40 , m_iBrandingWidth(0) 39 41 #endif 40 42 { 41 /* Prepare: */42 43 prepare(); 43 44 } … … 88 89 layout()->activate(); 89 90 } 91 92 void QIToolBar::enableBranding(const QIcon &icnBranding, 93 const QString &strBranding, 94 const QColor &clrBranding, 95 int iBrandingWidth) 96 { 97 m_icnBranding = icnBranding; 98 m_strBranding = strBranding; 99 m_clrBranding = clrBranding; 100 m_iBrandingWidth = iBrandingWidth; 101 update(); 102 } 90 103 #endif /* VBOX_WS_MAC */ 91 104 … … 123 136 /* Fill background: */ 124 137 painter.fillRect(rectangle, gradient); 138 139 /* Do we have branding stuff? */ 140 if (!m_icnBranding.isNull()) 141 { 142 /* Configure font to fit width (m_iBrandingWidth - 2 * 4): */ 143 QFont fnt = font(); 144 int iTextWidth = 0; 145 for (int i = 0; i <= 10; ++i) // no more than 10 tries .. 146 { 147 if (fnt.pixelSize() == -1) 148 fnt.setPointSize(fnt.pointSize() - i); 149 else 150 fnt.setPixelSize(fnt.pixelSize() - i); 151 iTextWidth = QFontMetrics(fnt).size(0, m_strBranding).width(); 152 if (iTextWidth <= m_iBrandingWidth - 2 * 4) 153 break; 154 } 155 const int iFontHeight = QFontMetrics(fnt).height(); 156 157 /* Draw pixmap: */ 158 const int iIconSize = qMin(rectangle.height(), 32 /* default */); 159 const int iIconMarginH = (m_iBrandingWidth - iIconSize) / 2; 160 const int iIconMarginV = (rectangle.height() - iIconSize - iFontHeight) / 2; 161 const int iIconX = rectangle.width() - iIconSize - iIconMarginH; 162 const int iIconY = iIconMarginV; 163 painter.drawPixmap(iIconX, iIconY, m_icnBranding.pixmap(QSize(iIconSize, iIconSize))); 164 165 /* Draw text path: */ 166 const int iTextMargingH = (m_iBrandingWidth - iTextWidth) / 2; 167 const int iTextX = rectangle.width() - iTextWidth - iTextMargingH; 168 const int iTextY = iIconY + iIconSize + iFontHeight; 169 QPainterPath textPath; 170 textPath.addText(0, 0, fnt, m_strBranding); 171 textPath.translate(iTextX, iTextY); 172 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); 173 painter.setPen(QPen(m_clrBranding.darker(80), 2, Qt::SolidLine, Qt::RoundCap)); 174 painter.drawPath(QPainterPathStroker().createStroke(textPath)); 175 painter.setBrush(Qt::black); 176 painter.setPen(Qt::NoPen); 177 painter.drawPath(textPath); 178 } 125 179 } 126 180 } -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIToolBar.h
r94985 r94995 24 24 /* Qt includes: */ 25 25 #include <QToolBar> 26 #ifdef VBOX_WS_MAC 27 # include <QColor> 28 # include <QIcon> 29 #endif 26 30 27 31 /* GUI includes: */ … … 64 68 /** Mac OS X: Updates native tool-bar layout. */ 65 69 void updateLayout(); 66 #endif 70 71 /** Mac OS X: Defines branding stuff to be shown. 72 * @param icnBranding Brings branding icon to be shown. 73 * @param strBranding Brings branding text to be shown. 74 * @param clrBranding Brings branding color to be used. 75 * @param iBrandingWidth Holds the branding stuff width. */ 76 void enableBranding(const QIcon &icnBranding, 77 const QString &strBranding, 78 const QColor &clrBranding, 79 int iBrandingWidth); 80 #endif /* VBOX_WS_MAC */ 67 81 68 82 protected: … … 87 101 /** Mac OS X: Holds whether unified tool-bar should be emulated. */ 88 102 bool m_fEmulateUnifiedToolbar; 89 #endif 103 104 /** Mac OS X: Holds branding icon to be shown. */ 105 QIcon m_icnBranding; 106 /** Mac OS X: Holds branding text to be shown. */ 107 QString m_strBranding; 108 /** Mac OS X: Holds branding color to be used. */ 109 QColor m_clrBranding; 110 /** Mac OS X: Holds the branding stuff width. */ 111 int m_iBrandingWidth; 112 #endif /* VBOX_WS_MAC */ 90 113 }; 91 114
Note:
See TracChangeset
for help on using the changeset viewer.