VirtualBox

Changeset 87892 in vbox


Ignore:
Timestamp:
Feb 26, 2021 6:26:25 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9950. Adding an additional property for the disk source selection

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp

    r87865 r87892  
    1717
    1818/* Qt includes: */
    19 #include <QButtonGroup>
    2019#include <QCheckBox>
    2120#include <QDir>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.h

    r87602 r87892  
    3636class UIFilePathSelector;
    3737class UINameAndSystemEditor;
    38 class QButtonGroup;
    3938
    4039/** 1st page of the New Virtual Machine wizard (base part): */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic4.cpp

    r87886 r87892  
    1717
    1818/* Qt includes: */
     19#include <QButtonGroup>
    1920#include <QGridLayout>
    2021#include <QMetaType>
     
    3435#include "UIWizardNewVMPageBasic4.h"
    3536
     37Q_DECLARE_METATYPE(SelectedDiskSource);
     38
    3639UIWizardNewVMPage4::UIWizardNewVMPage4()
    3740    : m_fRecommendedNoDisk(false)
    38     , m_pDiskSkip(0)
    39     , m_pDiskCreate(0)
    40     , m_pDiskPresent(0)
     41    , m_pDiskEmpty(0)
     42    , m_pDiskNew(0)
     43    , m_pDiskExisting(0)
    4144    , m_pDiskSelector(0)
    42     , m_pVMMButton(0)
    43 {
    44 }
    45 
    46 void UIWizardNewVMPage4::updateVirtualDiskSource()
    47 {
    48     if (!m_pDiskSelector || !m_pVMMButton)
    49         return;
    50 
    51     /* Enable/disable controls: */
    52     m_pDiskSelector->setEnabled(m_pDiskPresent->isChecked());
    53     m_pVMMButton->setEnabled(m_pDiskPresent->isChecked());
    54 
    55     /* Fetch filed values: */
    56     // if (m_pDiskSkip->isChecked())
    57     // {
    58     //     m_uVirtualDiskId = QUuid();
    59     // }
    60     // else if (m_pDiskPresent->isChecked())
    61     // {
    62     //     m_uVirtualDiskId = m_pDiskSelector->id();
    63     // }
     45    , m_pDiskSelectionButton(0)
     46    , m_enmSelectedDiskSource(SelectedDiskSource_New)
     47{
     48}
     49
     50SelectedDiskSource UIWizardNewVMPage4::selectedDiskSource() const
     51{
     52    return m_enmSelectedDiskSource;
     53}
     54
     55void UIWizardNewVMPage4::setSelectedDiskSource(SelectedDiskSource enmSelectedDiskSource)
     56{
     57    m_enmSelectedDiskSource = enmSelectedDiskSource;
    6458}
    6559
     
    8074        /* Update medium-combo if necessary: */
    8175        m_pDiskSelector->setCurrentItem(uMediumId);
    82         /* Update hard disk source: */
    83         updateVirtualDiskSource();
    8476        /* Focus on hard disk combo: */
    8577        m_pDiskSelector->setFocus();
     
    10294        m_virtualDisk = pWizard->virtualDisk();
    10395        m_pDiskSelector->setCurrentItem(m_virtualDisk.GetId());
    104         m_pDiskPresent->click();
     96        m_pDiskExisting->click();
    10597    }
    10698    if (pWizard)
     
    135127void UIWizardNewVMPage4::retranslateWidgets()
    136128{
    137     if (m_pDiskSkip)
    138         m_pDiskSkip->setText(UIWizardNewVM::tr("&Do not add a virtual hard disk"));
    139     if (m_pDiskCreate)
    140         m_pDiskCreate->setText(UIWizardNewVM::tr("&Create a virtual hard disk now"));
    141     if (m_pDiskPresent)
    142         m_pDiskPresent->setText(UIWizardNewVM::tr("&Use an existing virtual hard disk file"));
    143     if (m_pVMMButton)
    144         m_pVMMButton->setToolTip(UIWizardNewVM::tr("Choose a virtual hard disk file..."));
     129    if (m_pDiskEmpty)
     130        m_pDiskEmpty->setText(UIWizardNewVM::tr("&Do not add a virtual hard disk"));
     131    if (m_pDiskNew)
     132        m_pDiskNew->setText(UIWizardNewVM::tr("&Create a virtual hard disk now"));
     133    if (m_pDiskExisting)
     134        m_pDiskExisting->setText(UIWizardNewVM::tr("&Use an existing virtual hard disk file"));
     135    if (m_pDiskSelectionButton)
     136        m_pDiskSelectionButton->setToolTip(UIWizardNewVM::tr("Choose a virtual hard disk file..."));
     137}
     138
     139void UIWizardNewVMPage4::setEnableDiskSelectionWidgets(bool fEnabled)
     140{
     141    if (!m_pDiskSelector || !m_pDiskSelectionButton)
     142        return;
     143
     144    m_pDiskSelector->setEnabled(fEnabled);
     145    m_pDiskSelectionButton->setEnabled(fEnabled);
    145146}
    146147
     
    149150    QWidget *pDiskContainer = new QWidget;
    150151    QGridLayout *pDiskLayout = new QGridLayout(pDiskContainer);
    151 
    152     m_pDiskSkip = new QRadioButton;
    153     m_pDiskCreate = new QRadioButton;
    154     m_pDiskPresent = new QRadioButton;
     152    m_pDiskSourceButtonGroup = new QButtonGroup;
     153    m_pDiskEmpty = new QRadioButton;
     154    m_pDiskNew = new QRadioButton;
     155    m_pDiskExisting = new QRadioButton;
     156    m_pDiskSourceButtonGroup->addButton(m_pDiskEmpty);
     157    m_pDiskSourceButtonGroup->addButton(m_pDiskNew);
     158    m_pDiskSourceButtonGroup->addButton(m_pDiskExisting);
    155159    QStyleOptionButton options;
    156     options.initFrom(m_pDiskPresent);
    157     int iWidth = m_pDiskPresent->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &options, m_pDiskPresent);
     160    options.initFrom(m_pDiskExisting);
     161    int iWidth = m_pDiskExisting->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &options, m_pDiskExisting);
    158162    pDiskLayout->setColumnMinimumWidth(0, iWidth);
    159163    m_pDiskSelector = new UIMediaComboBox;
     
    162166        m_pDiskSelector->repopulate();
    163167    }
    164     m_pVMMButton = new QIToolButton;
    165     {
    166         m_pVMMButton->setAutoRaise(true);
    167         m_pVMMButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png"));
    168     }
    169     pDiskLayout->addWidget(m_pDiskSkip, 0, 0, 1, 3);
    170     pDiskLayout->addWidget(m_pDiskCreate, 1, 0, 1, 3);
    171     pDiskLayout->addWidget(m_pDiskPresent, 2, 0, 1, 3);
     168    m_pDiskSelectionButton = new QIToolButton;
     169    {
     170        m_pDiskSelectionButton->setAutoRaise(true);
     171        m_pDiskSelectionButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png"));
     172    }
     173    pDiskLayout->addWidget(m_pDiskEmpty, 0, 0, 1, 3);
     174    pDiskLayout->addWidget(m_pDiskNew, 1, 0, 1, 3);
     175    pDiskLayout->addWidget(m_pDiskExisting, 2, 0, 1, 3);
    172176    pDiskLayout->addWidget(m_pDiskSelector, 3, 1);
    173     pDiskLayout->addWidget(m_pVMMButton, 3, 2);
     177    pDiskLayout->addWidget(m_pDiskSelectionButton, 3, 2);
    174178    return pDiskContainer;
    175179}
     
    180184    prepare();
    181185    qRegisterMetaType<CMedium>();
     186    qRegisterMetaType<SelectedDiskSource>();
    182187    registerField("virtualDisk", this, "virtualDisk");
     188    registerField("diskSource", this, "diskSource");
    183189}
    184190
    185191int UIWizardNewVMPageBasic4::nextId() const
    186192{
    187     if (m_pDiskCreate->isChecked())
     193    if (m_pDiskNew->isChecked())
    188194        return UIWizardNewVM::Page5;
    189195    return UIWizardNewVM::Page8;
     
    199205
    200206    pMainLayout->addStretch();
    201     updateVirtualDiskSource();
     207    setEnableDiskSelectionWidgets(m_enmSelectedDiskSource == SelectedDiskSource_Existing);
    202208    createConnections();
    203209}
     
    205211void UIWizardNewVMPageBasic4::createConnections()
    206212{
    207     connect(m_pDiskSkip, &QRadioButton::toggled,
    208             this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
    209     connect(m_pDiskCreate, &QRadioButton::toggled,
    210             this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
    211     connect(m_pDiskPresent, &QRadioButton::toggled,
    212             this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
     213    connect(m_pDiskSourceButtonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
     214            this, &UIWizardNewVMPageBasic4::sltHandleSelectedDiskSourceChange);
    213215    connect(m_pDiskSelector, static_cast<void(UIMediaComboBox::*)(int)>(&UIMediaComboBox::currentIndexChanged),
    214             this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
    215     connect(m_pVMMButton, &QIToolButton::clicked,
     216            this, &UIWizardNewVMPageBasic4::sltVirtualSelectedDiskSourceChanged);
     217    connect(m_pDiskSelectionButton, &QIToolButton::clicked,
    216218            this, &UIWizardNewVMPageBasic4::sltGetWithFileOpenDialog);
    217219}
    218220
    219 void UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged()
    220 {
    221     /* Call to base-class: */
    222     updateVirtualDiskSource();
    223 
    224     /* Broadcast complete-change: */
     221void UIWizardNewVMPageBasic4::sltHandleSelectedDiskSourceChange()
     222{
     223    if (!m_pDiskSourceButtonGroup)
     224        return;
     225
     226    if (m_pDiskSourceButtonGroup->checkedButton() == m_pDiskEmpty)
     227        setSelectedDiskSource(SelectedDiskSource_Empty);
     228    else if (m_pDiskSourceButtonGroup->checkedButton() == m_pDiskExisting)
     229        setSelectedDiskSource(SelectedDiskSource_Existing);
     230    else
     231        setSelectedDiskSource(SelectedDiskSource_New);
     232
     233    setEnableDiskSelectionWidgets(m_enmSelectedDiskSource == SelectedDiskSource_Existing);
     234    completeChanged();
     235}
     236
     237void UIWizardNewVMPageBasic4::sltVirtualSelectedDiskSourceChanged()
     238{
    225239    emit completeChanged();
    226240}
     
    261275    if (type.GetRecommendedHDD() != 0)
    262276    {
    263         if (m_pDiskCreate)
     277        if (m_pDiskNew)
    264278        {
    265             m_pDiskCreate->setFocus();
    266             m_pDiskCreate->setChecked(true);
     279            m_pDiskNew->setFocus();
     280            m_pDiskNew->setChecked(true);
    267281        }
    268282        m_fRecommendedNoDisk = false;
     
    270284    else
    271285    {
    272         if (m_pDiskSkip)
     286        if (m_pDiskEmpty)
    273287        {
    274             m_pDiskSkip->setFocus();
    275             m_pDiskSkip->setChecked(true);
     288            m_pDiskEmpty->setFocus();
     289            m_pDiskEmpty->setChecked(true);
    276290        }
    277291        m_fRecommendedNoDisk = true;
    278     }
     292     }
    279293    if (m_pDiskSelector)
    280294        m_pDiskSelector->setCurrentIndex(0);
     
    290304bool UIWizardNewVMPageBasic4::isComplete() const
    291305{
    292     if (!m_pDiskSkip)
     306    if (!m_pDiskEmpty)
    293307        return false;
    294     return m_pDiskSkip->isChecked() ||
    295         !m_pDiskPresent->isChecked() ||
     308    return m_pDiskEmpty->isChecked() ||
     309        !m_pDiskExisting->isChecked() ||
    296310        !uiCommon().medium(m_pDiskSelector->id()).isNull();
    297311}
     
    303317
    304318//     /* Ensure unused virtual-disk is deleted: */
    305 //     if (m_pDiskSkip->isChecked() || m_pDiskCreate->isChecked() || (!m_virtualDisk.isNull() && m_uVirtualDiskId != m_virtualDisk.GetId()))
     319//     if (m_pDiskEmpty->isChecked() || m_pDiskNew->isChecked() || (!m_virtualDisk.isNull() && m_uVirtualDiskId != m_virtualDisk.GetId()))
    306320//         ensureNewVirtualDiskDeleted();
    307321
    308 //     if (m_pDiskSkip->isChecked())
     322//     if (m_pDiskEmpty->isChecked())
    309323//     {
    310324//         /* Ask user about disk-less machine unless that's the recommendation: */
     
    312326//             fResult = msgCenter().confirmHardDisklessMachine(thisImp());
    313327//     }
    314 //     else if (m_pDiskCreate->isChecked())
     328//     else if (m_pDiskNew->isChecked())
    315329//     {
    316330//         /* Show the New Virtual Hard Drive wizard: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic4.h

    r87886 r87892  
    3333
    3434/* Forward declarations: */
     35class QButtonGroup;
    3536class QRadioButton;
    3637class QIRichTextLabel;
     
    3839class UIMediaComboBox;
    3940
    40 /** 3rd page of the New Virtual Machine wizard (base part). */
     41enum SelectedDiskSource
     42{
     43    SelectedDiskSource_Empty = 0,
     44    SelectedDiskSource_New,
     45    SelectedDiskSource_Existing,
     46    SelectedDiskSource_Max
     47};
     48
    4149class UIWizardNewVMPage4 : public UIWizardPageBase
    4250{
     
    4957protected:
    5058
    51     /** Constructor. */
    5259    UIWizardNewVMPage4();
    5360
    54     /** Handlers. */
    55     void updateVirtualDiskSource();
     61    SelectedDiskSource selectedDiskSource() const;
     62    void setSelectedDiskSource(SelectedDiskSource enmSelectedDiskSource);
     63
    5664    void getWithFileOpenDialog();
    5765    bool getWithNewVirtualDiskWizard();
    5866
    5967
    60 
    6168    QWidget *createDiskWidgets();
    6269
    63     /** Helpers. */
    6470    void ensureNewVirtualDiskDeleted();
    6571    void retranslateWidgets();
    6672
    67     /** Input. */
     73    void setEnableDiskSelectionWidgets(bool fEnable);
    6874    bool m_fRecommendedNoDisk;
    6975
     
    7581    /** @name Widgets
    7682     * @{ */
    77        QRadioButton *m_pDiskSkip;
    78        QRadioButton *m_pDiskCreate;
    79        QRadioButton *m_pDiskPresent;
     83       QButtonGroup *m_pDiskSourceButtonGroup;
     84       QRadioButton *m_pDiskEmpty;
     85       QRadioButton *m_pDiskNew;
     86       QRadioButton *m_pDiskExisting;
    8087       UIMediaComboBox *m_pDiskSelector;
    81        QIToolButton *m_pVMMButton;
     88       QIToolButton *m_pDiskSelectionButton;
    8289    /** @} */
    83 
     90    SelectedDiskSource m_enmSelectedDiskSource;
    8491};
    8592
    86 /** 3rd page of the New Virtual Machine wizard (basic extension). */
    8793class UIWizardNewVMPageBasic4 : public UIWizardPage, public UIWizardNewVMPage4
    8894{
    8995    Q_OBJECT;
    9096    Q_PROPERTY(CMedium virtualDisk READ virtualDisk WRITE setVirtualDisk);
     97    Q_PROPERTY(SelectedDiskSource selectedDiskSource READ selectedDiskSource WRITE setSelectedDiskSource);
    9198
    9299public:
     
    107114private slots:
    108115
    109     /** Handlers. */
    110     void sltVirtualDiskSourceChanged();
     116    void sltHandleSelectedDiskSourceChange();
     117    void sltVirtualSelectedDiskSourceChanged();
    111118    void sltGetWithFileOpenDialog();
    112119
     
    114121
    115122
    116     /** Prepare stuff. */
    117123    void prepare();
    118124    void createConnections();
     
    121127    void cleanupPage();
    122128
    123     /** Validation stuff. */
    124129    bool isComplete() const;
    125     //virtual bool validatePage() /* override */;
    126130
    127     /** Widgets. */
    128131    QIRichTextLabel *m_pLabel;
    129132};
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r87886 r87892  
    1717
    1818/* Qt includes: */
    19 #include <QButtonGroup>
    2019#include <QCheckBox>
    2120#include <QGridLayout>
     
    6160
    6261        pMainLayout->addStretch();
    63         updateVirtualDiskSource();
     62
    6463    }
    6564
     
    145144void UIWizardNewVMPageExpert::sltVirtualDiskSourceChanged()
    146145{
    147     /* Call to base-class: */
    148     updateVirtualDiskSource();
    149 
    150146    /* Broadcast complete-change: */
    151147    emit completeChanged();
     
    239235
    240236    /* Connections for disk and hardware stuff: */
    241     if (m_pDiskSkip)
    242     {
    243         connect(m_pDiskSkip, &QRadioButton::toggled,
     237    if (m_pDiskEmpty)
     238    {
     239        connect(m_pDiskEmpty, &QRadioButton::toggled,
    244240                this, &UIWizardNewVMPageExpert::sltVirtualDiskSourceChanged);
    245         connect(m_pDiskSkip, &QRadioButton::toggled,
     241        connect(m_pDiskEmpty, &QRadioButton::toggled,
    246242                this, &UIWizardNewVMPageExpert::sltValueModified);
    247243    }
    248     if (m_pDiskCreate)
    249     {
    250         connect(m_pDiskCreate, &QRadioButton::toggled,
     244    if (m_pDiskNew)
     245    {
     246        connect(m_pDiskNew, &QRadioButton::toggled,
    251247                this, &UIWizardNewVMPageExpert::sltVirtualDiskSourceChanged);
    252         connect(m_pDiskCreate, &QRadioButton::toggled,
     248        connect(m_pDiskNew, &QRadioButton::toggled,
    253249                this, &UIWizardNewVMPageExpert::sltValueModified);
    254250    }
    255     if (m_pDiskPresent)
    256     {
    257         connect(m_pDiskPresent, &QRadioButton::toggled,
     251    if (m_pDiskExisting)
     252    {
     253        connect(m_pDiskExisting, &QRadioButton::toggled,
    258254                this, &UIWizardNewVMPageExpert::sltVirtualDiskSourceChanged);
    259         connect(m_pDiskPresent, &QRadioButton::toggled,
     255        connect(m_pDiskExisting, &QRadioButton::toggled,
    260256                this, &UIWizardNewVMPageExpert::sltValueModified);
    261257    }
     
    263259        connect(m_pDiskSelector, static_cast<void(UIMediaComboBox::*)(int)>(&UIMediaComboBox::currentIndexChanged),
    264260                this, &UIWizardNewVMPageExpert::sltVirtualDiskSourceChanged);
    265     if (m_pVMMButton)
    266         connect(m_pVMMButton, &QIToolButton::clicked,
     261    if (m_pDiskSelectionButton)
     262        connect(m_pDiskSelectionButton, &QIToolButton::clicked,
    267263                this, &UIWizardNewVMPageExpert::sltGetWithFileOpenDialog);
    268264    if (m_pBaseMemoryEditor)
     
    299295
    300296    /* Prepare initial disk choice: */
    301     if (!m_userSetWidgets.contains(m_pDiskCreate) &&
    302         !m_userSetWidgets.contains(m_pDiskSkip) &&
    303         !m_userSetWidgets.contains(m_pDiskPresent))
     297    if (!m_userSetWidgets.contains(m_pDiskNew) &&
     298        !m_userSetWidgets.contains(m_pDiskEmpty) &&
     299        !m_userSetWidgets.contains(m_pDiskExisting))
    304300    {
    305301        if (type.GetRecommendedHDD() != 0)
    306302        {
    307             if (m_pDiskCreate)
     303            if (m_pDiskNew)
    308304            {
    309                 m_pDiskCreate->setFocus();
    310                 m_pDiskCreate->setChecked(true);
     305                m_pDiskNew->setFocus();
     306                m_pDiskNew->setChecked(true);
    311307            }
    312308            m_fRecommendedNoDisk = false;
     
    314310        else
    315311        {
    316             if (m_pDiskSkip)
     312            if (m_pDiskEmpty)
    317313            {
    318                 m_pDiskSkip->setFocus();
    319                 m_pDiskSkip->setChecked(true);
     314                m_pDiskEmpty->setFocus();
     315                m_pDiskEmpty->setChecked(true);
    320316            }
    321317            m_fRecommendedNoDisk = true;
     
    405401    }
    406402
    407     if (m_pDiskPresent->isChecked() && uiCommon().medium(m_pDiskSelector->id()).isNull())
     403    if (m_pDiskExisting->isChecked() && uiCommon().medium(m_pDiskSelector->id()).isNull())
    408404    {
    409405        m_pToolBox->setPageTitleIcon(ExpertToolboxItems_Disk,
     
    464460        if (fResult)
    465461        {
    466             if (m_pDiskCreate->isChecked())
     462            if (m_pDiskNew->isChecked())
    467463            {
    468464                /* Show the New Virtual Hard Drive wizard if necessary: */
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