VirtualBox

Changeset 92440 in vbox


Ignore:
Timestamp:
Nov 15, 2021 7:27:42 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10141. Saving and loading medium selector geometry.

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

Legend:

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

    r92437 r92440  
    3636#include "UIMediumSelector.h"
    3737#include "UIMessageCenter.h"
     38#include "UIModalWindowManager.h"
    3839#include "UIIconPool.h"
    3940#include "UIMedium.h"
     
    8182    , m_uMachineID(uMachineID)
    8283    , m_pActionPool(pActionPool)
     84    , m_iGeometrySaveTimerId(-1)
    8385{
    8486    /* Start full medium-enumeration (if necessary): */
     
    8890    finalize();
    8991    selectMedium(uCurrentMediumId);
     92    loadSettings();
    9093}
    9194
     
    128131        m_pTreeWidget->headerItem()->setText(2, tr("Actual Size"));
    129132    }
     133}
     134
     135bool UIMediumSelector::event(QEvent *pEvent)
     136{
     137    if (pEvent->type() == QEvent::Resize || pEvent->type() == QEvent::Move)
     138    {
     139        if (m_iGeometrySaveTimerId != -1)
     140            killTimer(m_iGeometrySaveTimerId);
     141        m_iGeometrySaveTimerId = startTimer(300);
     142    }
     143    else if (pEvent->type() == QEvent::Timer)
     144    {
     145        QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
     146        if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
     147        {
     148            killTimer(m_iGeometrySaveTimerId);
     149            m_iGeometrySaveTimerId = -1;
     150            saveDialogGeometry();
     151        }
     152    }
     153    return QIWithRetranslateUI<QIWithRestorableGeometry<QIMainDialog> >::event(pEvent);
    130154}
    131155
     
    561585    Q_UNUSED(pEvent);
    562586
    563     /* Try to determine the initial size: */
    564     QSize proposedSize;
    565     int iHostScreen = 0;
    566     if (m_pParent)
    567         iHostScreen = gpDesktop->screenNumber(m_pParent);
    568     else
    569         iHostScreen = gpDesktop->screenNumber(this);
    570     if (iHostScreen >= 0 && iHostScreen < gpDesktop->screenCount())
    571     {
    572         /* On the basis of current host-screen geometry if possible: */
    573         const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);
    574         if (screenGeometry.isValid())
    575             proposedSize = screenGeometry.size() / 2.5;
    576     }
    577     /* Fallback to default size if we failed: */
    578     if (proposedSize.isNull())
    579         proposedSize = QSize(800, 600);
    580     /* Resize to initial size: */
    581     resize(proposedSize);
    582 
    583     if (m_pParent)
    584         UIDesktopWidgetWatchdog::centerWidget(this, m_pParent, false);
    585 
    586587    if (m_pTreeWidget)
    587588        m_pTreeWidget->setFocus();
     
    722723    }
    723724}
     725
     726void UIMediumSelector::saveDialogGeometry()
     727{
     728    const QRect geo = currentGeometry();
     729    LogRel2(("GUI: UIMediumSelector: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
     730             geo.x(), geo.y(), geo.width(), geo.height()));
     731    gEDataManager->setMediumSelectorDialogGeometry(geo, isCurrentlyMaximized());
     732}
     733
     734void UIMediumSelector::loadSettings()
     735{
     736    const QRect availableGeo = gpDesktop->availableGeometry(this);
     737    int iDefaultWidth = availableGeo.width() / 2;
     738    int iDefaultHeight = availableGeo.height() * 3 / 4;
     739    QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
     740
     741    QWidget *pParent = windowManager().realParentWindow(m_pParent ? m_pParent : windowManager().mainWindowShown());
     742    /* Load geometry from extradata: */
     743    const QRect geo = gEDataManager->mediumSelectorDialogGeometry(this, pParent, defaultGeo);
     744    LogRel2(("GUI: UISoftKeyboard: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
     745             geo.x(), geo.y(), geo.width(), geo.height()));
     746
     747    restoreGeometry(geo);
     748}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h

    r92437 r92440  
    6969protected:
    7070
    71     void showEvent(QShowEvent *pEvent);
    72 
     71    /** @name Event-handling stuff.
     72      * @{ */
     73        /** Handles translation event. */
     74        virtual void retranslateUi() final override;
     75        void showEvent(QShowEvent *pEvent) final override;
     76        bool event(QEvent *pEvent) final override;
     77    /** @} */
    7378
    7479private slots:
     
    9297
    9398private:
    94 
    95 
    96     /** @name Event-handling stuff.
    97       * @{ */
    98         /** Handles translation event. */
    99         virtual void retranslateUi() /* override */;
    100     /** @} */
    10199
    102100    /** @name Prepare/cleanup cascade.
     
    124122    void          selectMedium(const QUuid &uMediumID);
    125123    void          setTitle();
     124    void          saveDialogGeometry();
     125    void          loadSettings();
    126126    QWidget              *m_pCentralWidget;
    127127    QVBoxLayout          *m_pMainLayout;
     
    156156    QUuid                 m_uCurrentMediumId;
    157157    UIActionPool         *m_pActionPool;
     158    int                   m_iGeometrySaveTimerId;
    158159};
    159160
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