VirtualBox

Changeset 94995 in vbox


Ignore:
Timestamp:
May 12, 2022 3:04:23 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151423
Message:

FE/Qt/Ds: QIToolBar: Possibility to reflect a bit of branding stuff.

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  
    2323# include <QApplication>
    2424# include <QPainter>
     25# include <QPainterPath>
    2526#endif
    2627
     
    3738#ifdef VBOX_WS_MAC
    3839    , m_fEmulateUnifiedToolbar(false)
     40    , m_iBrandingWidth(0)
    3941#endif
    4042{
    41     /* Prepare: */
    4243    prepare();
    4344}
     
    8889    layout()->activate();
    8990}
     91
     92void 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}
    90103#endif /* VBOX_WS_MAC */
    91104
     
    123136        /* Fill background: */
    124137        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        }
    125179    }
    126180}
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIToolBar.h

    r94985 r94995  
    2424/* Qt includes: */
    2525#include <QToolBar>
     26#ifdef VBOX_WS_MAC
     27# include <QColor>
     28# include <QIcon>
     29#endif
    2630
    2731/* GUI includes: */
     
    6468    /** Mac OS X: Updates native tool-bar layout. */
    6569    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 */
    6781
    6882protected:
     
    87101    /** Mac OS X: Holds whether unified tool-bar should be emulated. */
    88102    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 */
    90113};
    91114
Note: See TracChangeset for help on using the changeset viewer.

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