VirtualBox

Changeset 30087 in vbox for trunk


Ignore:
Timestamp:
Jun 8, 2010 9:43:31 AM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: Make the 1 pixel splitter handle easier to catch by surrounding it
with an invisible snap area.

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

Legend:

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

    r30022 r30087  
    110110#endif /* RT_OS_DARWIN */
    111111
    112 QISplitter::QISplitter(QWidget *aParent /* = 0 */)
    113     : QSplitter(aParent)
    114     , mPolished(false)
     112QISplitter::QISplitter(QWidget *pParent /* = 0 */)
     113    : QSplitter(pParent)
     114    , m_fPolished(false)
    115115    , m_type(Shade)
    116 {
    117     qApp->installEventFilter (this);
     116#ifdef Q_WS_MAC
     117    , m_fHandleGrabbed(false)
     118#endif /* Q_WS_MAC */
     119{
     120    qApp->installEventFilter(this);
    118121}
    119122
    120123QISplitter::QISplitter(Qt::Orientation orientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */)
    121124    : QSplitter(orientation, pParent)
    122     , mPolished(false)
     125    , m_fPolished(false)
    123126    , m_type(Shade)
     127#ifdef Q_WS_MAC
     128    , m_fHandleGrabbed(false)
     129#endif /* Q_WS_MAC */
    124130{
    125131    qApp->installEventFilter (this);
    126132}
    127133
    128 bool QISplitter::eventFilter(QObject *aWatched, QEvent *aEvent)
    129 {
    130     if (aWatched == handle(1))
    131     {
    132         switch (aEvent->type())
     134bool QISplitter::eventFilter(QObject *pWatched, QEvent *pEvent)
     135{
     136    if (pWatched == handle(1))
     137    {
     138        switch (pEvent->type())
    133139        {
    134140            case QEvent::MouseButtonDblClick:
    135                 restoreState (mBaseState);
     141                restoreState(m_baseState);
    136142                break;
    137143            default:
     
    139145        }
    140146    }
    141 
    142     return QSplitter::eventFilter(aWatched, aEvent);
    143 }
    144 
    145 void QISplitter::showEvent(QShowEvent *aEvent)
    146 {
    147     if (!mPolished)
    148     {
    149         mPolished = true;
    150         mBaseState = saveState();
    151     }
    152 
    153     return QSplitter::showEvent(aEvent);
     147#ifdef Q_WS_MAC
     148    /* Special handling on the Mac. Cause there the horizontal handle is only 1
     149     * pixel wide, its hard to catch. Therefor we make some invisible area
     150     * around the handle and forwarding the mouse events to the handle, if the
     151     * user presses the left mouse button. */
     152    else if (   m_type == Native
     153             && orientation() == Qt::Horizontal
     154             && count() > 1
     155             && qApp->activeWindow() == window())
     156    {
     157        switch (pEvent->type())
     158        {
     159            case QEvent::MouseButtonPress:
     160            case QEvent::MouseMove:
     161            {
     162                const int margin = 3;
     163                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);
     164                for (int i=1; i < count(); ++i)
     165                {
     166                    QWidget *pHandle = handle(i);
     167                    if (   pHandle
     168                        && pHandle != pWatched)
     169                    {
     170                        /* Create new mouse event with translated mouse positions. */
     171                        QMouseEvent newME(pMouseEvent->type(),
     172                                          pHandle->mapFromGlobal(pMouseEvent->globalPos()),
     173                                          pMouseEvent->button(),
     174                                          pMouseEvent->buttons(),
     175                                          pMouseEvent->modifiers());
     176                        /* Check if we hit the handle */
     177                        bool fMarginHit = QRect(pHandle->mapToGlobal(QPoint(0, 0)), pHandle->size()).adjusted(-margin, 0, margin, 0).contains(pMouseEvent->globalPos());
     178                        if (pEvent->type() == QEvent::MouseButtonPress)
     179                        {
     180                            /* If we have a handle position hit and the left
     181                             * button is pressed, start the grabbing. */
     182                            if (   fMarginHit
     183                                && pMouseEvent->buttons().testFlag(Qt::LeftButton))
     184                            {
     185                                m_fHandleGrabbed = true;
     186                                setCursor(Qt::SplitHCursor);
     187                                qApp->postEvent(pHandle, new QMouseEvent(newME));
     188                                return true;
     189                            }
     190                        }
     191                        else if(pEvent->type() == QEvent::MouseMove)
     192                        {
     193                            /* If we are in the near of the handle or currently
     194                             * dragging, forward the mouse event. */
     195                            if (   fMarginHit
     196                                || (   m_fHandleGrabbed
     197                                    && pMouseEvent->buttons().testFlag(Qt::LeftButton)))
     198                            {
     199                                setCursor(Qt::SplitHCursor);
     200                                qApp->postEvent(pHandle, new QMouseEvent(newME));
     201                                return true;
     202                            }
     203                            else
     204                            {
     205                                /* If not, reset the state. */
     206                                m_fHandleGrabbed = false;
     207                                setCursor(Qt::ArrowCursor);
     208                            }
     209                        }
     210                    }
     211                }
     212                break;
     213            }
     214            case QEvent::WindowDeactivate:
     215            case QEvent::MouseButtonRelease:
     216            {
     217                m_fHandleGrabbed = false;
     218                setCursor(Qt::ArrowCursor);
     219                break;
     220            }
     221            default:
     222                break;
     223        }
     224    }
     225#endif /* Q_WS_MAC */
     226
     227    return QSplitter::eventFilter(pWatched, pEvent);
     228}
     229
     230void QISplitter::showEvent(QShowEvent *pEvent)
     231{
     232    if (!m_fPolished)
     233    {
     234        m_fPolished = true;
     235        m_baseState = saveState();
     236    }
     237
     238    return QSplitter::showEvent(pEvent);
    154239}
    155240
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.h

    r30022 r30087  
    3131    enum Type { Native, Shade };
    3232
    33     QISplitter(QWidget *aParent = 0);
     33    QISplitter(QWidget *pParent = 0);
    3434    QISplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget *pParent = 0);
    3535
    3636    void setHandleType(Type type) { m_type = type; }
    3737    Type handleType() const { return m_type; }
    38 private:
    3938
    40     bool eventFilter(QObject *aWatched, QEvent *aEvent);
    41     void showEvent(QShowEvent *aEvent);
     39protected:
     40
     41    bool eventFilter(QObject *pWatched, QEvent *pEvent);
     42    void showEvent(QShowEvent *pEvent);
    4243
    4344    QSplitterHandle* createHandle();
    4445
    45     QByteArray mBaseState;
     46private:
    4647
    47     bool mPolished;
     48    QByteArray m_baseState;
     49
     50    bool m_fPolished;
    4851    Type m_type;
     52#ifdef Q_WS_MAC
     53    bool m_fHandleGrabbed;
     54#endif /* Q_WS_MAC */
    4955};
    5056
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