Changeset 100497 in vbox for trunk/src/VBox
- Timestamp:
- Jul 11, 2023 7:27:14 AM (17 months ago)
- 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 255 255 256 256 UIVisoCreatorWidget::UIVisoCreatorWidget(UIActionPool *pActionPool, QWidget *pParent, 257 bool fShowToolBar, const QString& str MachineName /* = QString() */)257 bool fShowToolBar, const QString& strVisoSavePath, const QString& strMachineName) 258 258 : QIWithRetranslateUI<QWidget>(pParent) 259 259 , m_pActionSettings(0) … … 275 275 , m_pBrowserContainerWidget(0) 276 276 , m_pStackedLayout(0) 277 , m_strVisoSavePath(strVisoSavePath) 277 278 { 278 279 m_visoOptions.m_strVisoName = !strMachineName.isEmpty() ? strMachineName : "ad-hoc"; … … 692 693 } 693 694 695 QString 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 *********************************************************************************************************************************/ 704 UIVisoCreatorDialog::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 720 QStringList UIVisoCreatorDialog::entryList() const 721 { 722 if (m_pVisoCreatorWidget) 723 return m_pVisoCreatorWidget->entryList(); 724 return QStringList(); 725 } 726 727 QString UIVisoCreatorDialog::visoName() const 728 { 729 if (m_pVisoCreatorWidget) 730 return m_pVisoCreatorWidget->visoName(); 731 return QString(); 732 } 733 734 QString UIVisoCreatorDialog::importedISOPath() const 735 { 736 if (m_pVisoCreatorWidget) 737 return m_pVisoCreatorWidget->importedISOPath(); 738 return QString(); 739 } 740 741 QStringList UIVisoCreatorDialog::customOptions() const 742 { 743 if (m_pVisoCreatorWidget) 744 return m_pVisoCreatorWidget->customOptions(); 745 return QStringList(); 746 } 747 748 QString UIVisoCreatorDialog::currentPath() const 749 { 750 if (m_pVisoCreatorWidget) 751 return m_pVisoCreatorWidget->currentPath(); 752 return QString(); 753 } 754 755 void UIVisoCreatorDialog::setCurrentPath(const QString &strPath) 756 { 757 if (m_pVisoCreatorWidget) 758 m_pVisoCreatorWidget->setCurrentPath(strPath); 759 } 760 761 void 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 802 void 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 811 void 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 824 bool 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 845 void UIVisoCreatorDialog::sltSetCancelButtonShortCut(QKeySequence keySequence) 846 { 847 if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel)) 848 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(keySequence); 849 } 850 851 void UIVisoCreatorDialog::sltVisoNameChanged(const QString &strName) 852 { 853 Q_UNUSED(strName); 854 updateWindowTitle(); 855 } 856 857 void UIVisoCreatorDialog::sltSettingDialogToggle(bool fIsShown) 858 { 859 if (m_pButtonBox) 860 m_pButtonBox->setEnabled(!fIsShown); 861 } 862 863 void 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 879 void 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 887 void UIVisoCreatorDialog::updateWindowTitle() 888 { 889 setWindowTitle(QString("%1 - %2").arg(UIVisoCreatorWidget::tr("VISO Creator")).arg(visoFileFullPath())); 890 } 891 892 QString UIVisoCreatorDialog::visoFileFullPath() const 893 { 894 if (!m_pVisoCreatorWidget) 895 return QString(); 896 return m_pVisoCreatorWidget->visoFileFullPath(); 897 } 898 694 899 /* static */ 695 900 QUuid UIVisoCreatorDialog::createViso(UIActionPool *pActionPool, QWidget *pParent, … … 747 952 748 953 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() const770 {771 if (m_pVisoCreatorWidget)772 return m_pVisoCreatorWidget->entryList();773 return QStringList();774 }775 776 QString UIVisoCreatorDialog::visoName() const777 {778 if (m_pVisoCreatorWidget)779 return m_pVisoCreatorWidget->visoName();780 return QString();781 }782 783 QString UIVisoCreatorDialog::importedISOPath() const784 {785 if (m_pVisoCreatorWidget)786 return m_pVisoCreatorWidget->importedISOPath();787 return QString();788 }789 790 QStringList UIVisoCreatorDialog::customOptions() const791 {792 if (m_pVisoCreatorWidget)793 return m_pVisoCreatorWidget->customOptions();794 return QStringList();795 }796 797 QString UIVisoCreatorDialog::currentPath() const798 {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() const942 {943 return QString("%1/%2%3").arg(m_strVisoSavePath).arg(visoName()).arg(".viso");944 }945 946 954 #include "UIVisoCreator.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h
r100496 r100497 86 86 87 87 UIVisoCreatorWidget(UIActionPool *pActionPool, QWidget *pParent, 88 bool fShowToolBar, const QString& str MachineName = QString());88 bool fShowToolBar, const QString& strVisoSavePath, const QString& strMachineName); 89 89 /** Returns the content of the .viso file. Each element of the list corresponds to a line in the .viso file. */ 90 90 QStringList entryList() const; … … 97 97 void setCurrentPath(const QString &strPath); 98 98 QMenu *menu() const; 99 QString visoFileFullPath() const; 99 100 100 101 #ifdef VBOX_WS_MAC … … 165 166 QGraphicsBlurEffect *m_pOverlayBlurEffect; 166 167 QStackedLayout *m_pStackedLayout; 168 QString m_strVisoSavePath; 167 169 }; 168 170 … … 204 206 205 207 private: 206 void prepareWidgets(const QString &strMachineName);208 void prepareWidgets(const QString& strVisoSavePath, const QString &strMachineName); 207 209 void prepareConnections(); 208 210 virtual void retranslateUi() final override; … … 215 217 QPointer<UIActionPool> m_pActionPool; 216 218 int m_iGeometrySaveTimerId; 217 QString m_strVisoSavePath;218 219 }; 219 220 #endif /* !FEQT_INCLUDED_SRC_medium_viso_UIVisoCreator_h */
Note:
See TracChangeset
for help on using the changeset viewer.