VirtualBox

Changeset 29083 in vbox


Ignore:
Timestamp:
May 5, 2010 1:55:28 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt: 3948: Mini-ToolBar for Full-screen & Seamless modes should now have correct positioning and mouse-hovering.

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

Legend:

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

    r29061 r29083  
    77
    88/*
    9  * Copyright (C) 2009 Oracle Corporation
     9 * Copyright (C) 2009-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 /* VBox includes */
    21 #include "VBoxGlobal.h"
    22 #include "VBoxMiniToolBar.h"
    23 
    24 /* Qt includes */
     20/* Global includes */
    2521#include <QCursor>
    2622#include <QDesktopWidget>
     
    3531#include <QToolButton>
    3632
    37 VBoxMiniToolBar::VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment, bool aActive, bool aAutoHide)
    38     : VBoxToolBar (aParent)
    39     , mActive (aActive)
    40     , mPolished (false)
    41     , mSeamless (false)
    42     , mAutoHide (aAutoHide)
    43     , mSlideToScreen (true)
    44     , mHideAfterSlide (false)
    45     , mAutoHideCounter (0)
    46     , mAlignment (aAlignment)
    47     , mAnimated (true)
    48     , mScrollDelay (10)
    49     , mAutoScrollDelay (100)
    50     , mAutoHideTotalCounter (10)
    51 {
    52     AssertMsg (parentWidget(), ("Parent widget must be set!!!\n"));
    53 
    54     /* Various options */
    55     setIconSize (QSize (16, 16));
    56     setMouseTracking (mAutoHide);
    57     setVisible (false);
    58 
    59     /* Left margin of tool-bar */
    60     mMargins << widgetForAction (addWidget (new QWidget (this)));
    61 
    62     /* Add pushpin */
    63     mAutoHideAct = new QAction (this);
    64     mAutoHideAct->setIcon (VBoxGlobal::iconSet (":/pin_16px.png"));
    65     mAutoHideAct->setToolTip (tr ("Always show the toolbar"));
    66     mAutoHideAct->setCheckable (true);
    67     mAutoHideAct->setChecked (!mAutoHide);
    68     connect (mAutoHideAct, SIGNAL (toggled (bool)), this, SLOT (togglePushpin (bool)));
    69     addAction (mAutoHideAct);
    70 
    71     /* Left menu margin */
    72     mSpacings << widgetForAction (addWidget (new QWidget (this)));
    73 
    74     /* Right menu margin */
    75     mInsertPosition = addWidget (new QWidget (this));
    76     mSpacings << widgetForAction (mInsertPosition);
    77 
    78     /* Left label margin */
    79     mLabelMargins << widgetForAction (addWidget (new QWidget (this)));
    80 
    81     /* Insert a label for VM Name */
    82     mDisplayLabel = new QLabel (this);
    83     mDisplayLabel->setAlignment (Qt::AlignCenter);
    84     addWidget (mDisplayLabel);
    85 
    86     /* Right label margin */
    87     mLabelMargins << widgetForAction (addWidget (new QWidget (this)));
    88 
    89     /* Exit action */
    90     QAction *restoreAct = new QAction (this);
    91     restoreAct->setIcon (VBoxGlobal::iconSet (":/restore_16px.png"));
    92     restoreAct->setToolTip (tr ("Exit Full Screen or Seamless Mode"));
    93     connect (restoreAct, SIGNAL (triggered()), this, SIGNAL (exitAction()));
    94     addAction (restoreAct);
    95 
    96     /* Close action */
    97     QAction *closeAct = new QAction (this);
    98     closeAct->setIcon (VBoxGlobal::iconSet (":/close_16px.png"));
    99     closeAct->setToolTip (tr ("Close VM"));
    100     connect (closeAct, SIGNAL (triggered()), this, SIGNAL (closeAction()));
    101     addAction (closeAct);
    102 
    103     /* Right margin of tool-bar */
    104     mMargins << widgetForAction (addWidget (new QWidget (this)));
    105 
    106     aParent->installEventFilter(this);
    107 }
    108 
    109 VBoxMiniToolBar& VBoxMiniToolBar::operator<< (QList <QMenu*> aMenus)
    110 {
    111     for (int i = 0; i < aMenus.size(); ++ i)
    112     {
    113         QAction *action = aMenus [i]->menuAction();
    114         insertAction (mInsertPosition, action);
    115         if (QToolButton *button = qobject_cast <QToolButton*> (widgetForAction (action)))
    116         {
    117             button->setPopupMode (QToolButton::InstantPopup);
    118             button->setAutoRaise (true);
    119         }
    120         if (i != aMenus.size() - 1)
    121             mSpacings << widgetForAction (insertWidget (mInsertPosition, new QWidget (this)));
     33/* Local includes */
     34#include "VBoxMiniToolBar.h"
     35#include "VBoxGlobal.h"
     36
     37/* Mini-toolbar constructor */
     38VBoxMiniToolBar::VBoxMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide)
     39    : VBoxToolBar(pParent)
     40    , m_pAutoHideAction(0)
     41    , m_pDisplayLabel(0)
     42    , m_pRestoreAction(0)
     43    , m_pCloseAction(0)
     44    , m_fActive(fActive)
     45    , m_fPolished(false)
     46    , m_fSeamless(false)
     47    , m_fAutoHide(fAutoHide)
     48    , m_fSlideToScreen(true)
     49    , m_fHideAfterSlide(false)
     50    , m_iAutoHideCounter(0)
     51    , m_iPositionX(0)
     52    , m_iPositionY(0)
     53    , m_pInsertPosition(0)
     54    , m_alignment(alignment)
     55    , m_fAnimated(true)
     56    , m_iScrollDelay(10)
     57    , m_iAutoScrollDelay(100)
     58    , m_iAutoHideTotalCounter(10)
     59{
     60    /* Check parent widget presence: */
     61    AssertMsg(parentWidget(), ("Parent widget must be set!\n"));
     62
     63    /* Toolbar options: */
     64    setIconSize(QSize(16, 16));
     65    setVisible(false);
     66
     67    /* Left margin of tool-bar: */
     68    m_Margins << widgetForAction(addWidget(new QWidget(this)));
     69
     70    /* Add pushpin: */
     71    m_pAutoHideAction = new QAction(this);
     72    m_pAutoHideAction->setIcon(VBoxGlobal::iconSet(":/pin_16px.png"));
     73    m_pAutoHideAction->setToolTip(tr("Always show the toolbar"));
     74    m_pAutoHideAction->setCheckable(true);
     75    m_pAutoHideAction->setChecked(!m_fAutoHide);
     76    connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SLOT(togglePushpin(bool)));
     77    addAction(m_pAutoHideAction);
     78
     79    /* Left menu margin: */
     80    m_Spacings << widgetForAction(addWidget(new QWidget(this)));
     81
     82    /* Right menu margin: */
     83    m_pInsertPosition = addWidget(new QWidget(this));
     84    m_Spacings << widgetForAction(m_pInsertPosition);
     85
     86    /* Left label margin: */
     87    m_LabelMargins << widgetForAction(addWidget(new QWidget(this)));
     88
     89    /* Insert a label for VM Name: */
     90    m_pDisplayLabel = new QLabel(this);
     91    m_pDisplayLabel->setAlignment(Qt::AlignCenter);
     92    addWidget(m_pDisplayLabel);
     93
     94    /* Right label margin: */
     95    m_LabelMargins << widgetForAction(addWidget(new QWidget(this)));
     96
     97    /* Exit action: */
     98    m_pRestoreAction = new QAction(this);
     99    m_pRestoreAction->setIcon(VBoxGlobal::iconSet(":/restore_16px.png"));
     100    m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode"));
     101    connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(exitAction()));
     102    addAction(m_pRestoreAction);
     103
     104    /* Close action: */
     105    m_pCloseAction = new QAction(this);
     106    m_pCloseAction->setIcon(VBoxGlobal::iconSet(":/close_16px.png"));
     107    m_pCloseAction->setToolTip(tr("Close VM"));
     108    connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(closeAction()));
     109    addAction(m_pCloseAction);
     110
     111    /* Right margin of tool-bar: */
     112    m_Margins << widgetForAction(addWidget(new QWidget(this)));
     113
     114    /* Event-filter for parent widget to control resize: */
     115    pParent->installEventFilter(this);
     116
     117    /* Enable mouse-tracking for this & children allowing to get mouse-move events: */
     118    setMouseTrackingEnabled(m_fAutoHide);
     119}
     120
     121/* Appends passed menus into internal menu-list */
     122VBoxMiniToolBar& VBoxMiniToolBar::operator<<(QList<QMenu*> menus)
     123{
     124    for (int i = 0; i < menus.size(); ++i)
     125    {
     126        QAction *pAction = menus[i]->menuAction();
     127        insertAction(m_pInsertPosition, pAction);
     128        if (QToolButton *pButton = qobject_cast<QToolButton*>(widgetForAction(pAction)))
     129        {
     130            pButton->setPopupMode(QToolButton::InstantPopup);
     131            pButton->setAutoRaise(true);
     132        }
     133        if (i != menus.size() - 1)
     134            m_Spacings << widgetForAction(insertWidget(m_pInsertPosition, new QWidget(this)));
    122135    }
    123136    return *this;
    124137}
    125138
    126 void VBoxMiniToolBar::setSeamlessMode (bool aSeamless)
    127 {
    128     mSeamless = aSeamless;
     139/* Seamless mode setter */
     140void VBoxMiniToolBar::setSeamlessMode(bool fSeamless)
     141{
     142    m_fSeamless = fSeamless;
    129143}
    130144
    131145/* Update the display text, usually the VM Name */
    132 void VBoxMiniToolBar::setDisplayText (const QString &aText)
    133 {
    134     if (mDisplayLabel->text() != aText)
    135     {
    136         /* Update toolbar label */
    137         mDisplayLabel->setText (aText);
    138 
    139         /* Reinitialize */
     146void VBoxMiniToolBar::setDisplayText(const QString &strText)
     147{
     148    /* If text was really changed: */
     149    if (m_pDisplayLabel->text() != strText)
     150    {
     151        /* Update toolbar label: */
     152        m_pDisplayLabel->setText(strText);
     153
     154        /* Reinitialize: */
    140155        initialize();
    141156
     157        /* Update toolbar if its not hidden: */
    142158        if (!isHidden())
    143             updateDisplay (!mAutoHide, false);
    144     }
    145 }
    146 
     159            updateDisplay(!m_fAutoHide, false);
     160    }
     161}
     162
     163/* Is auto-hide feature enabled? */
    147164bool VBoxMiniToolBar::isAutoHide() const
    148165{
    149     return mAutoHide;
    150 }
    151 
    152 void VBoxMiniToolBar::updateDisplay (bool aShow, bool aSetHideFlag)
    153 {
    154     mAutoHideCounter = 0;
    155 
    156     setMouseTracking (mAutoHide);
    157 
    158     if (aShow)
     166    return m_fAutoHide;
     167}
     168
     169void VBoxMiniToolBar::updateDisplay(bool fShow, bool fSetHideFlag)
     170{
     171    m_iAutoHideCounter = 0;
     172
     173    setMouseTrackingEnabled(m_fAutoHide);
     174
     175    if (fShow)
    159176    {
    160177        if (isHidden())
    161178            moveToBase();
    162179
    163         if (mAnimated)
    164         {
    165             if (aSetHideFlag)
     180        if (m_fAnimated)
     181        {
     182            if (fSetHideFlag)
    166183            {
    167                 mHideAfterSlide = false;
    168                 mSlideToScreen = true;
     184                m_fHideAfterSlide = false;
     185                m_fSlideToScreen = true;
    169186            }
    170             if (mActive) show();
    171             mScrollTimer.start (mScrollDelay, this);
    172         }
    173         else if (mActive) show();
    174 
    175         if (mAutoHide)
    176             mAutoScrollTimer.start (mAutoScrollDelay, this);
     187            if (m_fActive)
     188                show();
     189            m_scrollTimer.start(m_iScrollDelay, this);
     190        }
     191        else if (m_fActive)
     192            show();
     193
     194        if (m_fAutoHide)
     195            m_autoScrollTimer.start(m_iAutoScrollDelay, this);
    177196        else
    178             mAutoScrollTimer.stop();
     197            m_autoScrollTimer.stop();
    179198    }
    180199    else
    181200    {
    182         if (mAnimated)
    183         {
    184             if (aSetHideFlag)
     201        if (m_fAnimated)
     202        {
     203            if (fSetHideFlag)
    185204            {
    186                 mHideAfterSlide = true;
    187                 mSlideToScreen = false;
     205                m_fHideAfterSlide = true;
     206                m_fSlideToScreen = false;
    188207            }
    189             mScrollTimer.start (mScrollDelay, this);
     208            m_scrollTimer.start(m_iScrollDelay, this);
    190209        }
    191210        else
    192211            hide();
    193212
    194         if (mAutoHide)
    195             mAutoScrollTimer.start (mAutoScrollDelay, this);
     213        if (m_fAutoHide)
     214            m_autoScrollTimer.start(m_iAutoScrollDelay, this);
    196215        else
    197             mAutoScrollTimer.stop();
    198     }
    199 }
    200 
    201 void VBoxMiniToolBar::mouseMoveEvent (QMouseEvent *aEvent)
    202 {
    203     if (!mHideAfterSlide)
    204     {
    205         mSlideToScreen = true;
    206         mScrollTimer.start (mScrollDelay, this);
    207     }
    208 
    209     QToolBar::mouseMoveEvent (aEvent);
    210 }
    211 
    212 /* Handles auto hide feature of the toolbar */
    213 void VBoxMiniToolBar::timerEvent (QTimerEvent *aEvent)
    214 {
    215     if (aEvent->timerId() == mScrollTimer.timerId())
    216     {
    217         QRect screen = mSeamless ? vboxGlobal().availableGeometry (QApplication::desktop()->screenNumber(window())) :
    218                                    QApplication::desktop()->screenGeometry (window());
    219         switch (mAlignment)
     216            m_autoScrollTimer.stop();
     217    }
     218}
     219
     220/* Parent widget event-filter */
     221bool VBoxMiniToolBar::eventFilter(QObject *pObject, QEvent *pEvent)
     222{
     223    /* If parent widget was resized: */
     224    if (pObject == parent() && pEvent->type() == QEvent::Resize)
     225    {
     226        /* Update toolbar position: */
     227        moveToBase();
     228        return true;
     229    }
     230    /* Base-class event-filter: */
     231    return VBoxToolBar::eventFilter(pObject, pEvent);
     232}
     233
     234/* Mouse-move event processor */
     235void VBoxMiniToolBar::mouseMoveEvent(QMouseEvent *pEvent)
     236{
     237    /* Activate sliding animation on mouse move: */
     238    if (!m_fHideAfterSlide)
     239    {
     240        m_fSlideToScreen = true;
     241        m_scrollTimer.start(m_iScrollDelay, this);
     242    }
     243    /* Base-class mouse-move event processing: */
     244    VBoxToolBar::mouseMoveEvent(pEvent);
     245}
     246
     247/* Timer event processor
     248 * Handles auto hide feature of the toolbar */
     249void VBoxMiniToolBar::timerEvent(QTimerEvent *pEvent)
     250{
     251    if (pEvent->timerId() == m_scrollTimer.timerId())
     252    {
     253        QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) :
     254                                     QApplication::desktop()->screenGeometry(window());
     255        switch (m_alignment)
    220256        {
    221257            case AlignTop:
    222258            {
    223                 if (((mPositionY == screen.y()) && mSlideToScreen) ||
    224                     ((mPositionY == screen.y() - height() + 1) && !mSlideToScreen))
     259                if (((m_iPositionY == screen.y()) && m_fSlideToScreen) ||
     260                    ((m_iPositionY == screen.y() - height() + 1) && !m_fSlideToScreen))
    225261                {
    226                     mScrollTimer.stop();
    227                     if (mHideAfterSlide)
     262                    m_scrollTimer.stop();
     263                    if (m_fHideAfterSlide)
    228264                    {
    229                         mHideAfterSlide = false;
     265                        m_fHideAfterSlide = false;
    230266                        hide();
    231267                    }
    232268                    return;
    233269                }
    234                 mSlideToScreen ? ++ mPositionY : -- mPositionY;
     270                m_fSlideToScreen ? ++m_iPositionY : --m_iPositionY;
    235271                break;
    236272            }
    237273            case AlignBottom:
    238274            {
    239                 if (((mPositionY == screen.y() + screen.height() - height()) && mSlideToScreen) ||
    240                     ((mPositionY == screen.y() + screen.height() - 1) && !mSlideToScreen))
     275                if (((m_iPositionY == screen.y() + screen.height() - height()) && m_fSlideToScreen) ||
     276                    ((m_iPositionY == screen.y() + screen.height() - 1) && !m_fSlideToScreen))
    241277                {
    242                     mScrollTimer.stop();
    243                     if (mHideAfterSlide)
     278                    m_scrollTimer.stop();
     279                    if (m_fHideAfterSlide)
    244280                    {
    245                         mHideAfterSlide = false;
     281                        m_fHideAfterSlide = false;
    246282                        hide();
    247283                    }
    248284                    return;
    249285                }
    250                 mSlideToScreen ? -- mPositionY : ++ mPositionY;
     286                m_fSlideToScreen ? --m_iPositionY : ++m_iPositionY;
    251287                break;
    252288            }
     
    254290                break;
    255291        }
    256         move (mapFromScreen (QPoint (mPositionX, mPositionY)));
     292        move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY)));
    257293        emit geometryUpdated();
    258294    }
    259     else if (aEvent->timerId() == mAutoScrollTimer.timerId())
     295    else if (pEvent->timerId() == m_autoScrollTimer.timerId())
    260296    {
    261297        QRect rect = this->rect();
    262         QPoint cursor_pos = QCursor::pos();
    263         QPoint p = mapFromGlobal (cursor_pos);
    264 
    265         if (!rect.contains (p))
    266         {
    267             ++ mAutoHideCounter;
    268 
    269             if (mAutoHideCounter == mAutoHideTotalCounter)
     298        QPoint p = mapFromGlobal(QCursor::pos());
     299        if (!rect.contains(p))
     300        {
     301            ++m_iAutoHideCounter;
     302
     303            if (m_iAutoHideCounter == m_iAutoHideTotalCounter)
    270304            {
    271                 mSlideToScreen = false;
    272                 mScrollTimer.start (mScrollDelay, this);
     305                m_fSlideToScreen = false;
     306                m_scrollTimer.start(m_iScrollDelay, this);
    273307            }
    274308        }
    275309        else
    276             mAutoHideCounter = 0;
     310            m_iAutoHideCounter = 0;
    277311    }
    278312    else
    279         QWidget::timerEvent (aEvent);
    280 }
    281 
    282 void VBoxMiniToolBar::showEvent (QShowEvent *aEvent)
    283 {
    284     if (!mPolished)
    285     {
    286         /* Tool-bar margins */
    287         foreach (QWidget *margin, mMargins)
    288             margin->setMinimumWidth (height());
    289 
    290         /* Tool-bar spacings */
    291         foreach (QWidget *spacing, mSpacings)
    292             spacing->setMinimumWidth (5);
    293 
    294         /* Title spacings */
    295         foreach (QWidget *lableMargin, mLabelMargins)
    296             lableMargin->setMinimumWidth (15);
    297 
    298         /* Initialize */
     313        QWidget::timerEvent(pEvent);
     314}
     315
     316/* Show event processor */
     317void VBoxMiniToolBar::showEvent(QShowEvent *pEvent)
     318{
     319    if (!m_fPolished)
     320    {
     321        /* Tool-bar margins: */
     322        foreach(QWidget *pMargin, m_Margins)
     323            pMargin->setMinimumWidth(height());
     324
     325        /* Tool-bar spacings: */
     326        foreach(QWidget *pSpacing, m_Spacings)
     327            pSpacing->setMinimumWidth(5);
     328
     329        /* Title spacings: */
     330        foreach(QWidget *pLableMargin, m_LabelMargins)
     331            pLableMargin->setMinimumWidth(15);
     332
     333        /* Initialize: */
    299334        initialize();
    300335
    301         mPolished = true;
    302     }
    303 
    304     VBoxToolBar::showEvent (aEvent);
    305 }
    306 
    307 void VBoxMiniToolBar::paintEvent (QPaintEvent *aEvent)
    308 {
     336        m_fPolished = true;
     337    }
     338    /* Base-class show event processing: */
     339    VBoxToolBar::showEvent(pEvent);
     340}
     341
     342/* Show event processor */
     343void VBoxMiniToolBar::paintEvent(QPaintEvent *pEvent)
     344{
     345    /* Paint background */
    309346    QPainter painter;
    310     painter.begin (this);
    311     painter.fillRect (aEvent->rect(), palette().brush (QPalette::Window));
     347    painter.begin(this);
     348    painter.fillRect(pEvent->rect(), palette().brush(QPalette::Window));
    312349    painter.end();
    313     VBoxToolBar::paintEvent (aEvent);
    314 }
    315 
    316 void VBoxMiniToolBar::togglePushpin (bool aOn)
    317 {
    318     mAutoHide = !aOn;
    319     updateDisplay (!mAutoHide, false);
    320 }
    321 
     350    /* Base-class paint event processing: */
     351    VBoxToolBar::paintEvent(pEvent);
     352}
     353
     354/* Toggle push-pin */
     355void VBoxMiniToolBar::togglePushpin(bool fOn)
     356{
     357    m_fAutoHide = !fOn;
     358    updateDisplay(!m_fAutoHide, false);
     359}
     360
     361/* Initialize mini-toolbar */
    322362void VBoxMiniToolBar::initialize()
    323363{
    324     /* Resize to sizehint */
    325     resize (sizeHint());
    326 
    327     /* Update geometry */
     364    /* Resize to sizehint: */
     365    resize(sizeHint());
     366
     367    /* Update geometry: */
    328368    recreateMask();
    329369    moveToBase();
    330370}
    331371
     372/* Recreate mini-toolbar mask */
    332373void VBoxMiniToolBar::recreateMask()
    333374{
    334     int edgeShift = height();
    335     int points [8];
    336     switch (mAlignment)
     375    int iEdgeShift = height();
     376    int iPoints[8];
     377    switch (m_alignment)
    337378    {
    338379        case AlignTop:
    339380        {
    340             points [0] = 0;
    341             points [1] = 0;
    342 
    343             points [2] = edgeShift;
    344             points [3] = height();
    345 
    346             points [4] = width() - edgeShift;
    347             points [5] = height();
    348 
    349             points [6] = width();
    350             points [7] = 0;
     381            iPoints[0] = 0;
     382            iPoints[1] = 0;
     383
     384            iPoints[2] = iEdgeShift;
     385            iPoints[3] = height();
     386
     387            iPoints[4] = width() - iEdgeShift;
     388            iPoints[5] = height();
     389
     390            iPoints[6] = width();
     391            iPoints[7] = 0;
    351392
    352393            break;
     
    354395        case AlignBottom:
    355396        {
    356             points [0] = edgeShift;
    357             points [1] = 0;
    358 
    359             points [2] = 0;
    360             points [3] = height();
    361 
    362             points [4] = width();
    363             points [5] = height();
    364 
    365             points [6] = width() - edgeShift;
    366             points [7] = 0;
     397            iPoints[0] = iEdgeShift;
     398            iPoints[1] = 0;
     399
     400            iPoints[2] = 0;
     401            iPoints[3] = height();
     402
     403            iPoints[4] = width();
     404            iPoints[5] = height();
     405
     406            iPoints[6] = width() - iEdgeShift;
     407            iPoints[7] = 0;
    367408
    368409            break;
     
    371412            break;
    372413    }
    373     /* Make sure any old mask is removed first */
     414    /* Make sure any old mask is removed first: */
    374415    clearMask();
    375416    /* Set the new mask */
    376417    QPolygon polygon;
    377     polygon.setPoints (4, points);
    378     setMask (polygon);
    379 }
    380 
     418    polygon.setPoints(4, iPoints);
     419    setMask(polygon);
     420}
     421
     422/* Move mini-toolbar to the base location */
    381423void VBoxMiniToolBar::moveToBase()
    382424{
    383     QRect screen = mSeamless ? vboxGlobal().availableGeometry (QApplication::desktop()->screenNumber(window())) :
    384                                QApplication::desktop()->screenGeometry (window());
    385     mPositionX = screen.x() + screen.width() / 2 - width() / 2;
    386     switch (mAlignment)
     425    QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) :
     426                                 QApplication::desktop()->screenGeometry(window());
     427    m_iPositionX = screen.x() + (screen.width() / 2) - (width() / 2);
     428    switch (m_alignment)
    387429    {
    388430        case AlignTop:
    389431        {
    390             mPositionY = screen.y() - height() + 1;
     432            m_iPositionY = screen.y() - height() + 1;
    391433            break;
    392434        }
    393435        case AlignBottom:
    394436        {
    395             mPositionY = screen.y() + screen.height() - 1;
     437            m_iPositionY = screen.y() + screen.height() - 1;
    396438            break;
    397439        }
    398440        default:
    399441        {
    400             mPositionY = 0;
    401             break;
    402         }
    403     }
    404     move(mapFromScreen (QPoint (mPositionX, mPositionY)));
    405 }
    406 
    407 QPoint VBoxMiniToolBar::mapFromScreen (const QPoint &aPoint)
    408 {
    409     QPoint globalPosition = parentWidget()->mapFromGlobal (aPoint);
    410     QRect fullArea = QApplication::desktop()->screenGeometry (window());
    411     QRect realArea = mSeamless ? vboxGlobal().availableGeometry (QApplication::desktop()->screenNumber(window())) :
    412                                  QApplication::desktop()->screenGeometry (window());
    413     QPoint shiftToReal (realArea.topLeft() - fullArea.topLeft());
    414     return globalPosition + shiftToReal;
    415 }
    416 
    417 bool VBoxMiniToolBar::eventFilter(QObject *pObj, QEvent *pEvent)
    418 {
    419     if (pEvent->type() == QEvent::Resize)
    420     {
    421         moveToBase();
    422         return true;
    423     }
    424     return VBoxToolBar::eventFilter(pObj, pEvent);
    425 }
    426 
     442            m_iPositionY = 0;
     443            break;
     444        }
     445    }
     446    move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY)));
     447}
     448
     449/* Enable/disable mouse-tracking for required widgets */
     450void VBoxMiniToolBar::setMouseTrackingEnabled(bool fEnabled)
     451{
     452    setMouseTracking(fEnabled);
     453    if (m_pDisplayLabel)
     454        m_pDisplayLabel->setMouseTracking(fEnabled);
     455    if (m_pAutoHideAction && widgetForAction(m_pAutoHideAction))
     456        widgetForAction(m_pAutoHideAction)->setMouseTracking(fEnabled);
     457    if (m_pRestoreAction && widgetForAction(m_pRestoreAction))
     458        widgetForAction(m_pRestoreAction)->setMouseTracking(fEnabled);
     459    if (m_pCloseAction && widgetForAction(m_pCloseAction))
     460        widgetForAction(m_pCloseAction)->setMouseTracking(fEnabled);
     461}
     462
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMiniToolBar.h

    r28800 r29083  
    66
    77/*
    8  * Copyright (C) 2009 Oracle Corporation
     8 * Copyright (C) 2009-2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#define __VBoxMiniToolBar_h__
    2121
    22 /* VBox includes */
    23 #include <VBoxToolBar.h>
    24 
    25 /* Qt includes */
     22/* Global includes */
    2623#include <QBasicTimer>
    2724
     25/* Local includes */
     26#include "VBoxToolBar.h"
     27
     28/* Global forwards */
    2829class QLabel;
    2930class QMenu;
     
    4546    };
    4647
    47     VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment, bool aIsActive, bool aAutoHide);
     48    VBoxMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide);
    4849
    49     VBoxMiniToolBar& operator<< (QList <QMenu*> aMenus);
     50    VBoxMiniToolBar& operator<<(QList<QMenu*> menus);
    5051
    51     void setSeamlessMode (bool aIsSeamless);
    52     void setDisplayText (const QString &aText);
     52    void setSeamlessMode(bool fSeamless);
     53    void setDisplayText(const QString &strText);
    5354
    5455    bool isAutoHide() const;
    5556
    56     void updateDisplay (bool aShow, bool aSetHideFlag);
     57    void updateDisplay(bool fShow, bool fSetHideFlag);
    5758
    5859signals:
     
    6465protected:
    6566
    66     void mouseMoveEvent (QMouseEvent *aEvent);
    67     void timerEvent (QTimerEvent *aEvent);
    68     void showEvent (QShowEvent *aEvent);
    69     void paintEvent (QPaintEvent *aEvent);
    7067    bool eventFilter(QObject *pObj, QEvent *pEvent);
     68    void mouseMoveEvent(QMouseEvent *pEvent);
     69    void timerEvent(QTimerEvent *pEvent);
     70    void showEvent(QShowEvent *pEvent);
     71    void paintEvent(QPaintEvent *pEvent);
    7172
    7273private slots:
    7374
    74     void togglePushpin (bool aOn);
     75    void togglePushpin(bool fOn);
    7576
    7677private:
     
    7980    void recreateMask();
    8081    void moveToBase();
    81     QPoint mapFromScreen (const QPoint &aPoint);
     82    void setMouseTrackingEnabled(bool fEnabled);
    8283
    83     QAction *mAutoHideAct;
    84     QLabel *mDisplayLabel;
     84    QAction *m_pAutoHideAction;
     85    QLabel *m_pDisplayLabel;
     86    QAction *m_pRestoreAction;
     87    QAction *m_pCloseAction;
    8588
    86     QBasicTimer mScrollTimer;
    87     QBasicTimer mAutoScrollTimer;
     89    QBasicTimer m_scrollTimer;
     90    QBasicTimer m_autoScrollTimer;
    8891
    89     bool mActive;
    90     bool mPolished;
    91     bool mSeamless;
    92     bool mAutoHide;
    93     bool mSlideToScreen;
    94     bool mHideAfterSlide;
     92    bool m_fActive;
     93    bool m_fPolished;
     94    bool m_fSeamless;
     95    bool m_fAutoHide;
     96    bool m_fSlideToScreen;
     97    bool m_fHideAfterSlide;
    9598
    96     int mAutoHideCounter;
    97     int mPositionX;
    98     int mPositionY;
     99    int m_iAutoHideCounter;
     100    int m_iPositionX;
     101    int m_iPositionY;
    99102
    100103    /* Lists of used spacers */
    101     QList <QWidget*> mMargins;
    102     QList <QWidget*> mSpacings;
    103     QList <QWidget*> mLabelMargins;
     104    QList<QWidget*> m_Margins;
     105    QList<QWidget*> m_Spacings;
     106    QList<QWidget*> m_LabelMargins;
    104107
    105108    /* Menu insert position */
    106     QAction *mInsertPosition;
     109    QAction *m_pInsertPosition;
    107110
    108111    /* Tool-bar alignment */
    109     Alignment mAlignment;
     112    Alignment m_alignment;
    110113
    111114    /* Wether to animate showing/hiding the toolbar */
    112     bool mAnimated;
     115    bool m_fAnimated;
    113116
    114117    /* Interval (in milli seconds) for scrolling the toolbar, default is 20 msec */
    115     int mScrollDelay;
     118    int m_iScrollDelay;
    116119
    117120    /* The wait time while the cursor is not over the window after this amount of time (in msec),
    118121     * the toolbar will auto hide if autohide is on. The default is 100msec. */
    119     int mAutoScrollDelay;
     122    int m_iAutoScrollDelay;
    120123
    121     /* Number of total steps before hiding. If it is 10 then wait 10 (steps) * 100ms (mAutoScrollDelay) = 1000ms delay.
     124    /* Number of total steps before hiding. If it is 10 then wait 10 (steps) * 100ms (m_iAutoScrollDelay) = 1000ms delay.
    122125     * The default is 10. */
    123     int mAutoHideTotalCounter;
     126    int m_iAutoHideTotalCounter;
    124127};
    125128
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