VirtualBox

Changeset 94015 in vbox


Ignore:
Timestamp:
Mar 1, 2022 9:36:38 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150248
Message:

FE/Qt: qt6: QDesktopWidget is gone, mostly replaced by QScreen and QGuiApplication functionality. Host screens does not seem to have an index assigned, so faked this by using the position in QGuiApplication::screens() list. bugref:9898

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp

    r94013 r94015  
    1818/* Qt includes: */
    1919#include <QApplication>
    20 #include <QDesktopWidget>
     20#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
     21# include <QDesktopWidget>
     22#endif
    2123#include <QWidget>
    2224#include <QScreen>
     
    285287int UIDesktopWidgetWatchdog::overallDesktopWidth() const
    286288{
     289#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     290    /** @todo bird: Not sure if this is entirely correct. */
     291    return QGuiApplication::primaryScreen()->geometry().width();
     292#else
    287293    /* Redirect call to desktop-widget: */
    288294    return QApplication::desktop()->width();
     295#endif
    289296}
    290297
    291298int UIDesktopWidgetWatchdog::overallDesktopHeight() const
    292299{
     300#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     301    /** @todo bird: Not sure if this is entirely correct. */
     302    return QGuiApplication::primaryScreen()->geometry().height();
     303#else
    293304    /* Redirect call to desktop-widget: */
    294305    return QApplication::desktop()->height();
     306#endif
    295307}
    296308
    297309int UIDesktopWidgetWatchdog::screenCount() const
    298310{
     311#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     312    return QGuiApplication::screens().size();
     313#else
    299314    /* Redirect call to desktop-widget: */
    300315    return QApplication::desktop()->screenCount();
    301 }
     316#endif
     317}
     318
     319#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     320
     321/** Helper for generating qt5 screen indexes as best as we can. */
     322static int screenToIndex(QScreen *pScreen)
     323{
     324    if (pScreen)
     325    {
     326        /** @todo Not at all sure about the sensitibility of this.   */
     327        QList<QScreen *> screenList = QGuiApplication::screens();
     328        unsigned         iScreen    = 0;
     329        foreach (QScreen *pCurScreen, screenList)
     330        {
     331            if (   pCurScreen == pScreen
     332                || (   pCurScreen->geometry() == pScreen->geometry()
     333                    && pCurScreen->serialNumber() == pScreen->serialNumber()))
     334                return iScreen;
     335            iScreen++;
     336        }
     337    }
     338    return -1;
     339}
     340
     341/** Helper for converting a qt5 screen index back to a QScreen pointer. */
     342static QScreen *indexToScreen(int idxScreen)
     343{
     344    if (idxScreen < 0)
     345        return QGuiApplication::primaryScreen();
     346
     347    QList<QScreen *> screenList = QGuiApplication::screens();
     348    if (idxScreen >= screenList.size())
     349        return QGuiApplication::primaryScreen();
     350
     351    return screenList.value(idxScreen);
     352}
     353
     354#endif
    302355
    303356int UIDesktopWidgetWatchdog::primaryScreen() const
    304357{
     358#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     359    return screenToIndex(QGuiApplication::primaryScreen());
     360#else
    305361    /* Redirect call to desktop-widget: */
    306362    return QApplication::desktop()->primaryScreen();
     363#endif
    307364}
    308365
    309366int UIDesktopWidgetWatchdog::screenNumber(const QWidget *pWidget) const
    310367{
     368#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     369    if (pWidget)
     370        return screenToIndex(pWidget->screen());
     371    return -1;
     372#else
    311373    /* Redirect call to desktop-widget: */
    312374    return QApplication::desktop()->screenNumber(pWidget);
     375#endif
    313376}
    314377
    315378int UIDesktopWidgetWatchdog::screenNumber(const QPoint &point) const
    316379{
     380#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     381    return screenToIndex(QGuiApplication::screenAt(point));
     382#else
    317383    /* Redirect call to desktop-widget: */
    318384    return QApplication::desktop()->screenNumber(point);
     385#endif
    319386}
    320387
    321388const QRect UIDesktopWidgetWatchdog::screenGeometry(int iHostScreenIndex /* = -1 */) const
    322389{
     390#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     391    return indexToScreen(iHostScreenIndex)->geometry();
     392#else
    323393    /* Make sure index is valid: */
    324394    if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount())
     
    328398    /* Redirect call to desktop-widget: */
    329399    return QApplication::desktop()->screenGeometry(iHostScreenIndex);
     400#endif
    330401}
    331402
     
    344415const QRect UIDesktopWidgetWatchdog::availableGeometry(int iHostScreenIndex /* = -1 */) const
    345416{
     417#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     418    /** @todo needs X11 work, see 5.x version of code! */
     419    return indexToScreen(iHostScreenIndex)->availableGeometry();
     420#else /* < 6.0.0 */
    346421    /* Make sure index is valid: */
    347422    if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount())
     
    349424    AssertReturn(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount(), QRect());
    350425
    351 #ifdef VBOX_WS_X11
    352 # ifdef VBOX_GUI_WITH_CUSTOMIZATIONS1
     426# ifdef VBOX_WS_X11
     427#  ifdef VBOX_GUI_WITH_CUSTOMIZATIONS1
    353428    // WORKAROUND:
    354429    // For customer WM we don't want Qt to return wrong available geometry,
    355430    // so we are returning fallback screen geometry in any case..
    356431    return QApplication::desktop()->screenGeometry(iHostScreenIndex);
    357 # else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
     432#  else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    358433    /* Get cached available-geometry: */
    359434    const QRect availableGeometry = m_availableGeometryData.value(iHostScreenIndex);
     
    361436    return availableGeometry.isValid() ? availableGeometry :
    362437           QApplication::desktop()->screenGeometry(iHostScreenIndex);
    363 # endif /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    364 #else /* !VBOX_WS_X11 */
     438#  endif /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
     439# else /* !VBOX_WS_X11 */
    365440    /* Redirect call to desktop-widget: */
    366441    return QApplication::desktop()->availableGeometry(iHostScreenIndex);
    367 #endif /* !VBOX_WS_X11 */
     442# endif /* !VBOX_WS_X11 */
     443#endif /* < 6.0.0 */
    368444}
    369445
    370446const QRect UIDesktopWidgetWatchdog::availableGeometry(const QWidget *pWidget) const
    371447{
     448#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     449    if (pWidget && pWidget->screen())
     450        return pWidget->screen()->availableGeometry();
     451    return QRect();
     452#else
    372453    /* Redirect call to wrapper above: */
    373454    return availableGeometry(screenNumber(pWidget));
     455#endif
    374456}
    375457
    376458const QRect UIDesktopWidgetWatchdog::availableGeometry(const QPoint &point) const
    377459{
     460#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     461    QScreen *pScreen = QGuiApplication::screenAt(point);
     462    if (pScreen)
     463        return pScreen->availableGeometry();
     464    return QRect();
     465#else
    378466    /* Redirect call to wrapper above: */
    379467    return availableGeometry(screenNumber(point));
     468#endif
    380469}
    381470
     
    9971086    /* Make sure index is valid: */
    9981087    if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount())
    999         iHostScreenIndex = QApplication::desktop()->primaryScreen();
    1000     AssertReturnVoid(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount());
     1088    {
     1089        iHostScreenIndex = UIDesktopWidgetWatchdog::primaryScreen();
     1090        AssertReturnVoid(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount());
     1091    }
    10011092
    10021093    /* Create invisible frame-less window worker: */
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