VirtualBox

Ignore:
Timestamp:
Jun 2, 2009 4:18:04 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: 3948: Mini-ToolBar for Full-screen & Seamless modes: re-parenting tool-bar to centralWidget(), fixing different bugs.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h

    r19844 r20200  
    102102
    103103    QRect desktopGeometry();
     104
     105    QRegion lastVisibleRegion() const;
    104106
    105107    bool isAutoresizeGuestActive();
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h

    r20047 r20200  
    254254    void mtExitMode();
    255255    void mtCloseVM();
     256    void mtMaskUpdate();
    256257
    257258private:
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxMiniToolBar.h

    r20146 r20200  
    4949    };
    5050
    51     VBoxMiniToolBar (Alignment aAlignment);
     51    VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment);
     52
     53    void setIsSeamlessMode (bool aIsSeamless);
    5254
    5355    VBoxMiniToolBar& operator<< (QList <QMenu*> aMenus);
     
    6062    void exitAction();
    6163    void closeAction();
     64    void geometryUpdated();
    6265
    6366protected:
    6467
    65     void resizeEvent (QResizeEvent *aEvent);
    6668    void mouseMoveEvent (QMouseEvent *aEvent);
    6769    void timerEvent (QTimerEvent *aEvent);
     
    7375
    7476private:
     77
     78    void recreateMask();
     79    void moveToBase();
     80    QPoint mapFromScreen (const QPoint &aPoint);
    7581
    7682    QAction *mAutoHideAct;
     
    8894    int mPositionX;
    8995    int mPositionY;
     96
     97    bool mIsSeamless;
    9098
    9199    /* Lists of used spacers */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r20047 r20200  
    26342634}
    26352635
     2636QRegion VBoxConsoleView::lastVisibleRegion() const
     2637{
     2638    return mLastVisibleRegion;
     2639}
     2640
    26362641bool VBoxConsoleView::isAutoresizeGuestActive()
    26372642{
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r20146 r20200  
    520520    mMiniVMMenu->addAction (mVmPauseAction);
    521521    mMiniVMMenu->addAction (mVmACPIShutdownAction);
    522 
    523     /* Mini toolbar */
    524     QList <QMenu*> menus (QList <QMenu*> () << mMiniVMMenu << mDevicesMenu);
    525     mMiniToolBar = new VBoxMiniToolBar (VBoxMiniToolBar::AlignBottom);
    526     *mMiniToolBar << menus;
    527     connect (mMiniToolBar, SIGNAL (exitAction()), this, SLOT (mtExitMode()));
    528     connect (mMiniToolBar, SIGNAL (closeAction()), this, SLOT (mtCloseVM()));
    529     connect (this, SIGNAL (closing()), mMiniToolBar, SLOT (close()));
    530522
    531523    ///// Status bar ////////////////////////////////////////////////////////
     
    818810                                   centralWidget());
    819811
     812    /* Mini toolbar */
     813    QList <QMenu*> menus (QList <QMenu*> () << mMiniVMMenu << mDevicesMenu);
     814    mMiniToolBar = new VBoxMiniToolBar (centralWidget(), VBoxMiniToolBar::AlignBottom);
     815    *mMiniToolBar << menus;
     816    connect (mMiniToolBar, SIGNAL (exitAction()), this, SLOT (mtExitMode()));
     817    connect (mMiniToolBar, SIGNAL (closeAction()), this, SLOT (mtCloseVM()));
     818    connect (mMiniToolBar, SIGNAL (geometryUpdated()), this, SLOT (mtMaskUpdate()));
     819    connect (this, SIGNAL (closing()), mMiniToolBar, SLOT (close()));
     820
    820821    activateUICustomizations();
    821822
     
    24402441    if (aOn)
    24412442    {
     2443        mMiniToolBar->setIsSeamlessMode (aSeamless);
    24422444        mMiniToolBar->updateDisplay (true, true);
    24432445    }
     
    25732575}
    25742576
     2577void VBoxConsoleWnd::mtMaskUpdate()
     2578{
     2579    if (mIsSeamless)
     2580        setMask (console->lastVisibleRegion());
     2581}
     2582
    25752583void VBoxConsoleWnd::vmFullscreen (bool aOn)
    25762584{
     
    29892997{
    29902998    QRegion region = aRegion;
     2999
    29913000    /* The global mask shift cause of toolbars and such things. */
    29923001    region.translate (mMaskShift.width(), mMaskShift.height());
     3002
     3003    /* Including mini toolbar area */
     3004    QRegion toolBarRegion (mMiniToolBar->mask());
     3005    toolBarRegion.translate (mMiniToolBar->mapToGlobal (toolBarRegion.boundingRect().topLeft()) - QPoint (1, 0));
     3006    region += toolBarRegion;
     3007
    29933008    /* Restrict the drawing to the available space on the screen.
    29943009     * (The &operator is better than the previous used -operator,
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMiniToolBar.cpp

    r20146 r20200  
    3535#include <QTimer>
    3636
    37 VBoxMiniToolBar::VBoxMiniToolBar (Alignment aAlignment)
    38     : VBoxToolBar (0)
     37VBoxMiniToolBar::VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment)
     38    : VBoxToolBar (aParent)
    3939    , mAutoHideCounter (0)
    4040    , mAutoHide (true)
     
    4242    , mHideAfterSlide (false)
    4343    , mPolished (false)
     44    , mIsSeamless (false)
    4445    , mAlignment (aAlignment)
    4546    , mAnimated (true)
     
    4849    , mAutoHideTotalCounter (10)
    4950{
    50     /* Play with toolbar mode as child of the main window, rather than top parentless */
    51     //setAllowedAreas (Qt::NoToolBarArea);
    52     //mMainWindow->addToolBar (/* Qt::NoToolBarArea, */ this);
    53 
    54     setWindowFlags (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
     51    AssertMsg (parentWidget(), ("Parent widget must be set!!!\n"));
     52
     53    /* Various options */
     54    setAutoFillBackground (true);
    5555    setIconSize (QSize (16, 16));
    5656    setMouseTracking (mAutoHide);
    5757    setVisible (false);
    58 
    59     // TODO, we need to hide the tab icon in taskbar when in seamless mode
    60     setWindowTitle (tr ("VirtualBox Mini Toolbar"));
    6158
    6259    /* Left margin of tool-bar */
     
    108105}
    109106
     107void VBoxMiniToolBar::setIsSeamlessMode (bool aIsSeamless)
     108{
     109    mIsSeamless = aIsSeamless;
     110}
     111
    110112VBoxMiniToolBar& VBoxMiniToolBar::operator<< (QList <QMenu*> aMenus)
    111113{
     
    131133    if (aShow)
    132134    {
     135        if (isHidden())
     136            moveToBase();
     137
    133138        if (mAnimated)
    134139        {
     
    174179{
    175180    mDisplayLabel->setText (aText);
    176 }
    177 
    178 void VBoxMiniToolBar::resizeEvent (QResizeEvent*)
    179 {
    180     /* Create polygon shaped toolbar */
    181     int triangular_x = height();
    182     int points [8];
    183     switch (mAlignment)
    184     {
    185         case AlignTop:
    186         {
    187             points [0] = 0;
    188             points [1] = 0;
    189 
    190             points [2] = triangular_x;
    191             points [3] = height();
    192 
    193             points [4] = width() - triangular_x;
    194             points [5] = height();
    195 
    196             points [6] = width();
    197             points [7] = 0;
    198 
    199             break;
    200         }
    201         case AlignBottom:
    202         {
    203             points [0] = triangular_x;
    204             points [1] = 0;
    205 
    206             points [2] = 0;
    207             points [3] = height();
    208 
    209             points [4] = width();
    210             points [5] = height();
    211 
    212             points [6] = width() - triangular_x;
    213             points [7] = 0;
    214 
    215             break;
    216         }
    217         default:
    218             break;
    219     }
    220     QPolygon polygon;
    221     polygon.setPoints (4, points);
    222     setMask (polygon);
    223 
    224     /* Set the initial position */
    225     QRect d = QApplication::desktop()->screenGeometry (this);
    226     mPositionX = d.width() / 2 - width() / 2;
    227     switch (mAlignment)
    228     {
    229         case AlignTop:
    230         {
    231             mPositionY = - height() + 1;
    232             break;
    233         }
    234         case AlignBottom:
    235         {
    236             mPositionY = d.height() - 1;
    237             break;
    238         }
    239         default:
    240         {
    241             mPositionY = 0;
    242             break;
    243         }
    244     }
    245     move (mPositionX, mPositionY);
    246181}
    247182
     
    282217            case AlignBottom:
    283218            {
    284                 QRect d = QApplication::desktop()->screenGeometry (this);
    285                 if (((mPositionY == d.height() - height()) && mSlideToScreen) ||
    286                     ((mPositionY == d.height() - 1) && !mSlideToScreen))
     219                QRect screen = mIsSeamless ? QApplication::desktop()->availableGeometry (this) :
     220                                             QApplication::desktop()->screenGeometry (this);
     221                if (((mPositionY == screen.height() - height()) && mSlideToScreen) ||
     222                    ((mPositionY == screen.height() - 1) && !mSlideToScreen))
    287223                {
    288224                    mScrollTimer.stop();
     
    300236                break;
    301237        }
    302         move (mPositionX, mPositionY);
     238        move (mapFromScreen (QPoint (mPositionX, mPositionY)));
     239        emit geometryUpdated();
    303240    }
    304241    else if (aEvent->timerId() == mAutoScrollTimer.timerId())
     
    344281        resize (sizeHint());
    345282
     283        /* Initialize */
     284        recreateMask();
     285        moveToBase();
     286
    346287        mPolished = true;
    347288    }
     
    356297}
    357298
     299void VBoxMiniToolBar::recreateMask()
     300{
     301    int edgeShift = height();
     302    int points [8];
     303    switch (mAlignment)
     304    {
     305        case AlignTop:
     306        {
     307            points [0] = 0;
     308            points [1] = 0;
     309
     310            points [2] = edgeShift;
     311            points [3] = height();
     312
     313            points [4] = width() - edgeShift;
     314            points [5] = height();
     315
     316            points [6] = width();
     317            points [7] = 0;
     318
     319            break;
     320        }
     321        case AlignBottom:
     322        {
     323            points [0] = edgeShift;
     324            points [1] = 0;
     325
     326            points [2] = 0;
     327            points [3] = height();
     328
     329            points [4] = width();
     330            points [5] = height();
     331
     332            points [6] = width() - edgeShift;
     333            points [7] = 0;
     334
     335            break;
     336        }
     337        default:
     338            break;
     339    }
     340    QPolygon polygon;
     341    polygon.setPoints (4, points);
     342    setMask (polygon);
     343}
     344
     345void VBoxMiniToolBar::moveToBase()
     346{
     347    QRect screen = mIsSeamless ? QApplication::desktop()->availableGeometry (this) :
     348                                 QApplication::desktop()->screenGeometry (this);
     349    mPositionX = screen.width() / 2 - width() / 2;
     350    switch (mAlignment)
     351    {
     352        case AlignTop:
     353        {
     354            mPositionY = - height() + 1;
     355            break;
     356        }
     357        case AlignBottom:
     358        {
     359            mPositionY = screen.height() - 1;
     360            break;
     361        }
     362        default:
     363        {
     364            mPositionY = 0;
     365            break;
     366        }
     367    }
     368    move (mapFromScreen (QPoint (mPositionX, mPositionY)));
     369}
     370
     371QPoint VBoxMiniToolBar::mapFromScreen (const QPoint &aPoint)
     372{
     373    QPoint globalPosition = parentWidget()->mapFromGlobal (aPoint);
     374    QRect fullArea = QApplication::desktop()->screenGeometry (this);
     375    QRect realArea = mIsSeamless ? QApplication::desktop()->availableGeometry (this) :
     376                                   QApplication::desktop()->screenGeometry (this);
     377    QPoint shiftToReal (realArea.topLeft() - fullArea.topLeft());
     378    return globalPosition + shiftToReal;
     379}
     380
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