VirtualBox

Changeset 57496 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 21, 2015 1:17:10 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: 7961: LogWindow: Increasing default size and saving/restoring previous geometry.

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

Legend:

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

    r57484 r57496  
    2929# include <QScrollBar>
    3030# include <QTextEdit>
     31# include <QDesktopWidget>
    3132
    3233/* GUI includes: */
     
    3839# include "UIMessageCenter.h"
    3940# include "VBoxUtils.h"
     41# include "UIExtraDataManager.h"
    4042
    4143/* COM includes: */
     
    412414    refresh();
    413415
     416    /* Load settings: */
     417    loadSettings();
     418
    414419    /* Loading language constants */
    415420    retranslateUi();
     
    418423UIVMLogViewer::~UIVMLogViewer()
    419424{
     425    /* Save settings: */
     426    saveSettings();
     427
    420428    if (!m_machine.isNull())
    421429        m_viewers.remove(m_machine.GetName());
     
    564572        return;
    565573
    566     m_fIsPolished = true;
    567 
    568     /* Resize the whole log-viewer to fit 80 symbols in
    569      * text-browser for the first time started: */
    570     QTextEdit *pFirstPage = currentLogPage();
    571     if (pFirstPage)
    572     {
    573         int fullWidth = pFirstPage->fontMetrics().width(QChar('x')) * 80 +
    574                         pFirstPage->verticalScrollBar()->width() +
    575                         pFirstPage->frameWidth() * 2 +
    576                         /* m_pViewerContainer margin */ 10 * 2 +
    577                         /* CentralWidget margin */ 10 * 2;
    578         resize(fullWidth, height());
    579     }
     574    m_fIsPolished = true;   
    580575
    581576    /* Make sure the log view widget has the focus */
    582577    QWidget *pCurrentLogPage = currentLogPage();
    583578    if (pCurrentLogPage)
    584         pCurrentLogPage->setFocus();
    585 
    586     /* Explicit widget centering relatively to it's parent: */
    587     VBoxGlobal::centerWidget(this, parentWidget(), false);
     579        pCurrentLogPage->setFocus();
    588580}
    589581
     
    644636}
    645637
     638void UIVMLogViewer::loadSettings()
     639{
     640    /* Restore window geometry: */
     641    {
     642        /* Getting available geometry to calculate default geometry: */
     643        const QRect desktopRect = QApplication::desktop()->availableGeometry(this);
     644        int iDefaultWidth = desktopRect.width() * 0.5;
     645        int iDefaultHeight = desktopRect.height() * 0.75;
     646
     647        /* Calculate default width to fit 132 characters: */
     648        QTextEdit *pCurrentLogPage = currentLogPage();
     649        if (pCurrentLogPage)
     650        {
     651            iDefaultWidth = pCurrentLogPage->fontMetrics().width(QChar('x')) * 132 +
     652                pCurrentLogPage->verticalScrollBar()->width() +
     653                pCurrentLogPage->frameWidth() * 2 +
     654                /* m_pViewerContainer margin */ 10 * 2 +
     655                /* CentralWidget margin */ 10 * 2;
     656        }
     657        QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight);
     658        defaultGeometry.moveCenter(parentWidget()->geometry().center());
     659
     660        /* Load geometry: */
     661        m_geometry = gEDataManager->logWindowGeometry(this, defaultGeometry);
     662#ifdef Q_WS_MAC
     663        move(m_geometry.topLeft());
     664        resize(m_geometry.size());
     665#else /* Q_WS_MAC */
     666        setGeometry(m_geometry);
     667#endif /* !Q_WS_MAC */
     668        LogRel(("GUI: UIVMLogViewer: Geometry loaded to: %dx%d @ %dx%d\n",
     669                m_geometry.x(), m_geometry.y(), m_geometry.width(), m_geometry.height()));
     670
     671        /* Maximize (if necessary): */
     672        if (gEDataManager->logWindowShouldBeMaximized())
     673            showMaximized();
     674    }
     675}
     676
     677void UIVMLogViewer::saveSettings()
     678{
     679    /* Save window geometry: */
     680    {
     681        /* Save geometry: */
     682        const QRect save_geometry = geometry();
     683#ifdef Q_WS_MAC
     684        gEDataManager->setLogWindowGeometry(save_geometry, ::darwinIsWindowMaximized(this));
     685#else /* Q_WS_MAC */
     686        gEDataManager->setLogWindowGeometry(save_geometry, isMaximized());
     687#endif /* !Q_WS_MAC */
     688        LogRel(("GUI: UIVMLogViewer: Geometry saved as: %dx%d @ %dx%d\n",
     689                save_geometry.x(), save_geometry.y(), save_geometry.width(), save_geometry.height()));
     690    }
     691}
     692
    646693#include "UIVMLogViewer.moc"
    647694
  • trunk/src/VBox/Frontends/VirtualBox/src/UIVMLogViewer.h

    r55401 r57496  
    8282    QTextEdit* createLogPage(const QString &strPage);
    8383
     84    /** Load settings helper. */
     85    void loadSettings();
     86
     87    /** Save settings helper. */
     88    void saveSettings();
     89
    8490    /* Array containing all VM Log Viewers: */
    8591    static VMLogViewerMap m_viewers;
     
    9197    UIVMLogViewerSearchPanel *m_pSearchPanel;
    9298    LogBook m_book;
     99
     100    /** Current dialog geometry. */
     101    QRect m_geometry;
    93102
    94103    /* Buttons: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp

    r56704 r57496  
    165165#endif /* DEBUG */
    166166
     167/* Virtual Machine: Logging dialog: */
     168const char* UIExtraDataDefs::GUI_LogWindowGeometry = "GUI/LogWindowGeometry";
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r56704 r57496  
    287287    /** @} */
    288288#endif /* DEBUG */
     289
     290        /** Holds log-window geometry. */
     291        extern const char* GUI_LogWindowGeometry;
    289292}
    290293
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r56704 r57496  
    18041804           << GUI_Dbg_Enabled << GUI_Dbg_AutoShow
    18051805#endif /* VBOX_WITH_DEBUGGER_GUI */
    1806            << GUI_ExtraDataManager_Geometry << GUI_ExtraDataManager_SplitterHints;
     1806           << GUI_ExtraDataManager_Geometry << GUI_ExtraDataManager_SplitterHints
     1807           << GUI_LogWindowGeometry;
    18071808}
    18081809#endif /* DEBUG */
     
    36203621}
    36213622#endif /* DEBUG */
     3623
     3624QRect UIExtraDataManager::logWindowGeometry(QWidget *pWidget, const QRect &defaultGeometry)
     3625{
     3626    /* Get corresponding extra-data: */
     3627    const QStringList data = extraDataStringList(GUI_LogWindowGeometry);
     3628
     3629    /* Parse loaded data: */
     3630    int iX = 0, iY = 0, iW = 0, iH = 0;
     3631    bool fOk = data.size() >= 4;   
     3632    do
     3633    {
     3634        if (!fOk) break;
     3635        iX = data[0].toInt(&fOk);
     3636        if (!fOk) break;
     3637        iY = data[1].toInt(&fOk);
     3638        if (!fOk) break;
     3639        iW = data[2].toInt(&fOk);
     3640        if (!fOk) break;
     3641        iH = data[3].toInt(&fOk);
     3642    }
     3643    while (0);
     3644
     3645    /* Use geometry (loaded or default): */
     3646    QRect geometry = fOk ? QRect(iX, iY, iW, iH) : defaultGeometry;
     3647
     3648    /* Take widget into account: */
     3649    if (pWidget)
     3650        geometry.setSize(geometry.size().expandedTo(pWidget->minimumSizeHint()));
     3651
     3652    /* In Windows Qt fails to reposition out of screen window properly, so moving to centre: */
     3653#ifdef Q_WS_WIN
     3654    /* Get screen-geometry [of screen with point (iX, iY) if possible]: */
     3655    const QRect screenGeometry = QApplication::desktop()->availableGeometry(QPoint(iX, iY));
     3656
     3657    /* Make sure resulting geometry is within current bounds: */
     3658    if (!screenGeometry.contains(geometry, true))
     3659        geometry.moveCenter(defaultGeometry.center());
     3660#endif /* Q_WS_WIN */
     3661
     3662    /* Return result: */
     3663    return geometry;
     3664}
     3665
     3666bool UIExtraDataManager::logWindowShouldBeMaximized()
     3667{
     3668    /* Get corresponding extra-data: */
     3669    const QStringList data = extraDataStringList(GUI_LogWindowGeometry);
     3670
     3671    /* Make sure 5th item has required value: */
     3672    return data.size() == 5 && data[4] == GUI_Geometry_State_Max;
     3673}
     3674
     3675void UIExtraDataManager::setLogWindowGeometry(const QRect &geometry, bool fMaximized)
     3676{
     3677    /* Serialize passed values: */
     3678    QStringList data;
     3679    data << QString::number(geometry.x());
     3680    data << QString::number(geometry.y());
     3681    data << QString::number(geometry.width());
     3682    data << QString::number(geometry.height());
     3683    if (fMaximized)
     3684        data << GUI_Geometry_State_Max;
     3685
     3686    /* Re-cache corresponding extra-data: */
     3687    setExtraDataStringList(GUI_LogWindowGeometry, data);
     3688}
    36223689
    36233690void UIExtraDataManager::sltExtraDataChange(QString strMachineID, QString strKey, QString strValue)
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r56704 r57496  
    534534#endif /* DEBUG */
    535535
     536    /** @name Virtual Machine: Logwindow dialog
     537      * @{ */
     538        /** Returns log-window geometry using @a pWidget and @a defaultGeometry as hints. */
     539        QRect logWindowGeometry(QWidget *pWidget, const QRect &defaultGeometry);
     540        /** Returns whether log-window should be maximized or not. */
     541        bool logWindowShouldBeMaximized();
     542        /** Defines log-window @a geometry and @a fMaximized state. */
     543        void setLogWindowGeometry(const QRect &geometry, bool fMaximized);
     544    /** @} */
     545
    536546private slots:
    537547
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