VirtualBox

Changeset 73451 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 2, 2018 12:31:25 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124078
Message:

FE/Qt: VirtualBox Manager UI: A bit of code reordering.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r73450 r73451  
    148148}
    149149
     150#ifdef VBOX_WS_MAC
     151bool UIVirtualBoxManager::eventFilter(QObject *pObject, QEvent *pEvent)
     152{
     153    /* Ignore for non-active window except for FileOpen event which should be always processed: */
     154    if (!isActiveWindow() && pEvent->type() != QEvent::FileOpen)
     155        return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     156
     157    /* Ignore for other objects: */
     158    if (qobject_cast<QWidget*>(pObject) &&
     159        qobject_cast<QWidget*>(pObject)->window() != this)
     160        return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     161
     162    /* Which event do we have? */
     163    switch (pEvent->type())
     164    {
     165        case QEvent::FileOpen:
     166        {
     167            sltHandleOpenUrlCall(QList<QUrl>() << static_cast<QFileOpenEvent*>(pEvent)->url());
     168            pEvent->accept();
     169            return true;
     170            break;
     171        }
     172        default:
     173            break;
     174    }
     175    /* Call to base-class: */
     176    return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     177}
     178#endif /* VBOX_WS_MAC */
     179
     180void UIVirtualBoxManager::retranslateUi()
     181{
     182    /* Set window title: */
     183    QString strTitle(VBOX_PRODUCT);
     184    strTitle += " " + tr("Manager", "Note: main window title which is prepended by the product name.");
     185#ifdef VBOX_BLEEDING_EDGE
     186    strTitle += QString(" EXPERIMENTAL build ")
     187             +  QString(RTBldCfgVersion())
     188             +  QString(" r")
     189             +  QString(RTBldCfgRevisionStr())
     190             +  QString(" - " VBOX_BLEEDING_EDGE);
     191#endif /* VBOX_BLEEDING_EDGE */
     192    setWindowTitle(strTitle);
     193
     194    /* Make sure chosen item fetched: */
     195    sltHandleChooserPaneIndexChange(false /* update details? */, false /* update snapshots? */, false /* update the logviewer? */);
     196
     197#ifdef VBOX_WS_MAC
     198    // WORKAROUND:
     199    // There is a bug in Qt Cocoa which result in showing a "more arrow" when
     200    // the necessary size of the toolbar is increased. Also for some languages
     201    // the with doesn't match if the text increase. So manually adjust the size
     202    // after changing the text.
     203    m_pToolBar->updateLayout();
     204#endif
     205}
     206
     207bool UIVirtualBoxManager::event(QEvent *pEvent)
     208{
     209    /* Which event do we have? */
     210    switch (pEvent->type())
     211    {
     212        /* Handle every ScreenChangeInternal event to notify listeners: */
     213        case QEvent::ScreenChangeInternal:
     214        {
     215            emit sigWindowRemapped();
     216            break;
     217        }
     218        /* Handle every Resize and Move we keep track of the geometry. */
     219        case QEvent::Resize:
     220        {
     221#ifdef VBOX_WS_X11
     222            /* Prevent handling if fake screen detected: */
     223            if (gpDesktop->isFakeScreenDetected())
     224                break;
     225#endif /* VBOX_WS_X11 */
     226
     227            if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
     228            {
     229                QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
     230                m_geometry.setSize(pResizeEvent->size());
     231            }
     232            break;
     233        }
     234        case QEvent::Move:
     235        {
     236#ifdef VBOX_WS_X11
     237            /* Prevent handling if fake screen detected: */
     238            if (gpDesktop->isFakeScreenDetected())
     239                break;
     240#endif /* VBOX_WS_X11 */
     241
     242            if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
     243            {
     244#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
     245                QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent);
     246                m_geometry.moveTo(pMoveEvent->pos());
     247#else /* !VBOX_WS_MAC && !VBOX_WS_WIN */
     248                m_geometry.moveTo(geometry().x(), geometry().y());
     249#endif /* !VBOX_WS_MAC && !VBOX_WS_WIN */
     250            }
     251            break;
     252        }
     253#ifdef VBOX_WS_MAC
     254        case QEvent::ContextMenu:
     255        {
     256            /* This is the unified context menu event. Lets show the context menu. */
     257            QContextMenuEvent *pContextMenuEvent = static_cast<QContextMenuEvent*>(pEvent);
     258            sltHandleContextMenuRequest(pContextMenuEvent->globalPos());
     259            /* Accept it to interrupt the chain. */
     260            pContextMenuEvent->accept();
     261            return false;
     262            break;
     263        }
     264#endif /* VBOX_WS_MAC */
     265        default:
     266            break;
     267    }
     268    /* Call to base-class: */
     269    return QIWithRetranslateUI<QIMainWindow>::event(pEvent);
     270}
     271
     272void UIVirtualBoxManager::showEvent(QShowEvent *pEvent)
     273{
     274    /* Call to base-class: */
     275    QIWithRetranslateUI<QIMainWindow>::showEvent(pEvent);
     276
     277    /* Is polishing required? */
     278    if (!m_fPolished)
     279    {
     280        /* Pass the show-event to polish-event: */
     281        polishEvent(pEvent);
     282        /* Mark as polished: */
     283        m_fPolished = true;
     284    }
     285}
     286
     287void UIVirtualBoxManager::polishEvent(QShowEvent *)
     288{
     289    /* Make sure user warned about inaccessible medium(s)
     290     * even if enumeration had finished before selector window shown: */
     291    QTimer::singleShot(0, this, SLOT(sltHandleMediumEnumerationFinish()));
     292
     293    /* Call for async polishing: */
     294    QMetaObject::invokeMethod(this, "sltHandlePolishEvent", Qt::QueuedConnection);
     295}
     296
     297void UIVirtualBoxManager::closeEvent(QCloseEvent *pEvent)
     298{
     299    /* Call to base-class: */
     300    QIWithRetranslateUI<QIMainWindow>::closeEvent(pEvent);
     301
     302    /* Quit application: */
     303    QApplication::quit();
     304}
     305
    150306void UIVirtualBoxManager::sltHandlePolishEvent()
    151307{
     
    605761
    606762void UIVirtualBoxManager::sltOpenMachineSettingsDialog(const QString &strCategoryRef /* = QString() */,
    607                                                     const QString &strControlRef /* = QString() */,
    608                                                     const QString &strID /* = QString() */)
     763                                                       const QString &strControlRef /* = QString() */,
     764                                                       const QString &strID /* = QString() */)
    609765{
    610766    /* This slot should not be called when there is not selection: */
     
    12451401{
    12461402    return m_pPaneChooser->currentItems();
    1247 }
    1248 
    1249 void UIVirtualBoxManager::retranslateUi()
    1250 {
    1251     /* Set window title: */
    1252     QString strTitle(VBOX_PRODUCT);
    1253     strTitle += " " + tr("Manager", "Note: main window title which is pretended by the product name.");
    1254 #ifdef VBOX_BLEEDING_EDGE
    1255     strTitle += QString(" EXPERIMENTAL build ")
    1256              +  QString(RTBldCfgVersion())
    1257              +  QString(" r")
    1258              +  QString(RTBldCfgRevisionStr())
    1259              +  QString(" - " VBOX_BLEEDING_EDGE);
    1260 #endif /* VBOX_BLEEDING_EDGE */
    1261     setWindowTitle(strTitle);
    1262 
    1263     /* Make sure chosen item fetched: */
    1264     sltHandleChooserPaneIndexChange(false /* update details? */, false /* update snapshots? */, false /* update the logviewer? */);
    1265 
    1266 #ifdef VBOX_WS_MAC
    1267     // WORKAROUND:
    1268     // There is a bug in Qt Cocoa which result in showing a "more arrow" when
    1269     // the necessary size of the toolbar is increased. Also for some languages
    1270     // the with doesn't match if the text increase. So manually adjust the size
    1271     // after changing the text.
    1272     m_pToolBar->updateLayout();
    1273 #endif
    1274 }
    1275 
    1276 bool UIVirtualBoxManager::event(QEvent *pEvent)
    1277 {
    1278     /* Which event do we have? */
    1279     switch (pEvent->type())
    1280     {
    1281         /* Handle every ScreenChangeInternal event to notify listeners: */
    1282         case QEvent::ScreenChangeInternal:
    1283         {
    1284             emit sigWindowRemapped();
    1285             break;
    1286         }
    1287         /* Handle every Resize and Move we keep track of the geometry. */
    1288         case QEvent::Resize:
    1289         {
    1290 #ifdef VBOX_WS_X11
    1291             /* Prevent handling if fake screen detected: */
    1292             if (gpDesktop->isFakeScreenDetected())
    1293                 break;
    1294 #endif /* VBOX_WS_X11 */
    1295 
    1296             if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
    1297             {
    1298                 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
    1299                 m_geometry.setSize(pResizeEvent->size());
    1300             }
    1301             break;
    1302         }
    1303         case QEvent::Move:
    1304         {
    1305 #ifdef VBOX_WS_X11
    1306             /* Prevent handling if fake screen detected: */
    1307             if (gpDesktop->isFakeScreenDetected())
    1308                 break;
    1309 #endif /* VBOX_WS_X11 */
    1310 
    1311             if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
    1312             {
    1313 #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
    1314                 QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent);
    1315                 m_geometry.moveTo(pMoveEvent->pos());
    1316 #else /* !VBOX_WS_MAC && !VBOX_WS_WIN */
    1317                 m_geometry.moveTo(geometry().x(), geometry().y());
    1318 #endif /* !VBOX_WS_MAC && !VBOX_WS_WIN */
    1319             }
    1320             break;
    1321         }
    1322 #ifdef VBOX_WS_MAC
    1323         case QEvent::ContextMenu:
    1324         {
    1325             /* This is the unified context menu event. Lets show the context menu. */
    1326             QContextMenuEvent *pContextMenuEvent = static_cast<QContextMenuEvent*>(pEvent);
    1327             sltHandleContextMenuRequest(pContextMenuEvent->globalPos());
    1328             /* Accept it to interrupt the chain. */
    1329             pContextMenuEvent->accept();
    1330             return false;
    1331             break;
    1332         }
    1333 #endif /* VBOX_WS_MAC */
    1334         default:
    1335             break;
    1336     }
    1337     /* Call to base-class: */
    1338     return QIMainWindow::event(pEvent);
    1339 }
    1340 
    1341 void UIVirtualBoxManager::showEvent(QShowEvent *pEvent)
    1342 {
    1343     /* Call to base-class: */
    1344     QIMainWindow::showEvent(pEvent);
    1345 
    1346     /* Is polishing required? */
    1347     if (!m_fPolished)
    1348     {
    1349         /* Pass the show-event to polish-event: */
    1350         polishEvent(pEvent);
    1351         /* Mark as polished: */
    1352         m_fPolished = true;
    1353     }
    1354 }
    1355 
    1356 void UIVirtualBoxManager::polishEvent(QShowEvent*)
    1357 {
    1358     /* Make sure user warned about inaccessible medium(s)
    1359      * even if enumeration had finished before selector window shown: */
    1360     QTimer::singleShot(0, this, SLOT(sltHandleMediumEnumerationFinish()));
    1361 
    1362     /* Call for async polishing: */
    1363     QMetaObject::invokeMethod(this, "sltHandlePolishEvent", Qt::QueuedConnection);
    1364 }
    1365 
    1366 #ifdef VBOX_WS_MAC
    1367 bool UIVirtualBoxManager::eventFilter(QObject *pObject, QEvent *pEvent)
    1368 {
    1369     /* Ignore for non-active window except for FileOpen event which should be always processed: */
    1370     if (!isActiveWindow() && pEvent->type() != QEvent::FileOpen)
    1371         return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
    1372 
    1373     /* Ignore for other objects: */
    1374     if (qobject_cast<QWidget*>(pObject) &&
    1375         qobject_cast<QWidget*>(pObject)->window() != this)
    1376         return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
    1377 
    1378     /* Which event do we have? */
    1379     switch (pEvent->type())
    1380     {
    1381         case QEvent::FileOpen:
    1382         {
    1383             sltHandleOpenUrlCall(QList<QUrl>() << static_cast<QFileOpenEvent*>(pEvent)->url());
    1384             pEvent->accept();
    1385             return true;
    1386             break;
    1387         }
    1388         default:
    1389             break;
    1390     }
    1391     /* Call to base-class: */
    1392     return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
    1393 }
    1394 #endif /* VBOX_WS_MAC */
    1395 
    1396 void UIVirtualBoxManager::closeEvent(QCloseEvent *pEvent)
    1397 {
    1398     /* Call to base-class: */
    1399     QIWithRetranslateUI<QIMainWindow>::closeEvent(pEvent);
    1400 
    1401     /* Quit application: */
    1402     QApplication::quit();
    14031403}
    14041404
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r73450 r73451  
    7777    virtual bool shouldBeMaximized() const /* override */;
    7878
     79    /** @name Event handling stuff.
     80      * @{ */
     81#ifdef VBOX_WS_MAC
     82        /** Mac OS X: Preprocesses any @a pEvent for passed @a pObject. */
     83        virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     84#endif
     85
     86        /** Handles translation event. */
     87        virtual void retranslateUi() /* override */;
     88
     89        /** Handles any Qt @a pEvent. */
     90        virtual bool event(QEvent *pEvent) /* override */;
     91        /** Handles show @a pEvent. */
     92        virtual void showEvent(QShowEvent *pEvent) /* override */;
     93        /** Handles first show @a pEvent. */
     94        virtual void polishEvent(QShowEvent *pEvent) /* override */;
     95        /** Handles close @a pEvent. */
     96        virtual void closeEvent(QCloseEvent *pEvent) /* override */;
     97    /** @} */
     98
    7999private slots:
    80100
     
    240260    /** Returns a list of current-items. */
    241261    QList<UIVirtualMachineItem*> currentItems() const;
    242 
    243     /** @name Event handling stuff.
    244       * @{ */
    245         /** Handles translation event. */
    246         virtual void retranslateUi() /* override */;
    247 
    248         /** Handles any Qt @a pEvent. */
    249         virtual bool event(QEvent *pEvent) /* override */;
    250         /** Handles show @a pEvent. */
    251         virtual void showEvent(QShowEvent *pEvent) /* override */;
    252         /** Handles first show @a pEvent. */
    253         virtual void polishEvent(QShowEvent *pEvent) /* override */;
    254 #ifdef VBOX_WS_MAC
    255         /** Mac OS X: Preprocesses any @a pEvent for passed @a pObject. */
    256         virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
    257 #endif
    258         /** Handles close @a pEvent. */
    259         virtual void closeEvent(QCloseEvent *pEvent) /* override */;
    260     /** @} */
    261262
    262263    /** @name Prepare/Cleanup cascade.
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