VirtualBox

Changeset 41387 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 22, 2012 10:42:51 AM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Reworking VBoxOSTypeSelectorWidget into UINameAndSystemEditor. Using it in General page of VM settings and 1st page of Create VM wizard.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r41373 r41387  
    356356        src/widgets/VBoxMiniToolBar.h \
    357357        src/widgets/VBoxOSTypeSelectorButton.h \
    358         src/widgets/VBoxOSTypeSelectorWidget.h \
     358        src/widgets/UINameAndSystemEditor.h \
    359359        src/widgets/VBoxWarningPane.h \
    360360        src/wizards/UIWizard.h \
     
    565565        src/widgets/VBoxMiniToolBar.cpp \
    566566        src/widgets/VBoxOSTypeSelectorButton.cpp \
    567         src/widgets/VBoxOSTypeSelectorWidget.cpp \
     567        src/widgets/UINameAndSystemEditor.cpp \
    568568        src/widgets/VBoxWarningPane.cpp \
    569569        src/wizards/UIWizard.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/precomp.h

    r38977 r41387  
    229229#include "VBoxNewVMWzd.h"
    230230#include "VBoxOSTypeSelectorButton.h"
    231 #include "VBoxOSTypeSelectorWidget.h"
     231#include "UINameAndSystemEditor.h"
    232232#include "UIMessageCenter.h"
    233233#include "VBoxProgressDialog.h"
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.cpp

    r38311 r41387  
    2424
    2525#include <QDir>
     26#include <QLineEdit>
    2627
    2728UIMachineSettingsGeneral::UIMachineSettingsGeneral()
     
    3334
    3435    /* Setup validators */
    35     mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
     36    m_pNameAndSystemEditor->nameEditor()->setValidator(new QRegExpValidator(QRegExp(".+"), this));
    3637
    3738    /* Shared Clipboard mode */
     
    5152CGuestOSType UIMachineSettingsGeneral::guestOSType() const
    5253{
    53     return mOSTypeSelector->type();
     54    return m_pNameAndSystemEditor->type();
    5455}
    5556
     
    6162bool UIMachineSettingsGeneral::is64BitOSTypeSelected() const
    6263{
    63     return mOSTypeSelector->type().GetIs64Bit();
     64    return m_pNameAndSystemEditor->type().GetIs64Bit();
    6465}
    6566
     
    6768bool UIMachineSettingsGeneral::isWindowsOSTypeSelected() const
    6869{
    69     return mOSTypeSelector->type().GetFamilyId() == "Windows";
     70    return m_pNameAndSystemEditor->type().GetFamilyId() == "Windows";
    7071}
    7172#endif /* VBOX_WITH_VIDEOHWACCEL */
     
    113114
    114115    /* Load general data to page: */
    115     mLeName->setText(generalData.m_strName);
    116     mOSTypeSelector->setType(vboxGlobal().vmGuestOSType(generalData.m_strGuestOsTypeId));
     116    m_pNameAndSystemEditor->setName(generalData.m_strName);
     117    m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(generalData.m_strGuestOsTypeId));
    117118    mCbSaveMounted->setChecked(generalData.m_fSaveMountedAtRuntime);
    118119    mCbShowToolBar->setChecked(generalData.m_fShowMiniToolBar);
     
    139140
    140141    /* Gather general data: */
    141     generalData.m_strName = mLeName->text();
    142     generalData.m_strGuestOsTypeId = mOSTypeSelector->type().GetId();
     142    generalData.m_strName = m_pNameAndSystemEditor->name();
     143    generalData.m_strGuestOsTypeId = m_pNameAndSystemEditor->type().GetId();
    143144    generalData.m_fSaveMountedAtRuntime = mCbSaveMounted->isChecked();
    144145    generalData.m_fShowMiniToolBar = mCbShowToolBar->isChecked();
     
    197198{
    198199    mValidator = aVal;
    199     connect (mOSTypeSelector, SIGNAL (osTypeChanged()), mValidator, SLOT (revalidate()));
     200    connect (m_pNameAndSystemEditor, SIGNAL (sigOsTypeChanged()), mValidator, SLOT (revalidate()));
    200201}
    201202
     
    213214    /* Basic tab-order */
    214215    setTabOrder (aWidget, mTwGeneral->focusProxy());
    215     setTabOrder (mTwGeneral->focusProxy(), mLeName);
    216     setTabOrder (mLeName, mOSTypeSelector);
     216    setTabOrder (mTwGeneral->focusProxy(), m_pNameAndSystemEditor);
    217217
    218218    /* Advanced tab-order */
    219     setTabOrder (mOSTypeSelector, mPsSnapshot);
     219    setTabOrder (m_pNameAndSystemEditor, mPsSnapshot);
    220220    setTabOrder (mPsSnapshot, mCbClipboard);
    221221    setTabOrder (mCbClipboard, mCbSaveMounted);
     
    248248{
    249249    /* Basic tab: */
    250     mLbName->setEnabled(isMachineOffline());
    251     mLeName->setEnabled(isMachineOffline());
    252     mOSTypeSelector->setEnabled(isMachineOffline());
     250    m_pNameAndSystemEditor->setEnabled(isMachineOffline());
    253251    /* Advanced tab: */
    254252    mLbSnapshot->setEnabled(isMachineOffline());
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.ui

    r37616 r41387  
    3838       </property>
    3939       <item>
    40         <widget class="VBoxOSTypeSelectorWidget" native="1" name="mOSTypeSelector" >
    41          <layout class="QGridLayout" name="mLtOSTypeSelector" >
    42           <property name="margin" >
    43            <number>0</number>
    44           </property>
    45           <item row="0" column="0" >
    46            <widget class="QLabel" name="mLbName" >
    47             <property name="text" >
    48              <string>&amp;Name:</string>
    49             </property>
    50             <property name="alignment" >
    51              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    52             </property>
    53             <property name="buddy" >
    54              <cstring>mLeName</cstring>
    55             </property>
    56            </widget>
    57           </item>
    58           <item row="0" column="1" colspan="2" >
    59            <widget class="QLineEdit" name="mLeName" >
    60             <property name="whatsThis" >
    61              <string>Displays the name of the virtual machine.</string>
    62             </property>
    63            </widget>
    64           </item>
    65          </layout>
    66         </widget>
     40        <widget class="UINameAndSystemEditor" native="1" name="m_pNameAndSystemEditor" />
    6741       </item>
    6842       <item>
     
    278252 <customwidgets>
    279253  <customwidget>
    280    <class>VBoxOSTypeSelectorWidget</class>
     254   <class>UINameAndSystemEditor</class>
    281255   <extends>QWidget</extends>
    282    <header>VBoxOSTypeSelectorWidget.h</header>
     256   <header>UINameAndSystemEditor.h</header>
    283257  </customwidget>
    284258  <customwidget>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.cpp

    r41372 r41387  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VBoxOSTypeSelectorWidget class implementation
     5 * UINameAndSystemEditor class implementation
    66 */
    77
    88/*
    9  * Copyright (C) 2008-2010 Oracle Corporation
     9 * Copyright (C) 2008-2012 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 #include "VBoxOSTypeSelectorWidget.h"
    21 
     20/* Global includes: */
     21#include <QGridLayout>
     22#include <QVBoxLayout>
     23#include <QLabel>
     24#include <QLineEdit>
    2225#include <QComboBox>
    23 #include <QLabel>
    24 #include <QVBoxLayout>
     26
     27/* Local includes: */
     28#include "UINameAndSystemEditor.h"
    2529
    2630enum
    2731{
    28     RoleTypeID = Qt::UserRole + 1
     32    TypeID = Qt::UserRole + 1
    2933};
    3034
    31 VBoxOSTypeSelectorWidget::VBoxOSTypeSelectorWidget (QWidget *aParent)
    32     : QIWithRetranslateUI <QWidget> (aParent)
    33     , mTxFamilyName (new QLabel (this))
    34     , mTxTypeName (new QLabel (this))
    35     , mPxTypeIcon (new QLabel (this))
    36     , mCbFamily (new QComboBox (this))
    37     , mCbType (new QComboBox (this))
    38     , mLayoutPosition (-1)
    39     , mLayoutActivated (false)
    40 {
    41     /* Register CGuestOSType type */
     35UINameAndSystemEditor::UINameAndSystemEditor(QWidget *pParent)
     36    : QIWithRetranslateUI<QWidget>(pParent)
     37{
     38    /* Register CGuestOSType type: */
    4239    qRegisterMetaType<CGuestOSType>();
    4340
    44     /* Setup widgets */
    45     mTxFamilyName->setAlignment (Qt::AlignRight);
    46     mTxTypeName->setAlignment (Qt::AlignRight);
    47     mTxFamilyName->setBuddy (mCbFamily);
    48     mTxTypeName->setBuddy (mCbType);
    49     mTxFamilyName->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed);
    50     mTxTypeName->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed);
    51     mCbFamily->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
    52     mCbType->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
    53     mPxTypeIcon->setFixedSize (32, 32);
    54 
    55     /* Check if host supports (AMD-V or VT-x) and long mode */
     41    /* Create widgets: */
     42    QGridLayout *pMainLayout = new QGridLayout(this);
     43    {
     44        m_pNameLabel = new QLabel(this);
     45        {
     46            m_pNameLabel->setAlignment(Qt::AlignRight);
     47            m_pNameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     48        }
     49        m_pNameEditor = new QLineEdit(this);
     50        {
     51            m_pNameEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     52            m_pNameLabel->setBuddy(m_pNameEditor);
     53        }
     54        m_pFamilyLabel = new QLabel(this);
     55        {
     56            m_pFamilyLabel->setAlignment(Qt::AlignRight);
     57            m_pFamilyLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     58        }
     59        m_pFamilyCombo = new QComboBox(this);
     60        {
     61            m_pFamilyCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     62            m_pFamilyLabel->setBuddy(m_pFamilyCombo);
     63        }
     64        m_pTypeLabel = new QLabel(this);
     65        {
     66            m_pTypeLabel->setAlignment(Qt::AlignRight);
     67            m_pTypeLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     68        }
     69        m_pTypeCombo = new QComboBox(this);
     70        {
     71            m_pTypeCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     72            m_pTypeLabel->setBuddy(m_pTypeCombo);
     73        }
     74        QVBoxLayout *pIconLayout = new QVBoxLayout;
     75        {
     76            m_pTypeIcon = new QLabel(this);
     77            {
     78                m_pTypeIcon->setFixedSize(32, 32);
     79            }
     80            pIconLayout->addWidget(m_pTypeIcon);
     81            pIconLayout->addStretch();
     82        }
     83        pMainLayout->addWidget(m_pNameLabel, 0, 0);
     84        pMainLayout->addWidget(m_pNameEditor, 0, 1, 1, 2);
     85        pMainLayout->addWidget(m_pFamilyLabel, 1, 0);
     86        pMainLayout->addWidget(m_pFamilyCombo, 1, 1);
     87        pMainLayout->addWidget(m_pTypeLabel, 2, 0);
     88        pMainLayout->addWidget(m_pTypeCombo, 2, 1);
     89        pMainLayout->addItem(pIconLayout, 1, 2, 2, 1);
     90    }
     91
     92    /* Check if host supports (AMD-V or VT-x) and long mode: */
    5693    CHost host = vboxGlobal().host();
    5794    m_fSupportsHWVirtEx = host.GetProcessorFeature(KProcessorFeature_HWVirtEx);
    5895    m_fSupportsLongMode = host.GetProcessorFeature(KProcessorFeature_LongMode);
    5996
    60     /* Fill OS family selector */
    61     int maximumSize = 0;
    62     QFontMetrics fm (mCbFamily->font());
    63     QList <CGuestOSType> families (vboxGlobal().vmGuestOSFamilyList());
    64     for (int i = 0; i < families.size(); ++ i)
    65     {
    66         /* Search for maximum length among family names */
    67         QString familyName (families [i].GetFamilyDescription());
    68         maximumSize = maximumSize < fm.width (familyName) ?
    69                       fm.width (familyName) : maximumSize;
    70         mCbFamily->insertItem (i, familyName);
    71         mCbFamily->setItemData (i, families [i].GetFamilyId(), RoleTypeID);
    72         /* Search for maximum length among type names */
    73         QList <CGuestOSType> types (vboxGlobal().vmGuestOSTypeList (families [i].GetFamilyId()));
    74         for (int j = 0; j < types.size(); ++ j)
    75         {
    76             QString typeName (types [j].GetDescription());
    77             maximumSize = maximumSize < fm.width (typeName) ?
    78                           fm.width (typeName) : maximumSize;
    79         }
    80     }
    81     mCbFamily->setCurrentIndex (0);
    82     onFamilyChanged (mCbFamily->currentIndex());
    83 
    84     /* Set the minimum size for OS Type & Family selectors. */
    85     QStyleOptionComboBox options;
    86     options.initFrom (mCbFamily);
    87     QSize size (style()->sizeFromContents (QStyle::CT_ComboBox, &options,
    88                 QSize (maximumSize, fm.height()), mCbFamily));
    89     mCbFamily->setMinimumWidth (size.width());
    90     mCbType->setMinimumWidth (size.width());
    91 
    92     /* Slots connections */
    93     connect (mCbFamily, SIGNAL (currentIndexChanged (int)),
    94              this, SLOT (onFamilyChanged (int)));
    95     connect (mCbType, SIGNAL (currentIndexChanged (int)),
    96              this, SLOT (onTypeChanged (int)));
    97 
    98     /* Retranslate */
     97    /* Fill OS family selector: */
     98    QList<CGuestOSType> families(vboxGlobal().vmGuestOSFamilyList());
     99    for (int i = 0; i < families.size(); ++i)
     100    {
     101        QString familyName(families[i].GetFamilyDescription());
     102        m_pFamilyCombo->insertItem(i, familyName);
     103        m_pFamilyCombo->setItemData(i, families[i].GetFamilyId(), TypeID);
     104    }
     105    m_pFamilyCombo->setCurrentIndex(0);
     106    sltFamilyChanged(m_pFamilyCombo->currentIndex());
     107
     108    /* Setup connections: */
     109    connect(m_pNameEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(sigNameChanged(const QString &)));
     110    connect(m_pFamilyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(sltFamilyChanged(int)));
     111    connect(m_pTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(sltTypeChanged(int)));
     112
     113    /* Retranslate: */
    99114    retranslateUi();
    100115}
    101116
    102 void VBoxOSTypeSelectorWidget::setType (const CGuestOSType &aType)
    103 {
    104     QString familyId (aType.GetFamilyId());
    105     QString typeId (aType.GetId());
    106 
    107     int familyIndex = mCbFamily->findData (familyId, RoleTypeID);
    108     AssertMsg (familyIndex != -1, ("Family ID should be valid: '%s'", familyId.toLatin1().constData()));
    109     if (familyIndex != -1)
    110         mCbFamily->setCurrentIndex (familyIndex);
    111 
    112     int typeIndex = mCbType->findData (typeId, RoleTypeID);
    113     AssertMsg (typeIndex != -1, ("Type ID should be valid: '%s'", typeId.toLatin1().constData()));
    114     if (typeIndex != -1)
    115         mCbType->setCurrentIndex (typeIndex);
    116 }
    117 
    118 CGuestOSType VBoxOSTypeSelectorWidget::type() const
    119 {
    120     return mType;
    121 }
    122 
    123 void VBoxOSTypeSelectorWidget::setLayoutPosition (int aPos)
    124 {
    125     mLayoutPosition = aPos;
    126 }
    127 
    128 void VBoxOSTypeSelectorWidget::activateLayout()
    129 {
    130     if (mLayoutActivated)
    131         return;
    132 
    133     mLayoutActivated = true;
    134 
    135     /* Layouting widgets */
    136     QVBoxLayout *layout1 = new QVBoxLayout();
    137     layout1->setSpacing (0);
    138     layout1->addWidget (mPxTypeIcon);
    139     layout1->addStretch();
    140 
    141     QGridLayout *layout2 = layout() ? static_cast <QGridLayout*> (layout()) :
    142                                       new QGridLayout (this);
    143     layout2->setMargin (0);
    144     int row = mLayoutPosition == -1 ? layout2->rowCount() : mLayoutPosition;
    145     layout2->addWidget (mTxFamilyName, row, 0);
    146     layout2->addWidget (mCbFamily, row, 1);
    147     layout2->addWidget (mTxTypeName, row + 1, 0);
    148     layout2->addWidget (mCbType, row + 1, 1);
    149     layout2->addLayout (layout1, row, 2, 2, 1);
    150 }
    151 
    152 void VBoxOSTypeSelectorWidget::retranslateUi()
    153 {
    154     mTxFamilyName->setText (tr ("&Type:"));
    155     mCbFamily->setWhatsThis (tr ("Displays the operating system family that "
    156                                  "you plan to install into this virtual machine."));
    157     mTxTypeName->setText (tr ("&Version:"));
    158     mCbType->setWhatsThis (tr ("Displays the operating system type that "
    159                                "you plan to install into this virtual "
    160                                "machine (called a guest operating system)."));
    161 }
    162 
    163 void VBoxOSTypeSelectorWidget::showEvent (QShowEvent *aEvent)
    164 {
    165     activateLayout(); /* if not yet */
    166     QIWithRetranslateUI <QWidget>::showEvent (aEvent);
    167 }
    168 
    169 void VBoxOSTypeSelectorWidget::onFamilyChanged (int aIndex)
    170 {
    171     /* Lock the signals of mCbType to prevent it's reaction on clearing */
    172     mCbType->blockSignals (true);
    173     mCbType->clear();
    174 
    175     /* Populate combo-box with OS Types related to currently selected Family ID */
    176     QString familyId (mCbFamily->itemData (aIndex, RoleTypeID).toString());
    177     QList <CGuestOSType> types (vboxGlobal().vmGuestOSTypeList (familyId));
    178     for (int i = 0; i < types.size(); ++ i)
    179     {
    180         if (types [i].GetIs64Bit() && (!m_fSupportsHWVirtEx || !m_fSupportsLongMode))
     117QLineEdit* UINameAndSystemEditor::nameEditor() const
     118{
     119    return m_pNameEditor;
     120}
     121
     122void UINameAndSystemEditor::setName(const QString &strName)
     123{
     124    m_pNameEditor->setText(strName);
     125}
     126
     127QString UINameAndSystemEditor::name() const
     128{
     129    return m_pNameEditor->text();
     130}
     131
     132void UINameAndSystemEditor::setType(const CGuestOSType &type)
     133{
     134    /* Initialize variables: */
     135    QString strFamilyId(type.GetFamilyId());
     136    QString strTypeId(type.GetId());
     137
     138    /* Get/check family index: */
     139    int iFamilyIndex = m_pFamilyCombo->findData(strFamilyId, TypeID);
     140    AssertMsg(iFamilyIndex != -1, ("Invalid family ID: '%s'", strFamilyId.toLatin1().constData()));
     141    if (iFamilyIndex != -1)
     142        m_pFamilyCombo->setCurrentIndex(iFamilyIndex);
     143
     144    /* Get/check type index: */
     145    int iTypeIndex = m_pTypeCombo->findData(strTypeId, TypeID);
     146    AssertMsg(iTypeIndex != -1, ("Invalid type ID: '%s'", strTypeId.toLatin1().constData()));
     147    if (iTypeIndex != -1)
     148        m_pTypeCombo->setCurrentIndex(iTypeIndex);
     149}
     150
     151CGuestOSType UINameAndSystemEditor::type() const
     152{
     153    return m_type;
     154}
     155
     156void UINameAndSystemEditor::retranslateUi()
     157{
     158    m_pNameLabel->setText(tr("&Name:"));
     159    m_pNameEditor->setWhatsThis(tr("Displays the name of the virtual machine."));
     160    m_pFamilyLabel->setText(tr("&Type:"));
     161    m_pFamilyCombo->setWhatsThis(tr("Displays the operating system family that "
     162                                    "you plan to install into this virtual machine."));
     163    m_pTypeLabel->setText(tr("&Version:"));
     164    m_pTypeCombo->setWhatsThis(tr("Displays the operating system type that "
     165                                  "you plan to install into this virtual machine "
     166                                  "(called a guest operating system)."));
     167}
     168
     169void UINameAndSystemEditor::sltFamilyChanged(int iIndex)
     170{
     171    /* Lock the signals of m_pTypeCombo to prevent it's reaction on clearing: */
     172    m_pTypeCombo->blockSignals(true);
     173    m_pTypeCombo->clear();
     174
     175    /* Populate combo-box with OS types related to currently selected family id: */
     176    QString strFamilyId(m_pFamilyCombo->itemData(iIndex, TypeID).toString());
     177    QList<CGuestOSType> types(vboxGlobal().vmGuestOSTypeList(strFamilyId));
     178    for (int i = 0; i < types.size(); ++i)
     179    {
     180        if (types[i].GetIs64Bit() && (!m_fSupportsHWVirtEx || !m_fSupportsLongMode))
    181181            continue;
    182         int index = mCbType->count();
    183         mCbType->insertItem (index, types [i].GetDescription());
    184         mCbType->setItemData (index, types [i].GetId(), RoleTypeID);
    185     }
    186 
    187     /* Select the most recently chosen item */
    188     if (mCurrentIds.contains (familyId))
    189     {
    190         QString typeId (mCurrentIds [familyId]);
    191         int typeIndex = mCbType->findData (typeId, RoleTypeID);
    192         if (typeIndex != -1)
    193             mCbType->setCurrentIndex (typeIndex);
    194     }
    195     /* Or select WinXP item for Windows family as default */
    196     else if (familyId == "Windows")
    197     {
    198         int xpIndex = mCbType->findData ("WindowsXP", RoleTypeID);
    199         if (xpIndex != -1)
    200             mCbType->setCurrentIndex (xpIndex);
    201     }
    202     /* Or select Ubuntu item for Linux family as default */
    203     else if (familyId == "Linux")
    204     {
    205         int ubIndex = mCbType->findData ("Ubuntu", RoleTypeID);
    206         if (ubIndex != -1)
    207             mCbType->setCurrentIndex (ubIndex);
    208     }
    209     /* Else simply select the first one present */
    210     else mCbType->setCurrentIndex (0);
    211 
    212     /* Update all the stuff with new type */
    213     onTypeChanged (mCbType->currentIndex());
    214 
    215     /* Unlock the signals of mCbType */
    216     mCbType->blockSignals (false);
    217 }
    218 
    219 void VBoxOSTypeSelectorWidget::onTypeChanged (int aIndex)
    220 {
    221     /* Save the new selected OS Type */
    222     mType = vboxGlobal().vmGuestOSType (
    223         mCbType->itemData (aIndex, RoleTypeID).toString(),
    224         mCbFamily->itemData (mCbFamily->currentIndex(), RoleTypeID).toString());
    225     mPxTypeIcon->setPixmap (vboxGlobal().vmGuestOSTypeIcon (mType.GetId()));
    226 
    227     /* Save the most recently used item */
    228     mCurrentIds [mType.GetFamilyId()] = mType.GetId();
    229 
    230     /* Notify connected objects about type was changed */
    231     emit osTypeChanged();
    232 }
    233 
     182        int iIndex = m_pTypeCombo->count();
     183        m_pTypeCombo->insertItem(iIndex, types[i].GetDescription());
     184        m_pTypeCombo->setItemData(iIndex, types[i].GetId(), TypeID);
     185    }
     186
     187    /* Select the most recently chosen item: */
     188    if (m_currentIds.contains(strFamilyId))
     189    {
     190        QString strTypeId(m_currentIds[strFamilyId]);
     191        int iTypeIndex = m_pTypeCombo->findData(strTypeId, TypeID);
     192        if (iTypeIndex != -1)
     193            m_pTypeCombo->setCurrentIndex(iTypeIndex);
     194    }
     195    /* Or select WinXP item for Windows family as default: */
     196    else if (strFamilyId == "Windows")
     197    {
     198        int iIndexWinXP = m_pTypeCombo->findData("WindowsXP", TypeID);
     199        if (iIndexWinXP != -1)
     200            m_pTypeCombo->setCurrentIndex(iIndexWinXP);
     201    }
     202    /* Or select Ubuntu item for Linux family as default: */
     203    else if (strFamilyId == "Linux")
     204    {
     205        int iIndexUbuntu = m_pTypeCombo->findData("Ubuntu", TypeID);
     206        if (iIndexUbuntu != -1)
     207            m_pTypeCombo->setCurrentIndex(iIndexUbuntu);
     208    }
     209    /* Else simply select the first one present: */
     210    else m_pTypeCombo->setCurrentIndex(0);
     211
     212    /* Update all the stuff: */
     213    sltTypeChanged(m_pTypeCombo->currentIndex());
     214
     215    /* Unlock the signals of m_pTypeCombo: */
     216    m_pTypeCombo->blockSignals (false);
     217}
     218
     219void UINameAndSystemEditor::sltTypeChanged(int iIndex)
     220{
     221    /* Save the new selected OS Type: */
     222    m_type = vboxGlobal().vmGuestOSType(m_pTypeCombo->itemData(iIndex, TypeID).toString(),
     223                                        m_pFamilyCombo->itemData(m_pFamilyCombo->currentIndex(), TypeID).toString());
     224    m_pTypeIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_type.GetId()));
     225
     226    /* Save the most recently used item: */
     227    m_currentIds[m_type.GetFamilyId()] = m_type.GetId();
     228
     229    /* Notifies listeners about OS type change: */
     230    emit sigOsTypeChanged();
     231}
     232
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.h

    r41361 r41387  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VBoxOSTypeSelectorWidget class declaration
     4 * UINameAndSystemEditor class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2008-2010 Oracle Corporation
     8 * Copyright (C) 2008-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717 */
    1818
    19 #ifndef __VBoxOSTypeSelectorWidget_h__
    20 #define __VBoxOSTypeSelectorWidget_h__
     19#ifndef __UINameAndSystemEditor_h__
     20#define __UINameAndSystemEditor_h__
    2121
     22/* Global includes: */
     23#include <QWidget>
     24
     25/* Local includes: */
    2226#include "QIWithRetranslateUI.h"
    2327#include "VBoxGlobal.h"
    2428
    25 #include <QWidget>
     29/* Forward declarations: */
     30class QLabel;
     31class QLineEdit;
     32class QComboBox;
    2633
    27 class QComboBox;
    28 class QLabel;
    29 
    30 class VBoxOSTypeSelectorWidget : public QIWithRetranslateUI <QWidget>
     34/* QWidget reimplementation providing editor for basic VM parameters: */
     35class UINameAndSystemEditor : public QIWithRetranslateUI<QWidget>
    3136{
    3237    Q_OBJECT;
     38    Q_PROPERTY(QString name READ name WRITE setName);
    3339    Q_PROPERTY(CGuestOSType type READ type WRITE setType);
     40
     41signals:
     42
     43    /* Notifies listeners about VM name change: */
     44    void sigNameChanged(const QString &strNewName);
     45
     46    /* Notifies listeners about VM operating system type change: */
     47    void sigOsTypeChanged();
    3448
    3549public:
    3650
    37     VBoxOSTypeSelectorWidget (QWidget *aParent);
     51    /* Constructor: */
     52    UINameAndSystemEditor(QWidget *pParent);
    3853
    39     void setType (const CGuestOSType &aType);
     54    /* Name stuff: */
     55    QLineEdit* nameEditor() const;
     56    void setName(const QString &strName);
     57    QString name() const;
     58
     59    /* Operating system type stuff: */
     60    void setType(const CGuestOSType &type);
    4061    CGuestOSType type() const;
    41 
    42     void setLayoutPosition (int aPos);
    43     void activateLayout();
    44 
    45 signals:
    46 
    47     void osTypeChanged();
    4862
    4963protected:
    5064
     65    /* Translation stuff: */
    5166    void retranslateUi();
    52     void showEvent (QShowEvent *aEvent);
    5367
    5468private slots:
    5569
    56     void onFamilyChanged (int aIndex);
    57     void onTypeChanged (int aIndex);
     70    /* Handles OS family change: */
     71    void sltFamilyChanged(int iIndex);
     72
     73    /* Handles OS type change: */
     74    void sltTypeChanged(int iIndex);
    5875
    5976private:
    6077
    61     QLabel *mTxFamilyName;
    62     QLabel *mTxTypeName;
    63     QLabel *mPxTypeIcon;
    64     QComboBox *mCbFamily;
    65     QComboBox *mCbType;
     78    /* Widgets: */
     79    QLabel *m_pNameLabel;
     80    QLabel *m_pFamilyLabel;
     81    QLabel *m_pTypeLabel;
     82    QLabel *m_pTypeIcon;
     83    QLineEdit *m_pNameEditor;
     84    QComboBox *m_pFamilyCombo;
     85    QComboBox *m_pTypeCombo;
    6686
    67     CGuestOSType mType;
    68     QMap <QString, QString> mCurrentIds;
    69 
    70     int mLayoutPosition;
    71     bool mLayoutActivated;
    72 
     87    /* Variables: */
     88    CGuestOSType m_type;
     89    QMap<QString, QString> m_currentIds;
    7390    bool m_fSupportsHWVirtEx;
    7491    bool m_fSupportsLongMode;
    7592};
    7693
    77 #endif /* __VBoxOSTypeSelectorWidget_h__ */
     94#endif /* __UINameAndSystemEditor_h__ */
    7895
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UIWizard.cpp

    r41372 r41387  
    402402    switch (m_type)
    403403    {
    404         /* New VM wizard much wider than others, fixing: */
    405         case UIWizardType_NewVM:
    406             dRatio -= 0.5;
    407             break;
    408         /* New VD wizard much taller than others, fixing: */
    409404        case UIWizardType_NewVD:
    410405        case UIWizardType_CloneVD:
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp

    r41373 r41387  
    2929#include "UIWizardNewVM.h"
    3030#include "UIMessageCenter.h"
    31 #include "VBoxOSTypeSelectorWidget.h"
     31#include "UINameAndSystemEditor.h"
    3232#include "QIRichTextLabel.h"
    3333
     
    148148        if (strNewName.contains(gs_OSTypePattern[i].pattern))
    149149        {
    150             m_pTypeSelector->blockSignals(true);
    151             m_pTypeSelector->setType(vboxGlobal().vmGuestOSType(gs_OSTypePattern[i].pcstId));
    152             m_pTypeSelector->blockSignals(false);
     150            m_pNameAndSystemEditor->blockSignals(true);
     151            m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(gs_OSTypePattern[i].pcstId));
     152            m_pNameAndSystemEditor->blockSignals(false);
    153153            break;
    154154        }
     
    159159    /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
    160160     * So simply disconnect the text-edit signal. */
    161     m_pNameEditor->disconnect(thisImp());
     161    m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), thisImp(), SLOT(sltNameChanged(const QString &)));
    162162}
    163163
     
    181181    QString strDefaultMachinesFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
    182182    /* Compose machine filename: */
    183     QString strMachineFilename = vbox.ComposeMachineFilename(m_pNameEditor->text(), strDefaultMachinesFolder);
     183    QString strMachineFilename = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(), strDefaultMachinesFolder);
    184184    /* Compose machine folder/basename: */
    185185    QFileInfo fileInfo(strMachineFilename);
     
    228228    {
    229229        m_pLabel = new QIRichTextLabel(this);
    230         m_pNameCnt = new QGroupBox(this);
     230        m_pNameAndSystemCnt = new QGroupBox(this);
    231231        {
    232             m_pNameCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    233             QHBoxLayout *pNameCntLayout = new QHBoxLayout(m_pNameCnt);
     232            m_pNameAndSystemCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     233            QHBoxLayout *pNameAndSystemLayout = new QHBoxLayout(m_pNameAndSystemCnt);
    234234            {
    235                 m_pNameEditor = new QLineEdit(m_pNameCnt);
    236                 pNameCntLayout->addWidget(m_pNameEditor);
    237             }
    238         }
    239         m_pTypeCnt = new QGroupBox(this);
    240         {
    241             m_pTypeCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    242             QHBoxLayout *pTypeSelectorLayout = new QHBoxLayout(m_pTypeCnt);
    243             {
    244                 m_pTypeSelector = new VBoxOSTypeSelectorWidget(m_pTypeCnt);
    245                 {
    246                     m_pTypeSelector->activateLayout();
    247                 }
    248                 pTypeSelectorLayout->addWidget(m_pTypeSelector);
     235                m_pNameAndSystemEditor = new UINameAndSystemEditor(m_pNameAndSystemCnt);
     236                pNameAndSystemLayout->addWidget(m_pNameAndSystemEditor);
    249237            }
    250238        }
    251239        pMainLayout->addWidget(m_pLabel);
    252         pMainLayout->addWidget(m_pNameCnt);
    253         pMainLayout->addWidget(m_pTypeCnt);
     240        pMainLayout->addWidget(m_pNameAndSystemCnt);
    254241        pMainLayout->addStretch();
    255242    }
    256243
    257244    /* Setup connections: */
    258     connect(m_pNameEditor, SIGNAL(textChanged(const QString&)), this, SLOT(sltNameChanged(const QString&)));
    259     connect(m_pTypeSelector, SIGNAL(osTypeChanged()), this, SLOT(sltOsTypeChanged()));
     245    connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
     246    connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(sltOsTypeChanged()));
    260247
    261248    /* Register fields: */
    262     registerField("name*", m_pNameEditor);
    263     registerField("type", m_pTypeSelector, "type", SIGNAL(osTypeChanged()));
     249    registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
     250    registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
    264251    registerField("machineFolder", this, "machineFolder");
    265252    registerField("machineBaseName", this, "machineBaseName");
     
    288275                                        "The name you choose will be used throughout VirtualBox "
    289276                                        "to identify this machine."));
    290     m_pNameCnt->setTitle(UIWizardNewVM::tr("&Name"));
    291     m_pTypeCnt->setTitle(UIWizardNewVM::tr("Operating system"));
     277    m_pNameAndSystemCnt->setTitle(UIWizardNewVM::tr("Name and operating system"));
    292278}
    293279
     
    296282    /* Translate page: */
    297283    retranslateUi();
    298 
    299     /* 'Name' field should have focus initially: */
    300     m_pNameEditor->setFocus();
    301284}
    302285
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.h

    r41373 r41387  
    2525/* Forward declarations: */
    2626class QGroupBox;
    27 class QLineEdit;
    28 class VBoxOSTypeSelectorWidget;
     27class UINameAndSystemEditor;
    2928class QIRichTextLabel;
    3029
     
    5958
    6059    /* Widgets: */
    61     QGroupBox *m_pNameCnt;
    62     QLineEdit *m_pNameEditor;
    63     QGroupBox *m_pTypeCnt;
    64     VBoxOSTypeSelectorWidget *m_pTypeSelector;
     60    QGroupBox *m_pNameAndSystemCnt;
     61    UINameAndSystemEditor *m_pNameAndSystemEditor;
    6562};
    6663
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r41372 r41387  
    3232#include "UIWizardNewVM.h"
    3333#include "UIIconPool.h"
    34 #include "VBoxOSTypeSelectorWidget.h"
     34#include "UINameAndSystemEditor.h"
    3535#include "VBoxGuestRAMSlider.h"
    3636#include "VBoxMediaComboBox.h"
     
    4444    {
    4545        pMainLayout->setContentsMargins(8, 6, 8, 6);
    46         m_pNameCnt = new QGroupBox(this);
    47         {
    48             m_pNameCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    49             QHBoxLayout *pNameCntLayout = new QHBoxLayout(m_pNameCnt);
    50             {
    51                 m_pNameEditor = new QLineEdit(m_pNameCnt);
    52                 pNameCntLayout->addWidget(m_pNameEditor);
    53             }
    54         }
    55         m_pTypeCnt = new QGroupBox(this);
    56         {
    57             m_pTypeCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    58             QHBoxLayout *pTypeCntLayout = new QHBoxLayout(m_pTypeCnt);
    59             {
    60                 m_pTypeSelector = new VBoxOSTypeSelectorWidget(m_pTypeCnt);
    61                 {
    62                     m_pTypeSelector->activateLayout();
    63                 }
    64                 pTypeCntLayout->addWidget(m_pTypeSelector);
     46        m_pNameAndSystemCnt = new QGroupBox(this);
     47        {
     48            m_pNameAndSystemCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     49            QHBoxLayout *pNameAndSystemLayout = new QHBoxLayout(m_pNameAndSystemCnt);
     50            {
     51                m_pNameAndSystemEditor = new UINameAndSystemEditor(m_pNameAndSystemCnt);
     52                pNameAndSystemLayout->addWidget(m_pNameAndSystemEditor);
    6553            }
    6654        }
     
    7563                    m_pRamSlider->setOrientation(Qt::Horizontal);
    7664                    m_pRamSlider->setTickPosition(QSlider::TicksBelow);
    77                     m_pRamSlider->setValue(m_pTypeSelector->type().GetRecommendedRAM());
     65                    m_pRamSlider->setValue(m_pNameAndSystemEditor->type().GetRecommendedRAM());
    7866                }
    7967                m_pRamEditor = new QILineEdit(m_pMemoryCnt);
     
    8371                    m_pRamEditor->setAlignment(Qt::AlignRight);
    8472                    m_pRamEditor->setValidator(new QIntValidator(m_pRamSlider->minRAM(), m_pRamSlider->maxRAM(), this));
    85                     m_pRamEditor->setText(QString::number(m_pTypeSelector->type().GetRecommendedRAM()));
     73                    m_pRamEditor->setText(QString::number(m_pNameAndSystemEditor->type().GetRecommendedRAM()));
    8674                }
    8775                m_pRamUnits = new QLabel(m_pMemoryCnt);
     
    141129            }
    142130        }
    143         pMainLayout->addWidget(m_pNameCnt);
    144         pMainLayout->addWidget(m_pTypeCnt);
     131        pMainLayout->addWidget(m_pNameAndSystemCnt);
    145132        pMainLayout->addWidget(m_pMemoryCnt);
    146133        pMainLayout->addWidget(m_pDiskCnt);
     
    150137
    151138    /* Setup connections: */
    152     connect(m_pNameEditor, SIGNAL(textChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
    153     connect(m_pTypeSelector, SIGNAL(osTypeChanged()), this, SLOT(sltOsTypeChanged()));
     139    connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
     140    connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(sltOsTypeChanged()));
    154141    connect(m_pRamSlider, SIGNAL(valueChanged(int)), this, SLOT(sltRamSliderValueChanged(int)));
    155142    connect(m_pRamEditor, SIGNAL(textChanged(const QString &)), this, SLOT(sltRamEditorTextChanged(const QString &)));
     
    163150    qRegisterMetaType<CMedium>();
    164151    /* Register fields: */
    165     registerField("name*", m_pNameEditor);
    166     registerField("type", m_pTypeSelector, "type", SIGNAL(osTypeChanged()));
     152    registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
     153    registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
    167154    registerField("machineFolder", this, "machineFolder");
    168155    registerField("machineBaseName", this, "machineBaseName");
     
    179166
    180167    /* Fetch recommended RAM value: */
    181     CGuestOSType type = m_pTypeSelector->type();
     168    CGuestOSType type = m_pNameAndSystemEditor->type();
    182169    m_pRamSlider->setValue(type.GetRecommendedRAM());
    183170    m_pRamEditor->setText(QString::number(type.GetRecommendedRAM()));
     
    193180
    194181    /* Fetch recommended RAM value: */
    195     CGuestOSType type = m_pTypeSelector->type();
     182    CGuestOSType type = m_pNameAndSystemEditor->type();
    196183    m_pRamSlider->setValue(type.GetRecommendedRAM());
    197184    m_pRamEditor->setText(QString::number(type.GetRecommendedRAM()));
     
    237224{
    238225    /* Translate widgets: */
    239     m_pNameCnt->setTitle(UIWizardNewVM::tr("&Name"));
    240     m_pTypeCnt->setTitle(UIWizardNewVM::tr("Operating system"));
     226    m_pNameAndSystemCnt->setTitle(UIWizardNewVM::tr("Name and operating system"));
    241227    m_pMemoryCnt->setTitle(UIWizardNewVM::tr("&Memory size"));
    242228    m_pRamUnits->setText(VBoxGlobal::tr("MB", "size suffix MBytes=1024 KBytes"));
     
    253239    /* Translate page: */
    254240    retranslateUi();
    255 
    256     /* 'Name' field should have focus initially: */
    257     m_pNameEditor->setFocus();
    258241}
    259242
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