VirtualBox

Changeset 70139 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 15, 2017 10:59:25 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: ​bugref:9072 Save/load the geometry of the logviewer dialog to/from extradata

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

Legend:

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

    r70074 r70139  
    108108    /* Center according requested widget: */
    109109    VBoxGlobal::centerWidget(this, pCenterWidget, false);
     110
     111    /* Load the dialog's settings from extradata */
     112    loadSettings();
    110113}
    111114
     
    211214void QIManagerDialog::cleanup()
    212215{
     216    saveSettings();
    213217    /* Cleanup menu-bar: */
    214218    cleanupMenuBar();
     
    223227}
    224228
     229void QIManagerDialog::setDialogGeometry(const QRect &geometry)
     230{
     231#ifdef VBOX_WS_MAC
     232    /* Use the old approach for OSX: */
     233    move(geometry.topLeft());
     234    resize(geometry.size());
     235#else /* VBOX_WS_MAC */
     236    /* Use the new approach for Windows/X11: */
     237    VBoxGlobal::setTopLevelGeometry(this, geometry);
     238#endif /* !VBOX_WS_MAC */
     239
     240    /* Maximize (if necessary): */
     241    if (shouldBeMaximized())
     242        showMaximized();
     243}
     244
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.h

    r69877 r70139  
    124124          * @note Injected into prepare(), reimplement to postprocess all there. */
    125125        virtual void finalize() {}
     126        /** Loads dialog setting such as geometry from extradata. */
     127        virtual void loadSettings() {}
    126128
    127129        /** Cleanup menu-bar.
     
    131133          * @note Normally you don't need to reimplement it. */
    132134        void cleanup();
     135        /** Saves dialog setting such as geometry into extradata. */
     136        virtual void saveSettings() const {}
     137
    133138    /** @} */
    134139
     
    150155        /** Returns button of passed @a enmType. */
    151156        QPushButton *button(ButtonType enmType) { return m_buttons.value(enmType); }
     157        /** Returns center widget. */
     158        QWidget* centerWidget() const { return pCenterWidget; }
    152159    /** @} */
    153160
     
    158165    /** @} */
    159166
     167        /** @name Functions related to geometry restoration.
     168         * @{ */
     169        /* Sets the position and size of the dialog. */
     170        void setDialogGeometry(const QRect &geometry);
     171        /** Returns whether the window should be maximized when geometry being restored. */
     172        virtual bool shouldBeMaximized() const { return false; }
     173        /** @} */
     174
    160175private:
    161176
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp

    r70098 r70139  
    3333
    3434/* GUI includes: */
     35# include "UIDesktopWidgetWatchdog.h"
     36# include "UIExtraDataManager.h"
    3537# include "UIIconPool.h"
    3638# include "UIVMLogViewerDialog.h"
    3739# include "UIVMLogViewerWidget.h"
     40# include "VBoxGlobal.h"
    3841
    3942#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    9497}
    9598
     99void UIVMLogViewerDialog::loadSettings()
     100{
     101    const UIVMLogViewerWidget *pWidget = qobject_cast<const UIVMLogViewerWidget *>(widget());
     102
     103    /* Restore window geometry: */
     104    /* Getting available geometry to calculate default geometry: */
     105    const QRect desktopRect = gpDesktop->availableGeometry(this);
     106    int iDefaultWidth = desktopRect.width() / 2;
     107    int iDefaultHeight = desktopRect.height() * 3 / 4;
     108
     109    /* Try obtain the default width of the current logviewer */
     110    if (pWidget)
     111    {
     112        int width =  pWidget->defaultLogPageWidth();
     113        if (width != 0)
     114            iDefaultWidth = width;
     115    }
     116
     117    QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight);
     118    if (centerWidget())
     119        defaultGeometry.moveCenter(centerWidget()->geometry().center());
     120
     121    /* Load geometry from extradata: */
     122    QRect geometry = gEDataManager->logWindowGeometry(this, defaultGeometry);
     123
     124    /* Restore geometry: */
     125    LogRel2(("GUI: UIVMLogViewer: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
     126             geometry.x(), geometry.y(), geometry.width(), geometry.height()));
     127    setDialogGeometry(geometry);
     128}
     129
     130void UIVMLogViewerDialog::saveSettings() const
     131{
     132    /* Save window geometry to extradata: */
     133    const QRect saveGeometry = geometry();
     134#ifdef VBOX_WS_MAC
     135    gEDataManager->setLogWindowGeometry(saveGeometry, ::darwinIsWindowMaximized(this));
     136#else /* !VBOX_WS_MAC */
     137    gEDataManager->setLogWindowGeometry(saveGeometry, isMaximized());
     138#endif /* !VBOX_WS_MAC */
     139    LogRel2(("GUI: UIVMLogViewer: Geometry saved as: Origin=%dx%d, Size=%dx%d\n",
     140             saveGeometry.x(), saveGeometry.y(), saveGeometry.width(), saveGeometry.height()));
     141}
     142
     143bool UIVMLogViewerDialog::shouldBeMaximized() const
     144{
     145    return gEDataManager->logWindowShouldBeMaximized();
     146}
     147
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h

    r70074 r70139  
    5858
    5959public:
     60
    6061    UIVMLogViewerDialog(QWidget *pCenterWidget, const CMachine &machine);
    6162
    6263protected:
    63     virtual void configure() /* override */;
    64     virtual void configureCentralWidget() /* override */;
    65     virtual void finalize() /* override */;
     64
     65    /** @name Prepare/cleanup cascade.
     66     * @{ */
     67        virtual void configure() /* override */;
     68        virtual void configureCentralWidget() /* override */;
     69        virtual void finalize() /* override */;
     70        virtual void saveSettings() const /* override */;
     71        virtual void loadSettings() /* override */;
     72    /** @} */
     73    /* Reads the related extradata to determine if the dialog should be maximized. */
     74    virtual bool shouldBeMaximized() const /* override */;
    6675
    6776private:
     77
    6878    void retranslateUi();
    6979
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70098 r70139  
    2828# endif
    2929# include <QPlainTextEdit>
     30# include <QScrollBar>
    3031
    3132/* GUI includes: */
     
    7071}
    7172
    72 int UIVMLogViewerWidget::currentLogPagewidth() const
    73 {
    74     if(!currentLogPage())
     73int UIVMLogViewerWidget::defaultLogPageWidth() const
     74{
     75    if(!m_pViewerContainer)
    7576        return 0;
    7677
    77     QTextDocument *pTextDocument = currentLogPage()->document();
    78     if(!pTextDocument)
     78    QWidget *pContainer = m_pViewerContainer->currentWidget();
     79    if(!pContainer)
    7980        return 0;
    80     /* Adjust text-edit size: */
    81     pTextDocument->adjustSize();
    82     /* Get corresponding QTextDocument size: */
    83     QSize textSize = pTextDocument->size().toSize();
    84     return textSize.width();
     81
     82    QPlainTextEdit *pBrowser = pContainer->findChild<QPlainTextEdit*>();
     83    if (!pBrowser)
     84        return 0;
     85    /* Compute a width for 132 characters plus scrollbar and frame width: */
     86    int iDefaultWidth = pBrowser->fontMetrics().width(QChar('x')) * 132 +
     87                        pBrowser->verticalScrollBar()->width() +
     88                        pBrowser->frameWidth() * 2;
     89
     90    return iDefaultWidth;
    8591}
    8692
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70098 r70139  
    5858    ~UIVMLogViewerWidget();
    5959    /* Returns the width of the current log page. return 0 if there is no current log page: */
    60     int currentLogPagewidth() const;
     60    int defaultLogPageWidth() const;
    6161
    6262    /** Returns the menu. */
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