VirtualBox

Changeset 100497 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 11, 2023 7:27:14 AM (17 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9080. Some refactoring.

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

Legend:

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

    r100496 r100497  
    255255
    256256UIVisoCreatorWidget::UIVisoCreatorWidget(UIActionPool *pActionPool, QWidget *pParent,
    257                                          bool fShowToolBar, const QString& strMachineName /* = QString() */)
     257                                         bool fShowToolBar, const QString& strVisoSavePath, const QString& strMachineName)
    258258    : QIWithRetranslateUI<QWidget>(pParent)
    259259    , m_pActionSettings(0)
     
    275275    , m_pBrowserContainerWidget(0)
    276276    , m_pStackedLayout(0)
     277    , m_strVisoSavePath(strVisoSavePath)
    277278{
    278279    m_visoOptions.m_strVisoName = !strMachineName.isEmpty() ? strMachineName : "ad-hoc";
     
    692693}
    693694
     695QString UIVisoCreatorWidget::visoFileFullPath() const
     696{
     697    return QString("%1/%2%3").arg(m_strVisoSavePath).arg(visoName()).arg(".viso");
     698}
     699
     700
     701/*********************************************************************************************************************************
     702*   UIVisoCreatorDialog implementation.                                                                                          *
     703*********************************************************************************************************************************/
     704UIVisoCreatorDialog::UIVisoCreatorDialog(UIActionPool *pActionPool, QWidget *pParent,
     705                                         const QString& strVisoSavePath, const QString& strMachineName /* = QString() */)
     706    : QIWithRetranslateUI<QIWithRestorableGeometry<QIMainDialog> >(pParent)
     707    , m_pVisoCreatorWidget(0)
     708    , m_pButtonBox(0)
     709    , m_pActionPool(pActionPool)
     710    , m_iGeometrySaveTimerId(-1)
     711{
     712    /* Make sure that the base class does not close this dialog upon pressing escape.
     713       we manage escape key here with special casing: */
     714    setRejectByEscape(false);
     715    prepareWidgets(strVisoSavePath, strMachineName);
     716    prepareConnections();
     717    loadSettings();
     718}
     719
     720QStringList  UIVisoCreatorDialog::entryList() const
     721{
     722    if (m_pVisoCreatorWidget)
     723        return m_pVisoCreatorWidget->entryList();
     724    return QStringList();
     725}
     726
     727QString UIVisoCreatorDialog::visoName() const
     728{
     729    if (m_pVisoCreatorWidget)
     730        return m_pVisoCreatorWidget->visoName();
     731    return QString();
     732}
     733
     734QString UIVisoCreatorDialog::importedISOPath() const
     735{
     736    if (m_pVisoCreatorWidget)
     737        return m_pVisoCreatorWidget->importedISOPath();
     738    return QString();
     739}
     740
     741QStringList UIVisoCreatorDialog::customOptions() const
     742{
     743    if (m_pVisoCreatorWidget)
     744        return m_pVisoCreatorWidget->customOptions();
     745    return QStringList();
     746}
     747
     748QString UIVisoCreatorDialog::currentPath() const
     749{
     750    if (m_pVisoCreatorWidget)
     751        return m_pVisoCreatorWidget->currentPath();
     752    return QString();
     753}
     754
     755void    UIVisoCreatorDialog::setCurrentPath(const QString &strPath)
     756{
     757    if (m_pVisoCreatorWidget)
     758        m_pVisoCreatorWidget->setCurrentPath(strPath);
     759}
     760
     761void UIVisoCreatorDialog::prepareWidgets(const QString& strVisoSavePath, const QString &strMachineName)
     762{
     763    QWidget *pCentralWidget = new QWidget;
     764    AssertPtrReturnVoid(pCentralWidget);
     765    setCentralWidget(pCentralWidget);
     766    QVBoxLayout *pMainLayout = new QVBoxLayout;
     767    AssertPtrReturnVoid(pMainLayout);
     768    pCentralWidget->setLayout(pMainLayout);
     769
     770
     771    m_pVisoCreatorWidget = new UIVisoCreatorWidget(m_pActionPool, this, true /* show toolbar */, strVisoSavePath, strMachineName);
     772    AssertPtrReturnVoid(m_pVisoCreatorWidget);
     773    if (m_pVisoCreatorWidget->menu())
     774    {
     775        menuBar()->addMenu(m_pVisoCreatorWidget->menu());
     776        pMainLayout->addWidget(m_pVisoCreatorWidget);
     777        connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigSetCancelButtonShortCut,
     778                this, &UIVisoCreatorDialog::sltSetCancelButtonShortCut);
     779        connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigVisoNameChanged,
     780                this, &UIVisoCreatorDialog::sltVisoNameChanged);
     781        connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigSettingDialogToggle,
     782                this, &UIVisoCreatorDialog::sltSettingDialogToggle);
     783    }
     784
     785    m_pButtonBox = new QIDialogButtonBox;
     786    AssertPtrReturnVoid(m_pButtonBox);
     787    m_pButtonBox->setDoNotPickDefaultButton(true);
     788    m_pButtonBox->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
     789    m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence(Qt::Key_Escape));
     790    pMainLayout->addWidget(m_pButtonBox);
     791
     792    connect(m_pButtonBox->button(QIDialogButtonBox::Help), &QPushButton::pressed,
     793            m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
     794
     795    m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(QKeySequence::HelpContents);
     796
     797    uiCommon().setHelpKeyword(m_pButtonBox->button(QIDialogButtonBox::Help), "create-optical-disk-image");
     798
     799    retranslateUi();
     800}
     801
     802void UIVisoCreatorDialog::prepareConnections()
     803{
     804    if (m_pButtonBox)
     805    {
     806        connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIVisoCreatorDialog::close);
     807        connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIVisoCreatorDialog::accept);
     808    }
     809}
     810
     811void UIVisoCreatorDialog::retranslateUi()
     812{
     813    updateWindowTitle();
     814    if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Ok))
     815    {
     816        m_pButtonBox->button(QDialogButtonBox::Ok)->setText(UIVisoCreatorWidget::tr("C&reate"));
     817        m_pButtonBox->button(QDialogButtonBox::Ok)->setToolTip(UIVisoCreatorWidget::tr("Creates VISO file with the selected content"));
     818    }
     819    if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Help))
     820        m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(UIVisoCreatorWidget::tr("Opens the help browser and navigates to the related section"));
     821    updateWindowTitle();
     822}
     823
     824bool UIVisoCreatorDialog::event(QEvent *pEvent)
     825{
     826    if (pEvent->type() == QEvent::Resize || pEvent->type() == QEvent::Move)
     827    {
     828        if (m_iGeometrySaveTimerId != -1)
     829            killTimer(m_iGeometrySaveTimerId);
     830        m_iGeometrySaveTimerId = startTimer(300);
     831    }
     832    else if (pEvent->type() == QEvent::Timer)
     833    {
     834        QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
     835        if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
     836        {
     837            killTimer(m_iGeometrySaveTimerId);
     838            m_iGeometrySaveTimerId = -1;
     839            saveDialogGeometry();
     840        }
     841    }
     842    return QIWithRetranslateUI<QIWithRestorableGeometry<QIMainDialog> >::event(pEvent);
     843}
     844
     845void UIVisoCreatorDialog::sltSetCancelButtonShortCut(QKeySequence keySequence)
     846{
     847    if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
     848        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(keySequence);
     849}
     850
     851void UIVisoCreatorDialog::sltVisoNameChanged(const QString &strName)
     852{
     853    Q_UNUSED(strName);
     854    updateWindowTitle();
     855}
     856
     857void UIVisoCreatorDialog::sltSettingDialogToggle(bool fIsShown)
     858{
     859    if (m_pButtonBox)
     860        m_pButtonBox->setEnabled(!fIsShown);
     861}
     862
     863void UIVisoCreatorDialog::loadSettings()
     864{
     865    const QRect availableGeo = gpDesktop->availableGeometry(this);
     866    int iDefaultWidth = availableGeo.width() / 2;
     867    int iDefaultHeight = availableGeo.height() * 3 / 4;
     868    QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
     869
     870    QWidget *pParent = windowManager().realParentWindow(parentWidget() ? parentWidget() : windowManager().mainWindowShown());
     871    /* Load geometry from extradata: */
     872    const QRect geo = gEDataManager->visoCreatorDialogGeometry(this, pParent, defaultGeo);
     873    LogRel2(("GUI: UISoftKeyboard: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
     874             geo.x(), geo.y(), geo.width(), geo.height()));
     875
     876    restoreGeometry(geo);
     877}
     878
     879void UIVisoCreatorDialog::saveDialogGeometry()
     880{
     881    const QRect geo = currentGeometry();
     882    LogRel2(("GUI: UIMediumSelector: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
     883             geo.x(), geo.y(), geo.width(), geo.height()));
     884    gEDataManager->setVisoCreatorDialogGeometry(geo, isCurrentlyMaximized());
     885}
     886
     887void UIVisoCreatorDialog::updateWindowTitle()
     888{
     889    setWindowTitle(QString("%1 - %2").arg(UIVisoCreatorWidget::tr("VISO Creator")).arg(visoFileFullPath()));
     890}
     891
     892QString UIVisoCreatorDialog::visoFileFullPath() const
     893{
     894    if (!m_pVisoCreatorWidget)
     895        return QString();
     896    return m_pVisoCreatorWidget->visoFileFullPath();
     897}
     898
    694899/* static */
    695900QUuid UIVisoCreatorDialog::createViso(UIActionPool *pActionPool, QWidget *pParent,
     
    747952
    748953
    749 /*********************************************************************************************************************************
    750 *   UIVisoCreatorDialog implementation.                                                                                          *
    751 *********************************************************************************************************************************/
    752 UIVisoCreatorDialog::UIVisoCreatorDialog(UIActionPool *pActionPool, QWidget *pParent,
    753                                          const QString& strVisoSavePath, const QString& strMachineName /* = QString() */)
    754     : QIWithRetranslateUI<QIWithRestorableGeometry<QIMainDialog> >(pParent)
    755     , m_pVisoCreatorWidget(0)
    756     , m_pButtonBox(0)
    757     , m_pActionPool(pActionPool)
    758     , m_iGeometrySaveTimerId(-1)
    759     , m_strVisoSavePath(strVisoSavePath)
    760 {
    761     /* Make sure that the base class does not close this dialog upon pressing escape.
    762        we manage escape key here with special casing: */
    763     setRejectByEscape(false);
    764     prepareWidgets(strMachineName);
    765     prepareConnections();
    766     loadSettings();
    767 }
    768 
    769 QStringList  UIVisoCreatorDialog::entryList() const
    770 {
    771     if (m_pVisoCreatorWidget)
    772         return m_pVisoCreatorWidget->entryList();
    773     return QStringList();
    774 }
    775 
    776 QString UIVisoCreatorDialog::visoName() const
    777 {
    778     if (m_pVisoCreatorWidget)
    779         return m_pVisoCreatorWidget->visoName();
    780     return QString();
    781 }
    782 
    783 QString UIVisoCreatorDialog::importedISOPath() const
    784 {
    785     if (m_pVisoCreatorWidget)
    786         return m_pVisoCreatorWidget->importedISOPath();
    787     return QString();
    788 }
    789 
    790 QStringList UIVisoCreatorDialog::customOptions() const
    791 {
    792     if (m_pVisoCreatorWidget)
    793         return m_pVisoCreatorWidget->customOptions();
    794     return QStringList();
    795 }
    796 
    797 QString UIVisoCreatorDialog::currentPath() const
    798 {
    799     if (m_pVisoCreatorWidget)
    800         return m_pVisoCreatorWidget->currentPath();
    801     return QString();
    802 }
    803 
    804 void    UIVisoCreatorDialog::setCurrentPath(const QString &strPath)
    805 {
    806     if (m_pVisoCreatorWidget)
    807         m_pVisoCreatorWidget->setCurrentPath(strPath);
    808 }
    809 
    810 void UIVisoCreatorDialog::prepareWidgets(const QString &strMachineName)
    811 {
    812     QWidget *pCentralWidget = new QWidget;
    813     AssertPtrReturnVoid(pCentralWidget);
    814     setCentralWidget(pCentralWidget);
    815     QVBoxLayout *pMainLayout = new QVBoxLayout;
    816     AssertPtrReturnVoid(pMainLayout);
    817     pCentralWidget->setLayout(pMainLayout);
    818 
    819 
    820     m_pVisoCreatorWidget = new UIVisoCreatorWidget(m_pActionPool, this, true /* show toolbar */, strMachineName);
    821     AssertPtrReturnVoid(m_pVisoCreatorWidget);
    822     if (m_pVisoCreatorWidget->menu())
    823     {
    824         menuBar()->addMenu(m_pVisoCreatorWidget->menu());
    825         pMainLayout->addWidget(m_pVisoCreatorWidget);
    826         connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigSetCancelButtonShortCut,
    827                 this, &UIVisoCreatorDialog::sltSetCancelButtonShortCut);
    828         connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigVisoNameChanged,
    829                 this, &UIVisoCreatorDialog::sltVisoNameChanged);
    830         connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigSettingDialogToggle,
    831                 this, &UIVisoCreatorDialog::sltSettingDialogToggle);
    832     }
    833 
    834     m_pButtonBox = new QIDialogButtonBox;
    835     AssertPtrReturnVoid(m_pButtonBox);
    836     m_pButtonBox->setDoNotPickDefaultButton(true);
    837     m_pButtonBox->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
    838     m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence(Qt::Key_Escape));
    839     pMainLayout->addWidget(m_pButtonBox);
    840 
    841     connect(m_pButtonBox->button(QIDialogButtonBox::Help), &QPushButton::pressed,
    842             m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
    843 
    844     m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(QKeySequence::HelpContents);
    845 
    846     uiCommon().setHelpKeyword(m_pButtonBox->button(QIDialogButtonBox::Help), "create-optical-disk-image");
    847 
    848     retranslateUi();
    849 }
    850 
    851 void UIVisoCreatorDialog::prepareConnections()
    852 {
    853     if (m_pButtonBox)
    854     {
    855         connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIVisoCreatorDialog::close);
    856         connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIVisoCreatorDialog::accept);
    857     }
    858 }
    859 
    860 void UIVisoCreatorDialog::retranslateUi()
    861 {
    862     updateWindowTitle();
    863     if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Ok))
    864     {
    865         m_pButtonBox->button(QDialogButtonBox::Ok)->setText(UIVisoCreatorWidget::tr("C&reate"));
    866         m_pButtonBox->button(QDialogButtonBox::Ok)->setToolTip(UIVisoCreatorWidget::tr("Creates VISO file with the selected content"));
    867     }
    868     if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Help))
    869         m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(UIVisoCreatorWidget::tr("Opens the help browser and navigates to the related section"));
    870     updateWindowTitle();
    871 }
    872 
    873 bool UIVisoCreatorDialog::event(QEvent *pEvent)
    874 {
    875     if (pEvent->type() == QEvent::Resize || pEvent->type() == QEvent::Move)
    876     {
    877         if (m_iGeometrySaveTimerId != -1)
    878             killTimer(m_iGeometrySaveTimerId);
    879         m_iGeometrySaveTimerId = startTimer(300);
    880     }
    881     else if (pEvent->type() == QEvent::Timer)
    882     {
    883         QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
    884         if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
    885         {
    886             killTimer(m_iGeometrySaveTimerId);
    887             m_iGeometrySaveTimerId = -1;
    888             saveDialogGeometry();
    889         }
    890     }
    891     return QIWithRetranslateUI<QIWithRestorableGeometry<QIMainDialog> >::event(pEvent);
    892 }
    893 
    894 void UIVisoCreatorDialog::sltSetCancelButtonShortCut(QKeySequence keySequence)
    895 {
    896     if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
    897         m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(keySequence);
    898 }
    899 
    900 void UIVisoCreatorDialog::sltVisoNameChanged(const QString &strName)
    901 {
    902     Q_UNUSED(strName);
    903     updateWindowTitle();
    904 }
    905 
    906 void UIVisoCreatorDialog::sltSettingDialogToggle(bool fIsShown)
    907 {
    908     if (m_pButtonBox)
    909         m_pButtonBox->setEnabled(!fIsShown);
    910 }
    911 
    912 void UIVisoCreatorDialog::loadSettings()
    913 {
    914     const QRect availableGeo = gpDesktop->availableGeometry(this);
    915     int iDefaultWidth = availableGeo.width() / 2;
    916     int iDefaultHeight = availableGeo.height() * 3 / 4;
    917     QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
    918 
    919     QWidget *pParent = windowManager().realParentWindow(parentWidget() ? parentWidget() : windowManager().mainWindowShown());
    920     /* Load geometry from extradata: */
    921     const QRect geo = gEDataManager->visoCreatorDialogGeometry(this, pParent, defaultGeo);
    922     LogRel2(("GUI: UISoftKeyboard: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
    923              geo.x(), geo.y(), geo.width(), geo.height()));
    924 
    925     restoreGeometry(geo);
    926 }
    927 
    928 void UIVisoCreatorDialog::saveDialogGeometry()
    929 {
    930     const QRect geo = currentGeometry();
    931     LogRel2(("GUI: UIMediumSelector: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
    932              geo.x(), geo.y(), geo.width(), geo.height()));
    933     gEDataManager->setVisoCreatorDialogGeometry(geo, isCurrentlyMaximized());
    934 }
    935 
    936 void UIVisoCreatorDialog::updateWindowTitle()
    937 {
    938     setWindowTitle(QString("%1 - %2").arg(UIVisoCreatorWidget::tr("VISO Creator")).arg(visoFileFullPath()));
    939 }
    940 
    941 QString UIVisoCreatorDialog::visoFileFullPath() const
    942 {
    943     return QString("%1/%2%3").arg(m_strVisoSavePath).arg(visoName()).arg(".viso");
    944 }
    945 
    946954#include "UIVisoCreator.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h

    r100496 r100497  
    8686
    8787    UIVisoCreatorWidget(UIActionPool *pActionPool, QWidget *pParent,
    88                         bool fShowToolBar, const QString& strMachineName = QString());
     88                        bool fShowToolBar, const QString& strVisoSavePath, const QString& strMachineName);
    8989    /** Returns the content of the .viso file. Each element of the list corresponds to a line in the .viso file. */
    9090    QStringList       entryList() const;
     
    9797    void    setCurrentPath(const QString &strPath);
    9898    QMenu *menu() const;
     99    QString visoFileFullPath() const;
    99100
    100101#ifdef VBOX_WS_MAC
     
    165166    QGraphicsBlurEffect   *m_pOverlayBlurEffect;
    166167    QStackedLayout        *m_pStackedLayout;
     168    QString                m_strVisoSavePath;
    167169};
    168170
     
    204206
    205207private:
    206     void prepareWidgets(const QString &strMachineName);
     208    void prepareWidgets(const QString& strVisoSavePath, const QString &strMachineName);
    207209    void prepareConnections();
    208210    virtual void retranslateUi() final override;
     
    215217    QPointer<UIActionPool> m_pActionPool;
    216218    int                  m_iGeometrySaveTimerId;
    217     QString              m_strVisoSavePath;
    218219};
    219220#endif /* !FEQT_INCLUDED_SRC_medium_viso_UIVisoCreator_h */
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