VirtualBox

Changeset 51665 in vbox for trunk/src


Ignore:
Timestamp:
Jun 19, 2014 12:28:48 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 6660: Advanced extra-data management framework: Integrate GUI_Geometry_InformationWindow.

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

Legend:

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

    r51476 r51665  
    2727/* GUI includes: */
    2828#include "UIVMInfoDialog.h"
     29#include "UIExtraDataManager.h"
    2930#include "UISession.h"
    3031#include "UIMachineLogic.h"
     
    3334#include "UIConverter.h"
    3435#include "UIIconPool.h"
     36#include "QITabWidget.h"
     37#include "QIDialogButtonBox.h"
    3538#include "VBoxGlobal.h"
    36 #include "QITabWidget.h"
    3739#include "VBoxUtils.h"
    38 #include "QIDialogButtonBox.h"
    3940
    4041/* COM includes: */
     
    8182    : QIWithRetranslateUI<QMainWindow>(0)
    8283    , m_pMachineWindow(pMachineWindow)
    83     , m_fIsPolished(false)
    84     , m_iWidth(0), m_iHeight(0), m_fMax(false)
    8584    , m_pTabWidget(0)
    8685    , m_session(pMachineWindow->session())
     
    276275    switch (pEvent->type())
    277276    {
    278         /* Store window state for this VM: */
    279         case QEvent::WindowStateChange:
    280         {
    281             if (m_fIsPolished)
    282                 m_fMax = isMaximized();
     277        /* Handle every Resize and Move we keep track of the geometry. */
     278        case QEvent::Resize:
     279        {
     280            if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
     281            {
     282                QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
     283                m_geometry.setSize(pResizeEvent->size());
     284            }
     285            break;
     286        }
     287        case QEvent::Move:
     288        {
     289            if (isVisible() && (windowState() & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen)) == 0)
     290            {
     291#ifdef Q_WS_MAC
     292                QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent);
     293                m_geometry.moveTo(pMoveEvent->pos());
     294#else /* Q_WS_MAC */
     295                m_geometry.moveTo(geometry().x(), geometry().y());
     296#endif /* !Q_WS_MAC */
     297            }
    283298            break;
    284299        }
     
    289304    /* Return result: */
    290305    return fResult;
    291 }
    292 
    293 void UIVMInfoDialog::resizeEvent(QResizeEvent *pEvent)
    294 {
    295     /* Pre-process through base-class: */
    296     QMainWindow::resizeEvent(pEvent);
    297 
    298     /* Store dialog size for this VM: */
    299     if (m_fIsPolished && !isMaximized())
    300     {
    301         m_iWidth = width();
    302         m_iHeight = height();
    303     }
    304 }
    305 
    306 void UIVMInfoDialog::showEvent(QShowEvent *pEvent)
    307 {
    308     /* One may think that QWidget::polish() is the right place to do things
    309      * below, but apparently, by the time when QWidget::polish() is called,
    310      * the widget style & layout are not fully done, at least the minimum
    311      * size hint is not properly calculated. Since this is sometimes necessary,
    312      * we provide our own "polish" implementation */
    313     if (!m_fIsPolished)
    314     {
    315         /* Mark as polished: */
    316         m_fIsPolished = true;
    317 
    318         /* Load window size, adjust position and load window state finally: */
    319         resize(m_iWidth, m_iHeight);
    320         vboxGlobal().centerWidget(this, m_pMachineWindow, false);
    321         if (m_fMax)
    322             QTimer::singleShot(0, this, SLOT(showMaximized()));
    323     }
    324 
    325     /* Post-process through base-class: */
    326     QMainWindow::showEvent(pEvent);
    327306}
    328307
     
    486465void UIVMInfoDialog::loadSettings()
    487466{
    488     /* Load dialog geometry: */
    489     QString strSize = m_session.GetMachine().GetExtraData(GUI_InfoDlgState);
    490     if (strSize.isEmpty())
    491     {
    492         m_iWidth = 400;
    493         m_iHeight = 450;
    494         m_fMax = false;
    495     }
    496     else
    497     {
    498         QStringList list = strSize.split(',');
    499         m_iWidth = list[0].toInt(), m_iHeight = list[1].toInt();
    500         m_fMax = list[2] == "max";
     467    /* Restore window geometry: */
     468    {
     469        /* Load geometry: */
     470        m_geometry = gEDataManager->informationWindowGeometry(this, m_pMachineWindow, vboxGlobal().managedVMUuid());
     471#ifdef Q_WS_MAC
     472        move(m_geometry.topLeft());
     473        resize(m_geometry.size());
     474#else /* Q_WS_MAC */
     475        setGeometry(m_geometry);
     476#endif /* !Q_WS_MAC */
     477        LogRel(("UIVMInfoDialog: Geometry loaded to: %dx%d @ %dx%d.\n",
     478                m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height()));
     479
     480        /* Maximize (if necessary): */
     481        if (gEDataManager->isInformationWindowShouldBeMaximized(vboxGlobal().managedVMUuid()))
     482            showMaximized();
    501483    }
    502484}
     
    504486void UIVMInfoDialog::saveSettings()
    505487{
    506     /* Save dialog geometry: */
    507     QString strSize("%1,%2,%3");
    508     m_session.GetMachine().SetExtraData(GUI_InfoDlgState,
    509                                         strSize.arg(m_iWidth).arg(m_iHeight).arg(isMaximized() ? "max" : "normal"));
     488    /* Save window geometry: */
     489    {
     490        /* Save geometry: */
     491#ifdef Q_WS_MAC
     492        gEDataManager->setInformationWindowGeometry(m_geometry, ::darwinIsWindowMaximized(this), vboxGlobal().managedVMUuid());
     493#else /* Q_WS_MAC */
     494        gEDataManager->setInformationWindowGeometry(m_geometry, isMaximized(), vboxGlobal().managedVMUuid());
     495#endif /* !Q_WS_MAC */
     496        LogRel(("UIVMInfoDialog: Geometry saved as: %dx%d @ %dx%d.\n",
     497                m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height()));
     498    }
    510499}
    511500
  • trunk/src/VBox/Frontends/VirtualBox/src/UIVMInfoDialog.h

    r51410 r51665  
    6565    /** Common event-handler. */
    6666    bool event(QEvent *pEvent);
    67     /** Resize event-handler. */
    68     void resizeEvent(QResizeEvent *pEvent);
    69     /** Show event-handler. */
    70     void showEvent(QShowEvent *pEvent);
    7167
    7268private slots:
     
    127123    /** Machine-window to center dialog according. */
    128124    UIMachineWindow       *m_pMachineWindow;
    129     /** Whether dialog was polished. */
    130     bool                   m_fIsPolished;
    131     /** @} */
    132 
    133     /** @name Geometry variables.
    134      * @{ */
    135     /** Current dialog width. */
    136     int                m_iWidth;
    137     /** Current dialog height. */
    138     int                m_iHeight;
    139     /** Whether dialog maximized. */
    140     bool               m_fMax;
     125    /** Current dialog geometry. */
     126    QRect                  m_geometry;
    141127    /** @} */
    142128
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp

    r51593 r51665  
    8383const char* UIExtraDataDefs::GUI_LastNormalWindowPosition = "GUI/LastNormalWindowPosition";
    8484const char* UIExtraDataDefs::GUI_LastScaleWindowPosition = "GUI/LastScaleWindowPosition";
    85 const char* UIExtraDataDefs::GUI_LastWindowState_Max = "max";
     85const char* UIExtraDataDefs::GUI_Geometry_State_Max = "max";
    8686const char* UIExtraDataDefs::GUI_LastGuestSizeHint = "GUI/LastGuestSizeHint";
    8787const char* UIExtraDataDefs::GUI_LastGuestSizeHintWasFullscreen = "GUI/LastGuestSizeHintWasFullscreen";
     
    125125const char* UIExtraDataDefs::GUI_CloseActionHook = "GUI/CloseActionHook";
    126126
    127 /* Runtime UI: Information-dialog definitions: */
    128 const char* UIExtraDataDefs::GUI_InfoDlgState = "GUI/InfoDlgState";
     127/* Runtime UI: Information-window definitions: */
     128const char* UIExtraDataDefs::GUI_Geometry_InformationWindow = "GUI/Geometry/InformationWindow";
    129129
    130130#ifdef VBOX_WITH_DEBUGGER_GUI
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r51654 r51665  
    9191    extern const char* GUI_LastNormalWindowPosition;
    9292    extern const char* GUI_LastScaleWindowPosition;
    93     extern const char* GUI_LastWindowState_Max;
     93    extern const char* GUI_Geometry_State_Max;
    9494    extern const char* GUI_LastGuestSizeHint;
    9595    extern const char* GUI_LastGuestSizeHintWasFullscreen;
     
    133133    extern const char* GUI_CloseActionHook;
    134134
    135     /* Runtime UI: Information-dialog declarations: */
    136     extern const char* GUI_InfoDlgState;
     135    /* Runtime UI: Information-window declarations: */
     136    extern const char* GUI_Geometry_InformationWindow;
    137137
    138138#ifdef VBOX_WITH_DEBUGGER_GUI
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r51664 r51665  
    311311}
    312312
    313 QRect UIExtraDataManager::selectorWindowGeometry(QWidget *pHintWidget /* = 0 */) const
     313QRect UIExtraDataManager::selectorWindowGeometry(QWidget *pWidget) const
    314314{
    315315    /* Load corresponding extra-data: */
     
    335335    QRect geometry = fOk ? QRect(iX, iY, iW, iH) : QRect(0, 0, 770, 550);
    336336
    337     /* Take hint-widget into account: */
    338     if (pHintWidget)
    339         geometry.setSize(geometry.size().expandedTo(pHintWidget->minimumSizeHint()));
     337    /* Take widget into account: */
     338    if (pWidget)
     339        geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint()));
    340340
    341341    /* Get screen-geometry [of screen with point (iX, iY) if possible]: */
     
    360360
    361361    /* Make sure 5th item has required value: */
    362     return data.size() == 5 && data[4] == GUI_LastWindowState_Max;
     362    return data.size() == 5 && data[4] == GUI_Geometry_State_Max;
    363363}
    364364
     
    372372    data << QString::number(geometry.height());
    373373    if (fMaximized)
    374         data << GUI_LastWindowState_Max;
     374        data << GUI_Geometry_State_Max;
    375375
    376376    /* Re-cache corresponding extra-data: */
     
    559559
    560560    /* Make sure 5th item has required value: */
    561     return data.size() == 5 && data[4] == GUI_LastWindowState_Max;
     561    return data.size() == 5 && data[4] == GUI_Geometry_State_Max;
    562562}
    563563
     
    580580    data << QString::number(geometry.height());
    581581    if (fMaximized)
    582         data << GUI_LastWindowState_Max;
     582        data << GUI_Geometry_State_Max;
    583583
    584584    /* Re-cache corresponding extra-data: */
     
    912912}
    913913#endif /* !Q_WS_MAC */
     914
     915QRect UIExtraDataManager::informationWindowGeometry(QWidget *pWidget, QWidget *pParentWidget, const QString &strID) const
     916{
     917    /* Load corresponding extra-data: */
     918    const QStringList data = extraDataStringList(GUI_Geometry_InformationWindow, strID);
     919
     920    /* Parse loaded data: */
     921    int iX = 0, iY = 0, iW = 0, iH = 0;
     922    bool fOk = data.size() >= 4;
     923    do
     924    {
     925        if (!fOk) break;
     926        iX = data[0].toInt(&fOk);
     927        if (!fOk) break;
     928        iY = data[1].toInt(&fOk);
     929        if (!fOk) break;
     930        iW = data[2].toInt(&fOk);
     931        if (!fOk) break;
     932        iH = data[3].toInt(&fOk);
     933    }
     934    while (0);
     935
     936    /* Use geometry (loaded or default): */
     937    QRect geometry = fOk ? QRect(iX, iY, iW, iH) : QRect(0, 0, 600, 450);
     938
     939    /* Take hint-widget into account: */
     940    if (pWidget)
     941        geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint()));
     942
     943    /* Get screen-geometry [of screen with point (iX, iY) if possible]: */
     944    const QRect screenGeometry = fOk ? QApplication::desktop()->availableGeometry(QPoint(iX, iY)) :
     945                                       QApplication::desktop()->availableGeometry();
     946
     947    /* Make sure resulting geometry is within current bounds: */
     948    geometry = geometry.intersected(screenGeometry);
     949
     950    /* Move default-geometry to pParentWidget' geometry center: */
     951    if (!fOk && pParentWidget)
     952        geometry.moveCenter(pParentWidget->geometry().center());
     953
     954    /* Return result: */
     955    return geometry;
     956}
     957
     958bool UIExtraDataManager::isInformationWindowShouldBeMaximized(const QString &strID) const
     959{
     960    /* Load corresponding extra-data: */
     961    const QStringList data = extraDataStringList(GUI_Geometry_InformationWindow, strID);
     962
     963    /* Make sure 5th item has required value: */
     964    return data.size() == 5 && data[4] == GUI_Geometry_State_Max;
     965}
     966
     967void UIExtraDataManager::setInformationWindowGeometry(const QRect &geometry, bool fMaximized, const QString &strID)
     968{
     969    /* Serialize passed values: */
     970    QStringList data;
     971    data << QString::number(geometry.x());
     972    data << QString::number(geometry.y());
     973    data << QString::number(geometry.width());
     974    data << QString::number(geometry.height());
     975    if (fMaximized)
     976        data << GUI_Geometry_State_Max;
     977
     978    /* Re-cache corresponding extra-data: */
     979    setExtraDataStringList(GUI_Geometry_InformationWindow, data, strID);
     980}
    914981
    915982GuruMeditationHandlerType UIExtraDataManager::guruMeditationHandlerType(const QString &strID) const
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r51664 r51665  
    131131    void setModeForWizard(WizardType type, WizardMode mode);
    132132
    133     /** Returns selector-window geometry using @a pHintWidget as the hint. */
    134     QRect selectorWindowGeometry(QWidget *pHintWidget = 0) const;
     133    /** Returns selector-window geometry using @a pWidget as the hint. */
     134    QRect selectorWindowGeometry(QWidget *pWidget) const;
    135135    /** Returns whether selector-window should be maximized or not. */
    136136    bool isSelectorWindowShouldBeMaximized() const;
     
    260260#endif /* !Q_WS_MAC */
    261261
     262    /** Returns information-window geometry using @a pWidget and @a pParentWidget as hints. */
     263    QRect informationWindowGeometry(QWidget *pWidget, QWidget *pParentWidget, const QString &strID) const;
     264    /** Returns whether information-window should be maximized or not. */
     265    bool isInformationWindowShouldBeMaximized(const QString &strID) const;
     266    /** Defines information-window geometry to passed @a geometry which is @a fMaximized. */
     267    void setInformationWindowGeometry(const QRect &geometry, bool fMaximized, const QString &strID);
     268
    262269    /** Returns redefined guru-meditation handler type. */
    263270    GuruMeditationHandlerType guruMeditationHandlerType(const QString &strID) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r51540 r51665  
    972972    switch (pEvent->type())
    973973    {
    974         /* By handling every Resize and Move we keep track of the normal
    975          * (non-minimized and non-maximized) window geometry. Shame on Qt
    976          * that it doesn't provide this geometry in its public APIs. */
     974        /* Handle every Resize and Move we keep track of the geometry. */
    977975        case QEvent::Resize:
    978976        {
     
    980978            {
    981979                QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
    982                 m_normalGeo.setSize(pResizeEvent->size());
     980                m_geometry.setSize(pResizeEvent->size());
    983981            }
    984982            break;
     
    990988#ifdef Q_WS_MAC
    991989                QMoveEvent *pMoveEvent = static_cast<QMoveEvent*>(pEvent);
    992                 m_normalGeo.moveTo(pMoveEvent->pos());
     990                m_geometry.moveTo(pMoveEvent->pos());
    993991#else /* Q_WS_MAC */
    994                 m_normalGeo.moveTo(geometry().x(), geometry().y());
     992                m_geometry.moveTo(geometry().x(), geometry().y());
    995993#endif /* !Q_WS_MAC */
    996994            }
     
    15011499void UISelectorWindow::loadSettings()
    15021500{
    1503     /* Restore window position: */
     1501    /* Restore window geometry: */
    15041502    {
    15051503        /* Load geometry: */
    1506         m_normalGeo = gEDataManager->selectorWindowGeometry(this);
    1507 #ifdef Q_WS_MAC
    1508         move(m_normalGeo.topLeft());
    1509         resize(m_normalGeo.size());
     1504        m_geometry = gEDataManager->selectorWindowGeometry(this);
     1505#ifdef Q_WS_MAC
     1506        move(m_geometry.topLeft());
     1507        resize(m_geometry.size());
    15101508#else /* Q_WS_MAC */
    1511         setGeometry(m_normalGeo);
     1509        setGeometry(m_geometry);
    15121510#endif /* !Q_WS_MAC */
    15131511        LogRel(("UISelectorWindow: Geometry loaded to: %dx%d @ %dx%d.\n",
    1514                 m_normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height()));
     1512                m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height()));
    15151513
    15161514        /* Maximize (if necessary): */
     
    15621560    }
    15631561
    1564     /* Save window position: */
    1565     {
    1566 #ifdef Q_WS_MAC
    1567         gEDataManager->setSelectorWindowGeometry(m_normalGeo, ::darwinIsWindowMaximized(this));
     1562    /* Save window geometry: */
     1563    {
     1564#ifdef Q_WS_MAC
     1565        gEDataManager->setSelectorWindowGeometry(m_geometry, ::darwinIsWindowMaximized(this));
    15681566#else /* Q_WS_MAC */
    1569         gEDataManager->setSelectorWindowGeometry(m_normalGeo, isMaximized());
     1567        gEDataManager->setSelectorWindowGeometry(m_geometry, isMaximized());
    15701568#endif /* !Q_WS_MAC */
    15711569        LogRel(("UISelectorWindow: Geometry saved as: %dx%d @ %dx%d.\n",
    1572                 m_normalGeo.x(), m_normalGeo.y(), m_normalGeo.width(), m_normalGeo.height()));
     1570                m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height()));
    15731571    }
    15741572}
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h

    r51453 r51665  
    238238
    239239    /* Other variables: */
    240     QRect m_normalGeo;
     240    QRect m_geometry;
    241241};
    242242
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