VirtualBox

Ignore:
Timestamp:
Sep 29, 2014 4:52:38 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96319
Message:

FE/Qt: X11: Runtime UI: Mini-toolbar: Rework it to be window again, fixing conflicts with Unity panels for full-screen and seamless modes.

File:
1 edited

Legend:

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

    r52874 r52891  
    5252                                           bool fAutoHide /* = true */)
    5353    : QWidget(pParent,
    54 #if   defined (Q_WS_WIN)
     54#if   defined(Q_WS_WIN)
    5555              Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
    56 #elif defined (Q_WS_MAC)
     56#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
    5757              Qt::Window | Qt::FramelessWindowHint
    58 #elif defined (Q_WS_X11)
    59               Qt::Widget
    60 #endif /* RT_OS_DARWIN */
     58#endif /* Q_WS_MAC || Q_WS_X11 */
    6159              )
    6260    /* Variables: General stuff: */
     
    143141void UIRuntimeMiniToolBar::adjustGeometry(int iHostScreen /* = -1 */)
    144142{
     143#ifndef Q_WS_X11
    145144    /* This method could be called before parent-widget
    146145     * become visible, we should skip everything in that case: */
     
    166165        default: break;
    167166    }
    168 #ifdef Q_WS_X11
    169     /* Disregard origin under X11,
    170      * because this is widget, not window: */
    171     screenRect.moveTopLeft(QPoint(0, 0));
    172 #endif /* Q_WS_X11 */
    173167    iX = screenRect.x() + screenRect.width() / 2 - width() / 2;
    174168    switch (m_alignment)
     
    202196    /* Simulate toolbar auto-hiding: */
    203197    simulateToolbarAutoHiding();
     198
     199#else /* Q_WS_X11 */
     200
     201    /* This method could be called before parent-widget
     202     * become visible, we should skip everything in that case: */
     203    if (QApplication::desktop()->screenNumber(parentWidget()) == -1)
     204        return;
     205
     206    /* Determine host-screen number if necessary: */
     207    bool fMoveToHostScreen = true;
     208    if (iHostScreen == -1)
     209    {
     210        fMoveToHostScreen = false;
     211        iHostScreen = QApplication::desktop()->screenNumber(this);
     212    }
     213
     214    /* Choose window geometry: */
     215    QRect screenRect;
     216    switch (m_geometryType)
     217    {
     218        case GeometryType_Available: screenRect = QApplication::desktop()->availableGeometry(iHostScreen); break;
     219        case GeometryType_Full:      screenRect = QApplication::desktop()->screenGeometry(iHostScreen); break;
     220        default: break;
     221    }
     222
     223    /* Move to corresponding host-screen: */
     224    if (fMoveToHostScreen)
     225        move(screenRect.topLeft());
     226
     227    /* Resize embedded-toolbar to minimum size: */
     228    m_pEmbeddedToolbar->resize(m_pEmbeddedToolbar->sizeHint());
     229
     230    /* Calculate embedded-toolbar position: */
     231    int iX = 0, iY = 0;
     232    iX = screenRect.width() / 2 - m_pEmbeddedToolbar->width() / 2;
     233    switch (m_alignment)
     234    {
     235        case Qt::AlignTop:    iY = 0; break;
     236        case Qt::AlignBottom: iY = screenRect.height() - m_pEmbeddedToolbar->height(); break;
     237        default: break;
     238    }
     239
     240    /* Update auto-hide animation: */
     241    m_shownToolbarPosition = QPoint(iX, iY);
     242    switch (m_alignment)
     243    {
     244        case Qt::AlignTop:    m_hiddenToolbarPosition = m_shownToolbarPosition - QPoint(0, m_pEmbeddedToolbar->height() - 3); break;
     245        case Qt::AlignBottom: m_hiddenToolbarPosition = m_shownToolbarPosition + QPoint(0, m_pEmbeddedToolbar->height() - 3); break;
     246    }
     247    m_pAnimation->update();
     248
     249    /* Update embedded-toolbar geometry if known: */
     250    const QString strAnimationState = property("AnimationState").toString();
     251    if (strAnimationState == "Start")
     252        m_pEmbeddedToolbar->move(m_hiddenToolbarPosition);
     253    else if (strAnimationState == "Final")
     254        m_pEmbeddedToolbar->move(m_shownToolbarPosition);
     255
     256    /* Adjust window mask: */
     257    setMask(m_pEmbeddedToolbar->geometry());
     258
     259    /* Simulate toolbar auto-hiding: */
     260    simulateToolbarAutoHiding();
     261#endif /* Q_WS_X11 */
    204262}
    205263
     
    238296void UIRuntimeMiniToolBar::prepare()
    239297{
    240 #ifdef Q_WS_MAC
     298#if defined(Q_WS_MAC) || defined (Q_WS_X11)
    241299    /* Install own event filter: */
    242300    installEventFilter(this);
    243 #endif /* Q_WS_MAC */
     301#endif /* Q_WS_MAC || Q_WS_X11 */
    244302
    245303#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     
    259317    setAttribute(Qt::WA_TranslucentBackground);
    260318# endif /* Q_WS_WIN */
    261 #endif /* Q_WS_MAC || Q_WS_WIN */
     319#elif defined(Q_WS_X11)
     320    /* Use Qt API to enable translucency if allowed: */
     321    if (QX11Info::isCompositingManagerRunning())
     322        setAttribute(Qt::WA_TranslucentBackground);
     323#endif /* Q_WS_X11 */
    262324
    263325    /* Make sure we have no focus: */
     
    378440}
    379441
     442#ifdef Q_WS_X11
     443void UIRuntimeMiniToolBar::resizeEvent(QResizeEvent*)
     444{
     445    /* Adjust mini-toolbar on resize: */
     446    adjustGeometry();
     447}
     448#endif /* Q_WS_X11 */
     449
    380450bool UIRuntimeMiniToolBar::eventFilter(QObject *pWatched, QEvent *pEvent)
    381451{
     
    388458        pEvent->type() == QEvent::FocusIn)
    389459        emit sigNotifyAboutFocusStolen();
    390 #elif defined(Q_WS_MAC)
    391     /* Due to Qt bug on Mac OS X window will be activated
    392      * even if has Qt::WA_ShowWithoutActivating attribute. */
     460#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
     461    /* Detect if we have window activation stolen. */
    393462    if (pWatched == this &&
    394463        pEvent->type() == QEvent::WindowActivate)
    395464        emit sigNotifyAboutFocusStolen();
    396 #endif /* Q_WS_MAC */
     465#endif /* Q_WS_MAC || Q_WS_X11 */
    397466
    398467    /* Call to base-class: */
     
    423492    /* Update window mask: */
    424493    setMask(m_pEmbeddedToolbar->geometry());
    425 
    426 # ifdef VBOX_WITH_MASKED_SEAMLESS
    427     /* Notify listeners as well: */
    428     const QRect windowGeo = geometry();
    429     emit sigNotifyAboutGeometryChange(windowGeo.intersected(m_pEmbeddedToolbar->geometry().translated(windowGeo.topLeft())));
    430 # endif /* VBOX_WITH_MASKED_SEAMLESS */
    431494#endif /* Q_WS_X11 */
    432495}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette