VirtualBox

Changeset 102479 in vbox


Ignore:
Timestamp:
Dec 5, 2023 2:56:51 PM (10 months ago)
Author:
vboxsync
Message:

FE/Qt: Wipe out all the excessive types of QISplitter handles; Also, do not cache palette colors, that simplifies theme support for QISplitter painting procedure.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.cpp

    r102478 r102479  
    4949    QIFlatSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);
    5050
    51     /** Defines @a color. */
    52     void configureColor(const QColor &color);
    53 
    54 protected:
    55 
    56     /** Handles paint @a pEvent. */
    57     virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
    58 
    59 private:
    60 
    61     /** Holds the main color. */
    62     QColor m_color;
    63 };
    64 
    65 
    66 /** QSplitterHandle subclass representing shaded line. */
    67 class QIShadeSplitterHandle : public QSplitterHandle
    68 {
    69     Q_OBJECT;
    70 
    71 public:
    72 
    73     /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */
    74     QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);
    75 
    76     /** Defines colors to passed @a color1 and @a color2. */
    77     void configureColors(const QColor &color1, const QColor &color2);
    78 
    79 protected:
    80 
    81     /** Handles paint @a pEvent. */
    82     virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
    83 
    84 private:
    85 
    86     /** Holds the main color. */
    87     QColor m_color;
    88     /** Holds the color1. */
    89     QColor m_color1;
    90     /** Holds the color2. */
    91     QColor m_color2;
    92 };
    93 
    94 
    95 #ifdef VBOX_WS_MAC
    96 /** QSplitterHandle subclass representing shaded line for macOS. */
    97 class QIDarwinSplitterHandle : public QSplitterHandle
    98 {
    99     Q_OBJECT;
    100 
    101 public:
    102 
    103     /** Constructs shaded splitter handle passing @a enmOrientation and @a pParent to the base-class. */
    104     QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent);
    105 
    106     /** Returns size-hint. */
    107     QSize sizeHint() const;
    108 
    10951protected:
    11052
     
    11254    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
    11355};
    114 #endif /* VBOX_WS_MAC */
    11556
    11657
     
    12465}
    12566
    126 void QIFlatSplitterHandle::configureColor(const QColor &color)
    127 {
    128     m_color = color;
    129     update();
    130 }
    131 
    13267void QIFlatSplitterHandle::paintEvent(QPaintEvent *pEvent)
    13368{
     69    /* Configure painter: */
    13470    QPainter painter(this);
    135     painter.fillRect(pEvent->rect(), m_color);
     71    painter.setClipRect(pEvent->rect());
     72
     73    /* Choose color: */
     74    const bool fActive = window() && window()->isActiveWindow();
     75    QColor clr = QApplication::palette().color(fActive ? QPalette::Active : QPalette::Inactive, QPalette::Window).darker(130);
     76
     77    /* Paint flat rect: */
     78    painter.fillRect(rect(), clr);
    13679}
    137 
    138 
    139 /*********************************************************************************************************************************
    140 *   Class QIShadeSplitterHandle implementation.                                                                                  *
    141 *********************************************************************************************************************************/
    142 
    143 QIShadeSplitterHandle::QIShadeSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent)
    144     : QSplitterHandle(enmOrientation, pParent)
    145 {
    146     QColor windowColor = QApplication::palette().color(QPalette::Active, QPalette::Window);
    147     QColor frameColor = QApplication::palette().color(QPalette::Active, QPalette::Text);
    148     frameColor.setAlpha(100);
    149     m_color1 = windowColor;
    150     m_color2 = windowColor;
    151     m_color = frameColor;
    152 }
    153 
    154 void QIShadeSplitterHandle::configureColors(const QColor &color1, const QColor &color2)
    155 {
    156     m_color1 = color1;
    157     m_color2 = color2;
    158     update();
    159 }
    160 
    161 void QIShadeSplitterHandle::paintEvent(QPaintEvent *pEvent)
    162 {
    163     QPainter painter(this);
    164     QLinearGradient gradient;
    165     QGradientStop point1(0, m_color1);
    166     QGradientStop point2(0.5, m_color);
    167     QGradientStop point3(1, m_color2);
    168     QGradientStops stops;
    169     stops << point1 << point2 << point3;
    170     gradient.setStops(stops);
    171     if (orientation() == Qt::Horizontal)
    172     {
    173         gradient.setStart(rect().left() + 1, 0);
    174         gradient.setFinalStop(rect().right(), 0);
    175     }
    176     else
    177     {
    178         gradient.setStart(0, rect().top() + 1);
    179         gradient.setFinalStop(0, rect().bottom());
    180     }
    181     painter.fillRect(pEvent->rect(), gradient);
    182 }
    183 
    184 
    185 /*********************************************************************************************************************************
    186 *   Class QIDarwinSplitterHandle implementation.                                                                                 *
    187 *********************************************************************************************************************************/
    188 
    189 #ifdef VBOX_WS_MAC
    190 
    191 QIDarwinSplitterHandle::QIDarwinSplitterHandle(Qt::Orientation enmOrientation, QISplitter *pParent)
    192     : QSplitterHandle(enmOrientation, pParent)
    193 {
    194 }
    195 
    196 QSize QIDarwinSplitterHandle::sizeHint() const
    197 {
    198     QSize parent = QSplitterHandle::sizeHint();
    199     if (orientation() == Qt::Vertical)
    200         return parent + QSize(0, 3);
    201     else
    202         return QSize(1, parent.height());
    203 }
    204 
    205 void QIDarwinSplitterHandle::paintEvent(QPaintEvent *)
    206 {
    207     QPainter painter(this);
    208 
    209     QColor topColor(145, 145, 145);
    210     QColor bottomColor(142, 142, 142);
    211     QColor gradientStart(252, 252, 252);
    212     QColor gradientStop(223, 223, 223);
    213 
    214     if (orientation() == Qt::Vertical)
    215     {
    216         painter.setPen(topColor);
    217         painter.drawLine(0, 0, width(), 0);
    218         painter.setPen(bottomColor);
    219         painter.drawLine(0, height() - 1, width(), height() - 1);
    220 
    221         QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height() -3));
    222         linearGrad.setColorAt(0, gradientStart);
    223         linearGrad.setColorAt(1, gradientStop);
    224         painter.fillRect(QRect(QPoint(0,1), size() - QSize(0, 2)), QBrush(linearGrad));
    225     }
    226     else
    227     {
    228         painter.setPen(topColor);
    229         painter.drawLine(0, 0, 0, height());
    230     }
    231 }
    232 
    233 #endif /* VBOX_WS_MAC */
    23480
    23581
     
    24086QISplitter::QISplitter(Qt::Orientation enmOrientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */)
    24187    : QSplitter(enmOrientation, pParent)
    242     , m_enmType(Shade)
    24388    , m_fPolished(false)
    244 #ifdef VBOX_WS_MAC
    245     , m_fHandleGrabbed(false)
    246 #endif
    24789{
    24890    qApp->installEventFilter(this);
    249 }
    250 
    251 QISplitter::QISplitter(Type enmType, Qt::Orientation enmOrientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */)
    252     : QSplitter(enmOrientation, pParent)
    253     , m_enmType(enmType)
    254     , m_fPolished(false)
    255 #ifdef VBOX_WS_MAC
    256     , m_fHandleGrabbed(false)
    257 #endif
    258 {
    259     qApp->installEventFilter(this);
    260 }
    261 
    262 void QISplitter::configureColor(const QColor &color)
    263 {
    264     m_color = color;
    265     for (int i = 1; i < count(); ++i)
    266     {
    267         QIFlatSplitterHandle *pHandle = qobject_cast<QIFlatSplitterHandle*>(handle(i));
    268         if (pHandle && m_color.isValid())
    269             pHandle->configureColor(m_color);
    270     }
    271 }
    272 
    273 void QISplitter::configureColors(const QColor &color1, const QColor &color2)
    274 {
    275     m_color1 = color1; m_color2 = color2;
    276     for (int i = 1; i < count(); ++i)
    277     {
    278         QIShadeSplitterHandle *pHandle = qobject_cast<QIShadeSplitterHandle*>(handle(i));
    279         if (pHandle && m_color1.isValid() && m_color2.isValid())
    280             pHandle->configureColors(m_color1, m_color2);
    281     }
     91    setHandleWidth(1);
    28292}
    28393
     
    297107        }
    298108    }
    299 
    300 #ifdef VBOX_WS_MAC
    301     // WORKAROUND:
    302     // Special handling on the Mac. Cause there the horizontal handle is only 1
    303     // pixel wide, its hard to catch. Therefor we make some invisible area
    304     // around the handle and forwarding the mouse events to the handle, if the
    305     // user presses the left mouse button.
    306     else if (   m_enmType == Native
    307              && orientation() == Qt::Horizontal
    308              && count() > 1
    309              && qApp->activeWindow() == window())
    310     {
    311         switch (pEvent->type())
    312         {
    313             case QEvent::MouseButtonPress:
    314             case QEvent::MouseMove:
    315             {
    316                 const int margin = 3;
    317                 QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);
    318                 const QPoint gPos = pMouseEvent->globalPosition().toPoint();
    319                 for (int i=1; i < count(); ++i)
    320                 {
    321                     QWidget *pHandle = handle(i);
    322                     if (   pHandle
    323                         && pHandle != pWatched)
    324                     {
    325                         /* Check if we hit the handle */
    326                         bool fMarginHit = QRect(pHandle->mapToGlobal(QPoint(0, 0)), pHandle->size()).adjusted(-margin, 0, margin, 0).contains(gPos);
    327                         if (pEvent->type() == QEvent::MouseButtonPress)
    328                         {
    329                             /* If we have a handle position hit and the left button is pressed, start the grabbing. */
    330                             if (   fMarginHit
    331                                 && pMouseEvent->buttons().testFlag(Qt::LeftButton))
    332                             {
    333                                 m_fHandleGrabbed = true;
    334                                 UICursor::setCursor(this, Qt::SplitHCursor);
    335                                 qApp->postEvent(pHandle, new QMouseEvent(pMouseEvent->type(),
    336                                                                          pHandle->mapFromGlobal(gPos),
    337                                                                          pMouseEvent->button(),
    338                                                                          pMouseEvent->buttons(),
    339                                                                          pMouseEvent->modifiers()));
    340                                 return true;
    341                             }
    342                         }
    343                         else if (pEvent->type() == QEvent::MouseMove)
    344                         {
    345                             /* If we are in the near of the handle or currently dragging, forward the mouse event. */
    346                             if (   fMarginHit
    347                                 || (   m_fHandleGrabbed
    348                                     && pMouseEvent->buttons().testFlag(Qt::LeftButton)))
    349                             {
    350                                 UICursor::setCursor(this, Qt::SplitHCursor);
    351                                 qApp->postEvent(pHandle, new QMouseEvent(pMouseEvent->type(),
    352                                                                          pHandle->mapFromGlobal(gPos),
    353                                                                          pMouseEvent->button(),
    354                                                                          pMouseEvent->buttons(),
    355                                                                          pMouseEvent->modifiers()));
    356                                 return true;
    357                             }
    358 
    359                             /* If not, reset the state. */
    360                             m_fHandleGrabbed = false;
    361                             UICursor::setCursor(this, Qt::ArrowCursor);
    362                         }
    363                     }
    364                 }
    365                 break;
    366             }
    367             case QEvent::WindowDeactivate:
    368             case QEvent::MouseButtonRelease:
    369             {
    370                 m_fHandleGrabbed = false;
    371                 UICursor::setCursor(this, Qt::ArrowCursor);
    372                 break;
    373             }
    374             default:
    375                 break;
    376         }
    377     }
    378 #endif /* VBOX_WS_MAC */
    379109
    380110    /* Call to base-class: */
     
    397127QSplitterHandle *QISplitter::createHandle()
    398128{
    399     /* Create native handle: */
    400     switch (m_enmType)
    401     {
    402         case Flat:
    403         {
    404             QIFlatSplitterHandle *pHandle = new QIFlatSplitterHandle(orientation(), this);
    405             if (m_color.isValid())
    406                 pHandle->configureColor(m_color);
    407             return pHandle;
    408         }
    409         case Shade:
    410         {
    411             QIShadeSplitterHandle *pHandle = new QIShadeSplitterHandle(orientation(), this);
    412             if (m_color1.isValid() && m_color2.isValid())
    413                 pHandle->configureColors(m_color1, m_color2);
    414             return pHandle;
    415         }
    416         case Native:
    417         {
    418 #ifdef VBOX_WS_MAC
    419             return new QIDarwinSplitterHandle(orientation(), this);
    420 #else
    421             return new QSplitterHandle(orientation(), this);
    422 #endif
    423         }
    424     }
    425     return 0;
     129    return new QIFlatSplitterHandle(orientation(), this);
    426130}
    427131
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.h

    r102478 r102479  
    4848public:
    4949
    50     /** Handle types. */
    51     enum Type { Flat, Shade, Native };
    52 
    5350    /** Constructs splitter passing @a enmOrientation and @a pParent to the base-class. */
    5451    QISplitter(Qt::Orientation enmOrientation = Qt::Horizontal, QWidget *pParent = 0);
    55     /** Constructs splitter passing @a enmOrientation and @a pParent to the base-class.
    56       * @param  enmType  Brings the splitter handle type. */
    57     QISplitter(Type enmType, Qt::Orientation enmOrientation = Qt::Horizontal, QWidget *pParent = 0);
    58 
    59     /** Configure custom color defined as @a color. */
    60     void configureColor(const QColor &color);
    61     /** Configure custom colors defined as @a color1 and @a color2. */
    62     void configureColors(const QColor &color1, const QColor &color2);
    6352
    6453protected:
     
    6857
    6958    /** Handles show @a pEvent. */
    70     void showEvent(QShowEvent *pEvent);
     59    virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
    7160
    72     /** Creates handle. */
    73     QSplitterHandle *createHandle();
     61    /** Creates a handle. */
     62    virtual QSplitterHandle *createHandle() RT_OVERRIDE;
    7463
    7564private:
    7665
    7766    /** Holds the serialized base-state. */
    78     QByteArray m_baseState;
    79 
    80     /** Holds the handle type. */
    81     Type m_enmType;
     67    QByteArray  m_baseState;
    8268
    8369    /** Holds whether the splitter is polished. */
    84     bool m_fPolished : 1;
    85 #ifdef VBOX_WS_MAC
    86     /** Holds whether handle is grabbed. */
    87     bool m_fHandleGrabbed : 1;
    88 #endif
     70    bool  m_fPolished;
    8971
    90     /** Holds color. */
    91     QColor m_color;
    92     /** Holds color1. */
    93     QColor m_color1;
    94     /** Holds color2. */
    95     QColor m_color2;
     72    /** Holds the handle color. */
     73    QColor  m_color;
    9674};
    9775
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp

    r102478 r102479  
    652652
    653653        /* Create splitter: */
    654         m_pSplitter = new QISplitter(QISplitter::Flat);
     654        m_pSplitter = new QISplitter;
    655655        if (m_pSplitter)
    656656        {
    657             /* Configure splitter: */
    658             m_pSplitter->setHandleWidth(1);
    659 
    660657            /* Create Chooser-pane: */
    661658            m_pPaneChooser = new UIChooser(this, actionPool());
     
    768765            }
    769766
    770             /* Adjust splitter colors according to main widgets it splits: */
    771             m_pSplitter->configureColor(QApplication::palette().color(QPalette::Active, QPalette::Window).darker(130));
    772767            /* Set the initial distribution. The right site is bigger. */
    773768            m_pSplitter->setStretchFactor(0, 2);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIStorageSettingsEditor.cpp

    r102478 r102479  
    43874387        pLayout->setContentsMargins(0, 0, 0, 0);
    43884388
    4389         /* Create splitter: */
     4389        /* Prepare splitter: */
    43904390        m_pSplitter = new QISplitter;
    43914391        if (m_pSplitter)
    43924392        {
    43934393            m_pSplitter->setChildrenCollapsible(false);
    4394             m_pSplitter->setOrientation(Qt::Horizontal);
    4395             m_pSplitter->setHandleWidth(4);
    43964394
    43974395            /* Prepare panes: */
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