VirtualBox

Changeset 81257 in vbox


Ignore:
Timestamp:
Oct 14, 2019 1:09:01 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: Reworking QIMainWindow to be QIWithRestorableGeometry template thus allowing to apply that behavior for other than QMainWindow sub-classes.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 deleted
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r81001 r81257  
    785785        src/extensions/QILineEdit.h \
    786786        src/extensions/QIMainDialog.h \
    787         src/extensions/QIMainWindow.h \
    788787        src/extensions/QIManagerDialog.h \
    789788        src/extensions/QIMenu.h \
     
    12671266        src/extensions/QILineEdit.cpp \
    12681267        src/extensions/QIMainDialog.cpp \
    1269         src/extensions/QIMainWindow.cpp \
    12701268        src/extensions/QIManagerDialog.cpp \
    12711269        src/extensions/QIMenu.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r81255 r81257  
    5353# include "QIDialogButtonBox.h"
    5454# include "QIFileDialog.h"
    55 # include "QIMainWindow.h"
    5655# include "QISplitter.h"
    5756# include "QIWidgetValidator.h"
     57# include "QIWithRestorableGeometry.h"
    5858# include "VBoxUtils.h"
    5959# include "UIIconPool.h"
     
    458458
    459459
    460 /** QIMainWindow extension
     460/** QMainWindow extension
    461461  * providing Extra Data Manager with UI features. */
    462 class UIExtraDataManagerWindow : public QIMainWindow
     462class UIExtraDataManagerWindow : public QIWithRestorableGeometry<QMainWindow>
    463463{
    464464    Q_OBJECT;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/QIWithRestorableGeometry.h

    r81256 r81257  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - QIMainWindow class declaration.
     3 * VBox Qt GUI - QIWithRestorableGeometry class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_extensions_QIMainWindow_h
    19 #define FEQT_INCLUDED_SRC_extensions_QIMainWindow_h
     18#ifndef FEQT_INCLUDED_SRC_globals_QIWithRestorableGeometry_h
     19#define FEQT_INCLUDED_SRC_globals_QIWithRestorableGeometry_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    2525#include <QMainWindow>
    2626#include <QRect>
     27#include <QResizeEvent>
    2728
    2829/* GUI includes: */
    2930#include "UILibraryDefs.h"
     31#ifdef VBOX_WS_MAC
     32# include "VBoxUtils-darwin.h"
     33#endif
     34#ifdef VBOX_WS_X11
     35# include "UICommon.h"
     36# include "UIDesktopWidgetWatchdog.h"
     37#endif
    3038
    31 /* Forward declarations: */
    32 class QWidget;
    33 
    34 /** QMainWindow extension providing GUI
    35   * with the extended geometry management support. */
    36 class SHARED_LIBRARY_STUFF QIMainWindow : public QMainWindow
     39/** Template with geometry saving/restoring capabilities. */
     40template <class Base>
     41class QIWithRestorableGeometry : public Base
    3742{
    38     Q_OBJECT;
    39 
    4043public:
    4144
    4245    /** Constructs main window passing @a pParent and @a enmFlags to base-class. */
    43     QIMainWindow(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0);
     46    QIWithRestorableGeometry(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0)
     47        : Base(pParent, enmFlags)
     48    {}
    4449
    4550protected:
    4651
    4752    /** Handles move @a pEvent. */
    48     virtual void moveEvent(QMoveEvent *pEvent) /* override */;
     53    virtual void moveEvent(QMoveEvent *pEvent) /* override */
     54    {
     55        /* Call to base-class: */
     56        QMainWindow::moveEvent(pEvent);
     57
     58#ifdef VBOX_WS_X11
     59        /* Prevent further handling if fake screen detected: */
     60        if (gpDesktop->isFakeScreenDetected())
     61            return;
     62#endif
     63
     64        /* Prevent handling for yet/already invisible window or if window is in minimized state: */
     65        if (isVisible() && (windowState() & Qt::WindowMinimized) == 0)
     66        {
     67#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
     68            /* Use the old approach for OSX/Win: */
     69            m_geometry.moveTo(frameGeometry().x(), frameGeometry().y());
     70#else
     71            /* Use the new approach otherwise: */
     72            m_geometry.moveTo(geometry().x(), geometry().y());
     73#endif
     74        }
     75    }
     76
    4977    /** Handles resize @a pEvent. */
    50     virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     78    virtual void resizeEvent(QResizeEvent *pEvent) /* override */
     79    {
     80        /* Call to base-class: */
     81        QMainWindow::resizeEvent(pEvent);
     82
     83#ifdef VBOX_WS_X11
     84        /* Prevent handling if fake screen detected: */
     85        if (gpDesktop->isFakeScreenDetected())
     86            return;
     87#endif
     88
     89        /* Prevent handling for yet/already invisible window or if window is in minimized state: */
     90        if (isVisible() && (windowState() & Qt::WindowMinimized) == 0)
     91        {
     92            QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
     93            m_geometry.setSize(pResizeEvent->size());
     94        }
     95    }
    5196
    5297    /** Returns whether the window should be maximized when geometry being restored. */
     
    5499
    55100    /** Restores the window geometry to passed @a rect. */
    56     void restoreGeometry(const QRect &rect);
     101    void restoreGeometry(const QRect &rect)
     102    {
     103        m_geometry = rect;
     104#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
     105        /* Use the old approach for OSX/Win: */
     106        move(m_geometry.topLeft());
     107        resize(m_geometry.size());
     108#else
     109        /* Use the new approach otherwise: */
     110        UICommon::setTopLevelGeometry(this, m_geometry);
     111#endif
     112
     113        /* Maximize (if necessary): */
     114        if (shouldBeMaximized())
     115            showMaximized();
     116    }
    57117
    58118    /** Returns current window geometry. */
    59     QRect currentGeometry() const;
     119    QRect currentGeometry() const
     120    {
     121        return m_geometry;
     122    }
     123
    60124    /** Returns whether the window is currently maximized. */
    61     bool isCurrentlyMaximized() const;
     125    bool isCurrentlyMaximized() const
     126    {
     127#ifdef VBOX_WS_MAC
     128        return ::darwinIsWindowMaximized(this);
     129#else
     130        return isMaximized();
     131#endif
     132    }
    62133
    63134private:
     
    67138};
    68139
    69 #endif /* !FEQT_INCLUDED_SRC_extensions_QIMainWindow_h */
     140#endif /* !FEQT_INCLUDED_SRC_globals_QIWithRestorableGeometry_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r81255 r81257  
    128128    /* Ignore for non-active window except for FileOpen event which should be always processed: */
    129129    if (!isActiveWindow() && pEvent->type() != QEvent::FileOpen)
    130         return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     130        return QMainWindowWithRestorableGeometryAndRetranslateUi::eventFilter(pObject, pEvent);
    131131
    132132    /* Ignore for other objects: */
    133133    if (qobject_cast<QWidget*>(pObject) &&
    134134        qobject_cast<QWidget*>(pObject)->window() != this)
    135         return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     135        return QMainWindowWithRestorableGeometryAndRetranslateUi::eventFilter(pObject, pEvent);
    136136
    137137    /* Which event do we have? */
     
    150150
    151151    /* Call to base-class: */
    152     return QIWithRetranslateUI<QIMainWindow>::eventFilter(pObject, pEvent);
     152    return QMainWindowWithRestorableGeometryAndRetranslateUi::eventFilter(pObject, pEvent);
    153153}
    154154#endif /* VBOX_WS_MAC */
     
    184184    }
    185185    /* Call to base-class: */
    186     return QIWithRetranslateUI<QIMainWindow>::event(pEvent);
     186    return QMainWindowWithRestorableGeometryAndRetranslateUi::event(pEvent);
    187187}
    188188
     
    190190{
    191191    /* Call to base-class: */
    192     QIWithRetranslateUI<QIMainWindow>::showEvent(pEvent);
     192    QMainWindowWithRestorableGeometryAndRetranslateUi::showEvent(pEvent);
    193193
    194194    /* Is polishing required? */
     
    211211{
    212212    /* Call to base-class: */
    213     QIWithRetranslateUI<QIMainWindow>::closeEvent(pEvent);
     213    QMainWindowWithRestorableGeometryAndRetranslateUi::closeEvent(pEvent);
    214214
    215215    /* Quit application: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r81248 r81257  
    2323
    2424/* Qt includes: */
     25#include <QMainWindow>
    2526#include <QUrl>
    2627
    2728/* GUI includes: */
    28 #include "QIMainWindow.h"
     29#include "QIWithRestorableGeometry.h"
    2930#include "QIWithRetranslateUI.h"
    3031#include "UICommon.h"
     
    3940
    4041/* Type definitions: */
     42typedef QIWithRestorableGeometry<QMainWindow> QMainWindowWithRestorableGeometry;
     43typedef QIWithRetranslateUI<QMainWindowWithRestorableGeometry> QMainWindowWithRestorableGeometryAndRetranslateUi;
    4144typedef QMap<QString, QIManagerDialog*> VMLogViewerMap;
    4245
    43 /** Singleton QIMainWindow extension used as VirtualBox Manager instance. */
    44 class UIVirtualBoxManager : public QIWithRetranslateUI<QIMainWindow>
     46/** Singleton QMainWindow extension used as VirtualBox Manager instance. */
     47class UIVirtualBoxManager : public QMainWindowWithRestorableGeometryAndRetranslateUi
    4548{
    4649    Q_OBJECT;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r81255 r81257  
    7979
    8080UIVMInformationDialog::UIVMInformationDialog(UIMachineWindow *pMachineWindow)
    81     : QIWithRetranslateUI<QIMainWindow>(0)
     81    : QMainWindowWithRestorableGeometryAndRetranslateUi(0)
    8282    , m_pTabWidget(0)
    8383    , m_pMachineWindow(pMachineWindow)
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.h

    r81248 r81257  
    2222#endif
    2323
     24/* Qt includes: */
     25#include <QMainWindow>
     26
    2427/* GUI includes: */
    25 #include "QIMainWindow.h"
     28#include "QIWithRestorableGeometry.h"
    2629#include "QIWithRetranslateUI.h"
    2730
     
    3538class UIMachineWindow;
    3639
     40/* Type definitions: */
     41typedef QIWithRestorableGeometry<QMainWindow> QMainWindowWithRestorableGeometry;
     42typedef QIWithRetranslateUI<QMainWindowWithRestorableGeometry> QMainWindowWithRestorableGeometryAndRetranslateUi;
    3743
    38 /** QIMainWindow subclass providing user
     44
     45/** QMainWindow subclass providing user
    3946  * with the dialog unifying VM details and statistics. */
    40 class UIVMInformationDialog : public QIWithRetranslateUI<QIMainWindow>
     47class UIVMInformationDialog : public QMainWindowWithRestorableGeometryAndRetranslateUi
    4148{
    4249    Q_OBJECT;
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