VirtualBox

Changeset 88520 in vbox


Ignore:
Timestamp:
Apr 15, 2021 10:34:10 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8161: A bit of rework for VirtualBox Manager widget; Saving toolbar and splitter settings instantly on change to avoid doing that on app shutdown.

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

Legend:

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

    r88242 r88520  
    55
    66/*
    7  * Copyright (C) 2006-2020 Oracle Corporation
     7 * Copyright (C) 2006-2021 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#include <QStackedWidget>
    2121#include <QStyle>
     22#include <QTimer>
    2223#include <QToolButton>
    2324#include <QVBoxLayout>
     
    5455    , m_enmSelectionType(SelectionType_Invalid)
    5556    , m_fSelectedMachineItemAccessible(false)
     57    , m_pSplitterSettingsSaveTimer(0)
    5658{
    5759    prepare();
     
    282284    /* Add 'Show Toolbar Text' action: */
    283285    QAction *pShowToolBarText = new QAction(UIVirtualBoxManager::tr("Show Toolbar Text"), 0);
    284     AssertPtrReturnVoid(pShowToolBarText);
    285     {
    286         /* Configure action: */
     286    if (pShowToolBarText)
     287    {
    287288        pShowToolBarText->setCheckable(true);
    288289        pShowToolBarText->setChecked(m_pToolBar->toolButtonStyle() == Qt::ToolButtonTextUnderIcon);
    289 
    290         /* Add into action list: */
    291290        actions << pShowToolBarText;
    292291    }
     
    294293    /* Prepare the menu position: */
    295294    QPoint globalPosition = position;
    296     QWidget *pSender = static_cast<QWidget*>(sender());
     295    QWidget *pSender = qobject_cast<QWidget*>(sender());
    297296    if (pSender)
    298297        globalPosition = pSender->mapToGlobal(position);
     
    307306                                       ? Qt::ToolButtonTextUnderIcon
    308307                                       : Qt::ToolButtonIconOnly);
     308        gEDataManager->setSelectorWindowToolBarTextVisible(pResult->isChecked());
    309309    }
    310310}
     
    330330    if (isMachineItemSelected() || isGroupItemSelected())
    331331        recacheCurrentItemInformation();
     332}
     333
     334void UIVirtualBoxManagerWidget::sltHandleSplitterMove()
     335{
     336    /* Create timer if isn't exist already: */
     337    if (!m_pSplitterSettingsSaveTimer)
     338    {
     339        m_pSplitterSettingsSaveTimer = new QTimer(this);
     340        if (m_pSplitterSettingsSaveTimer)
     341        {
     342            m_pSplitterSettingsSaveTimer->setInterval(300);
     343            m_pSplitterSettingsSaveTimer->setSingleShot(true);
     344            connect(m_pSplitterSettingsSaveTimer, &QTimer::timeout,
     345                    this, &UIVirtualBoxManagerWidget::sltSaveSplitterSettings);
     346        }
     347    }
     348    /* [Re]start timer finally: */
     349    m_pSplitterSettingsSaveTimer->start();
     350}
     351
     352void UIVirtualBoxManagerWidget::sltSaveSplitterSettings()
     353{
     354    const QList<int> splitterSizes = m_pSplitter->sizes();
     355    LogRel2(("GUI: UIVirtualBoxManagerWidget: Saving splitter as: Size=%d,%d\n",
     356             splitterSizes.at(0), splitterSizes.at(1)));
     357    gEDataManager->setSelectorWindowSplitterHints(splitterSizes);
    332358}
    333359
     
    603629#endif
    604630
    605                         /* Add tool-bar into layout: */
     631                        /* Add toolbar into layout: */
    606632                        pLayoutRight->addWidget(m_pToolBar);
    607633                    }
     
    703729    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
    704730            this, &UIVirtualBoxManagerWidget::sltHandleStateChange);
     731
     732    /* Splitter connections: */
     733    connect(m_pSplitter, &QISplitter::splitterMoved,
     734            this, &UIVirtualBoxManagerWidget::sltHandleSplitterMove);
    705735
    706736    /* Tool-bar connections: */
     
    747777    /* Restore splitter handle position: */
    748778    {
    749         /* Read splitter hints: */
    750779        QList<int> sizes = gEDataManager->selectorWindowSplitterHints();
    751780        /* If both hints are zero, we have the 'default' case: */
    752         if (sizes[0] == 0 && sizes[1] == 0)
     781        if (sizes.at(0) == 0 && sizes.at(1) == 0)
    753782        {
    754             /* Propose some 'default' based on current dialog width: */
    755783            sizes[0] = (int)(width() * .9 * (1.0 / 3));
    756784            sizes[1] = (int)(width() * .9 * (2.0 / 3));
    757785        }
    758         /* Pass hints to the splitter: */
     786        LogRel2(("GUI: UIVirtualBoxManagerWidget: Restoring splitter to: Size=%d,%d\n",
     787                 sizes.at(0), sizes.at(1)));
    759788        m_pSplitter->setSizes(sizes);
    760789    }
     
    969998}
    970999
    971 void UIVirtualBoxManagerWidget::saveSettings()
    972 {
    973     /* Save toolbar visibility: */
    974     {
    975         gEDataManager->setSelectorWindowToolBarVisible(!m_pToolBar->isHidden());
    976         gEDataManager->setSelectorWindowToolBarTextVisible(m_pToolBar->toolButtonStyle() == Qt::ToolButtonTextUnderIcon);
    977     }
    978 
    979     /* Save splitter handle position: */
    980     {
    981         gEDataManager->setSelectorWindowSplitterHints(m_pSplitter->sizes());
    982     }
    983 }
    984 
    9851000void UIVirtualBoxManagerWidget::cleanupConnections()
    9861001{
     
    10261041void UIVirtualBoxManagerWidget::cleanup()
    10271042{
    1028     /* Save settings: */
    1029     saveSettings();
    1030 
    10311043    /* Cleanup everything: */
    10321044    cleanupConnections();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h

    r87516 r88520  
    55
    66/*
    7  * Copyright (C) 2006-2020 Oracle Corporation
     7 * Copyright (C) 2006-2021 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333/* Forward declarations: */
    3434class QStackedWidget;
     35class QTimer;
    3536class QISplitter;
     37class QIToolBar;
    3638class UIActionPool;
    3739class UIChooser;
    3840class UITabBar;
    39 class QIToolBar;
    4041class UITools;
    4142class UIVirtualBoxManager;
     
    241242    /** @} */
    242243
     244    /** @name Splitter stuff.
     245      * @{ */
     246        /** Handles signal about splitter move. */
     247        void sltHandleSplitterMove();
     248        /** Handles request to save splitter settings. */
     249        void sltSaveSplitterSettings();
     250    /** @} */
     251
    243252    /** @name Tool-bar stuff.
    244253      * @{ */
     
    295304        void updateToolbar();
    296305
    297         /** Saves settings. */
    298         void saveSettings();
    299306        /** Cleanups connections. */
    300307        void cleanupConnections();
     
    336343    /** Holds whether the last selected item was accessible. */
    337344    bool           m_fSelectedMachineItemAccessible;
     345
     346    /** Holds the splitter settings save timer. */
     347    QTimer *m_pSplitterSettingsSaveTimer;
    338348};
    339349
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