VirtualBox

Changeset 74593 in vbox for trunk


Ignore:
Timestamp:
Oct 3, 2018 12:19:06 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: macOS: Reworking UIToolBar to have possibility to emulate native style.

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

Legend:

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

    r74137 r74593  
    2424# include <QMainWindow>
    2525# include <QResizeEvent>
     26# ifdef VBOX_WS_MAC
     27#  include <QPainter>
     28# endif
    2629
    2730/* GUI includes: */
     
    3740    : QToolBar(pParent)
    3841    , m_pMainWindow(qobject_cast<QMainWindow*>(pParent))
     42#ifdef VBOX_WS_MAC
     43    , m_fEmulateUnifiedToolbar(false)
     44#endif
    3945{
    4046    /* Prepare: */
     
    6268}
    6369
     70void UIToolBar::emulateMacToolbar()
     71{
     72    /* Remember request, to be used in paintEvent: */
     73    m_fEmulateUnifiedToolbar = true;
     74}
     75
    6476void UIToolBar::setShowToolBarButton(bool fShow)
    6577{
     
    7183    // WORKAROUND:
    7284    // There is a bug in Qt Cocoa which result in showing a "more arrow" when
    73     // the necessary size of the toolbar is increased. Also for some languages
     85    // the necessary size of the tool-bar is increased. Also for some languages
    7486    // the with doesn't match if the text increase. So manually adjust the size
    7587    // after changing the text.
     
    92104}
    93105
     106#ifdef VBOX_WS_MAC
     107void UIToolBar::paintEvent(QPaintEvent *pEvent)
     108{
     109    /* Call to base-class: */
     110    QToolBar::paintEvent(pEvent);
     111
     112    /* If we have request to emulate unified tool-bar: */
     113    if (m_fEmulateUnifiedToolbar)
     114    {
     115        /* Acquire rectangle: */
     116        const QRect rectangle = pEvent->rect();
     117
     118        /* Prepare gradient: */
     119        const QColor backgroundColor = palette().color(QPalette::Active, QPalette::Mid);
     120        QLinearGradient gradient(rectangle.topLeft(), rectangle.bottomLeft());
     121        gradient.setColorAt(0,   backgroundColor.lighter(125));
     122        gradient.setColorAt(.65, backgroundColor.lighter(130));
     123        gradient.setColorAt(1,   backgroundColor.lighter(135));
     124
     125        /* Fill background: */
     126        QPainter painter(this);
     127        painter.fillRect(rectangle, gradient);
     128    }
     129}
     130#endif /* VBOX_WS_MAC */
     131
    94132void UIToolBar::prepare()
    95133{
     
    109147    setContextMenuPolicy(Qt::NoContextMenu);
    110148}
    111 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIToolBar.h

    r74137 r74593  
    2727/* Forward declarations: */
    2828class QMainWindow;
     29class QResizeEvent;
     30class QWidget;
     31#ifdef VBOX_WS_MAC
     32class QPaintEvent;
     33#endif
    2934
    30 /** QToolBar extension
    31   * with few settings presets. */
     35/** QToolBar extension with few settings presets. */
    3236class SHARED_LIBRARY_STUFF UIToolBar : public QToolBar
    3337{
     
    4852
    4953#ifdef VBOX_WS_MAC
    50     /** Mac OS X: Defines whether native tool-bar should be used. */
     54    /** Mac OS X: Defines whether native tool-bar should be enabled. */
    5155    void enableMacToolbar();
     56    /** Mac OS X: Defines whether native tool-bar should be emulated. */
     57    void emulateMacToolbar();
     58
    5259    /** Mac OS X: Defines whether native tool-bar button should be shown. */
    5360    void setShowToolBarButton(bool fShow);
    5461    /** Mac OS X: Updates native tool-bar layout. */
    5562    void updateLayout();
    56 #endif /* VBOX_WS_MAC */
     63#endif
    5764
    5865protected:
     
    6067    /** Handles resize @a pEvent. */
    6168    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     69
     70#ifdef VBOX_WS_MAC
     71    /** Handles paint @a pEvent. */
     72    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     73#endif
    6274
    6375private:
     
    6880    /** Holds the parent main-window isntance. */
    6981    QMainWindow *m_pMainWindow;
     82
     83#ifdef VBOX_WS_MAC
     84    /** Holds whether unified tool-bar should be emulated. */
     85    bool  m_fEmulateUnifiedToolbar;
     86#endif
    7087};
    7188
    7289#endif /* !___UIToolBar_h___ */
    73 
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