VirtualBox

Changeset 67931 in vbox


Ignore:
Timestamp:
Jul 12, 2017 1:11:31 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
116923
Message:

FE/Qt: Virtual Media Manager & New Virtual Disk Wizard: Merging similar widgets used to control the medium size into one UIMediumSizeEditor widget; reusing it in both places.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
7 edited
2 copied

Legend:

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

    r67750 r67931  
    435435        src/widgets/UIHotKeyEditor.h \
    436436        src/widgets/UILineTextEdit.h \
     437        src/widgets/UIMediumSizeEditor.h \
    437438        src/widgets/UIMenuBar.h \
    438439        src/widgets/UIPopupBox.h \
     
    748749        src/widgets/UIHotKeyEditor.cpp \
    749750        src/widgets/UILineTextEdit.cpp \
     751        src/widgets/UIMediumSizeEditor.cpp \
    750752        src/widgets/UIMenuBar.cpp \
    751753        src/widgets/UIPopupBox.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDetailsWidget.cpp

    r67923 r67931  
    3737# include "UIIconPool.h"
    3838# include "UIMediumDetailsWidget.h"
     39# include "UIMediumSizeEditor.h"
    3940# include "VBoxGlobal.h"
    4041
     
    5354    , m_pLabelType(0), m_pComboBoxType(0), m_pErrorPaneType(0)
    5455    , m_pLabelLocation(0), m_pSelectorLocation(0), m_pErrorPaneLocation(0)
    55     , m_uMediumSizeMin(_4M)
    56     , m_uMediumSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize())
    57     , m_iSliderScale(calculateSliderScale(m_uMediumSizeMax))
    58     , m_pLabelSize(0), m_pSliderSize(0), m_pLabelMinSize(0), m_pLabelMaxSize(0), m_pEditorSize(0), m_pErrorPaneSize(0)
     56    , m_pLabelSize(0), m_pEditorSize(0), m_pErrorPaneSize(0)
    5957    , m_pButtonBox(0)
    6058    , m_pLayoutDetails(0)
     
    9593    m_pLabelLocation->setText(tr("&Location:"));
    9694    m_pLabelSize->setText(tr("&Size:"));
    97     m_pLabelMinSize->setText(vboxGlobal().formatSize(m_uMediumSizeMin));
    98     m_pLabelMaxSize->setText(vboxGlobal().formatSize(m_uMediumSizeMax));
    9995
    10096    /* Translate fields: */
     
    10399        m_pComboBoxType->setItemText(i, gpConverter->toString(m_pComboBoxType->itemData(i).value<KMediumType>()));
    104100    m_pSelectorLocation->setToolTip(tr("Holds the location of this medium."));
    105     m_pSliderSize->setToolTip(tr("Holds the size of this medium."));
    106101    m_pEditorSize->setToolTip(tr("Holds the size of this medium."));
    107102
     
    141136}
    142137
    143 void UIMediumDetailsWidget::sltSizeSliderChanged(int iValue)
    144 {
    145     m_newData.m_options.m_uLogicalSize = sliderToSizeMB(iValue, m_iSliderScale);
    146     m_pEditorSize->blockSignals(true);
    147     m_pEditorSize->setText(vboxGlobal().formatSize(m_newData.m_options.m_uLogicalSize));
    148     m_pEditorSize->blockSignals(false);
     138void UIMediumDetailsWidget::sltSizeEditorChanged(qulonglong uSize)
     139{
     140    m_newData.m_options.m_uLogicalSize = uSize;
    149141    revalidate(m_pErrorPaneSize);
    150     updateSizeToolTips(m_newData.m_options.m_uLogicalSize);
    151     updateButtonStates();
    152 }
    153 
    154 void UIMediumDetailsWidget::sltSizeEditorChanged(const QString &strValue)
    155 {
    156     m_newData.m_options.m_uLogicalSize = vboxGlobal().parseSize(strValue);
    157     m_pSliderSize->blockSignals(true);
    158     m_pSliderSize->setValue(sizeMBToSlider(m_newData.m_options.m_uLogicalSize, m_iSliderScale));
    159     m_pSliderSize->blockSignals(false);
    160     revalidate(m_pErrorPaneSize);
    161     updateSizeToolTips(m_newData.m_options.m_uLogicalSize);
    162142    updateButtonStates();
    163143}
     
    357337                /* Configure layout: */
    358338                pLayoutSize->setContentsMargins(0, 0, 0, 0);
    359                 pLayoutSize->setColumnStretch(0, 1);
    360                 pLayoutSize->setColumnStretch(1, 1);
    361                 pLayoutSize->setColumnStretch(2, 0);
    362                 pLayoutSize->setColumnStretch(3, 0);
    363 
    364                 /* Create size slider: */
    365                 m_pSliderSize = new QSlider;
    366                 AssertPtrReturnVoid(m_pSliderSize);
    367                 {
    368                     /* Configure slider: */
    369                     m_pSliderSize->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    370                     m_pSliderSize->setOrientation(Qt::Horizontal);
    371                     m_pSliderSize->setTickPosition(QSlider::TicksBelow);
    372                     m_pSliderSize->setFocusPolicy(Qt::StrongFocus);
    373                     m_pSliderSize->setPageStep(m_iSliderScale);
    374                     m_pSliderSize->setSingleStep(m_iSliderScale / 8);
    375                     m_pSliderSize->setTickInterval(0);
    376                     m_pSliderSize->setMinimum(sizeMBToSlider(m_uMediumSizeMin, m_iSliderScale));
    377                     m_pSliderSize->setMaximum(sizeMBToSlider(m_uMediumSizeMax, m_iSliderScale));
    378                     connect(m_pSliderSize, &QSlider::valueChanged,
    379                             this, &UIMediumDetailsWidget::sltSizeSliderChanged);
    380 
    381                     /* Add into layout: */
    382                     pLayoutSize->addWidget(m_pSliderSize, 0, 0, 1, 2);
    383                 }
    384 
    385                 /* Create minimum size label: */
    386                 m_pLabelMinSize = new QLabel;
    387                 AssertPtrReturnVoid(m_pLabelMinSize);
    388                 {
    389                     /* Configure label: */
    390                     m_pLabelMinSize->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    391 
    392                     /* Add into layout: */
    393                     pLayoutSize->addWidget(m_pLabelMinSize, 1, 0);
    394                 }
    395 
    396                 /* Create maximum size label: */
    397                 m_pLabelMaxSize = new QLabel;
    398                 AssertPtrReturnVoid(m_pLabelMaxSize);
    399                 {
    400                     /* Configure label: */
    401                     m_pLabelMaxSize->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    402 
    403                     /* Add into layout: */
    404                     pLayoutSize->addWidget(m_pLabelMaxSize, 1, 1);
    405                 }
    406339
    407340                /* Create size editor: */
    408                 m_pEditorSize = new QILineEdit;
     341                m_pEditorSize = new UIMediumSizeEditor;
    409342                AssertPtrReturnVoid(m_pEditorSize);
    410343                {
    411344                    /* Configure editor: */
    412345                    m_pLabelSize->setBuddy(m_pEditorSize);
    413                     m_pEditorSize->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    414                     m_pEditorSize->setFixedWidthByText("88888.88 MB");
    415                     m_pEditorSize->setAlignment(Qt::AlignRight);
    416                     m_pEditorSize->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
    417                     connect(m_pEditorSize, &QILineEdit::textChanged,
     346                    m_pEditorSize->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     347                    connect(m_pEditorSize, &UIMediumSizeEditor::sigSizeChanged,
    418348                            this, &UIMediumDetailsWidget::sltSizeEditorChanged);
    419349
    420350                    /* Add into layout: */
    421                     pLayoutSize->addWidget(m_pEditorSize, 0, 2);
     351                    pLayoutSize->addWidget(m_pEditorSize, 0, 0, 2, 1);
    422352                }
    423353
     
    432362
    433363                    /* Add into layout: */
    434                     pLayoutSize->addWidget(m_pErrorPaneSize, 0, 3);
     364                    pLayoutSize->addWidget(m_pErrorPaneSize, 0, 1);
    435365                }
    436366
     
    592522    /* Load size: */
    593523    m_pLabelSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    594     m_pSliderSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    595     m_pLabelMinSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    596     m_pLabelMaxSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    597524    m_pEditorSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    598     m_pEditorSize->setText(vboxGlobal().formatSize(m_newData.m_options.m_uLogicalSize));
     525    m_pEditorSize->setMediumSize(m_newData.m_options.m_uLogicalSize);
    599526}
    600527
     
    673600}
    674601
    675 /* static */
    676 int UIMediumDetailsWidget::calculateSliderScale(qulonglong uMaximumMediumSize)
    677 {
    678     /* Detect how many steps to recognize between adjacent powers of 2
    679      * to ensure that the last slider step is exactly that we need: */
    680     int iSliderScale = 0;
    681     int iPower = log2i(uMaximumMediumSize);
    682     qulonglong uTickMB = (qulonglong)1 << iPower;
    683     if (uTickMB < uMaximumMediumSize)
    684     {
    685         qulonglong uTickMBNext = (qulonglong)1 << (iPower + 1);
    686         qulonglong uGap = uTickMBNext - uMaximumMediumSize;
    687         iSliderScale = (int)((uTickMBNext - uTickMB) / uGap);
    688 #ifdef VBOX_WS_MAC
    689         // WORKAROUND:
    690         // There is an issue with Qt5 QSlider under OSX:
    691         // Slider tick count (maximum - minimum) is limited with some
    692         // "magical number" - 588351, having it more than that brings
    693         // unpredictable results like slider token jumping and disappearing,
    694         // so we are limiting tick count by lowering slider-scale 128 times.
    695         iSliderScale /= 128;
    696 #endif /* VBOX_WS_MAC */
    697     }
    698     return qMax(iSliderScale, 8);
    699 }
    700 
    701 /* static */
    702 int UIMediumDetailsWidget::log2i(qulonglong uValue)
    703 {
    704     int iPower = -1;
    705     while (uValue)
    706     {
    707         ++iPower;
    708         uValue >>= 1;
    709     }
    710     return iPower;
    711 }
    712 
    713 /* static */
    714 int UIMediumDetailsWidget::sizeMBToSlider(qulonglong uValue, int iSliderScale)
    715 {
    716     /* Make sure *any* slider value is multiple of 512: */
    717     uValue /= 512;
    718 
    719     /* Calculate result: */
    720     int iPower = log2i(uValue);
    721     qulonglong uTickMB = qulonglong (1) << iPower;
    722     qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    723     int iStep = (uValue - uTickMB) * iSliderScale / (uTickMBNext - uTickMB);
    724     int iResult = iPower * iSliderScale + iStep;
    725 
    726     /* Return result: */
    727     return iResult;
    728 }
    729 
    730 /* static */
    731 qulonglong UIMediumDetailsWidget::sliderToSizeMB(int uValue, int iSliderScale)
    732 {
    733     /* Calculate result: */
    734     int iPower = uValue / iSliderScale;
    735     int iStep = uValue % iSliderScale;
    736     qulonglong uTickMB = qulonglong (1) << iPower;
    737     qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    738     qulonglong uResult = uTickMB + (uTickMBNext - uTickMB) * iStep / iSliderScale;
    739 
    740     /* Make sure *any* slider value is multiple of 512: */
    741     uResult *= 512;
    742 
    743     /* Return result: */
    744     return uResult;
    745 }
    746 
    747 void UIMediumDetailsWidget::updateSizeToolTips(qulonglong uSize)
    748 {
    749     const QString strToolTip = tr("<nobr>%1 (%2 B)</nobr>").arg(vboxGlobal().formatSize(uSize)).arg(uSize);
    750     m_pSliderSize->setToolTip(strToolTip);
    751     m_pEditorSize->setToolTip(strToolTip);
    752 }
    753 
    754602QWidget *UIMediumDetailsWidget::infoContainer(UIMediumType enmType) const
    755603{
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDetailsWidget.h

    r67923 r67931  
    3434class QComboBox;
    3535class QLabel;
    36 class QSlider;
    3736class QStackedLayout;
    3837class QWidget;
    3938class QILabel;
    40 class QILineEdit;
    4139class QITabWidget;
    4240class UIFilePathSelector;
     41class UIMediumSizeEditor;
    4342
    4443
     
    196195        /** Handles location change. */
    197196        void sltLocationPathChanged(const QString &strPath);
    198         /** Handles size slider change. */
    199         void sltSizeSliderChanged(int iValue);
    200197        /** Handles size editor change. */
    201         void sltSizeEditorChanged(const QString &strValue);
     198        void sltSizeEditorChanged(qulonglong uSize);
    202199
    203200        /** Handles button-box button click. */
     
    239236        /** Updates button states. */
    240237        void updateButtonStates();
    241 
    242         /** Calculates slider scale according to passed @a uMaximumMediumSize. */
    243         static int calculateSliderScale(qulonglong uMaximumMediumSize);
    244         /** Returns log2 for passed @a uValue. */
    245         static int log2i(qulonglong uValue);
    246         /** Converts passed bytes @a uValue to slides scaled value using @a iSliderScale. */
    247         static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
    248         /** Converts passed slider @a uValue to bytes unscaled value using @a iSliderScale. */
    249         static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
    250         /** Updates slider/editor tool-tips. */
    251         void updateSizeToolTips(qulonglong uSize);
    252238    /** @} */
    253239
     
    292278        QLabel    *m_pErrorPaneLocation;
    293279
    294         /** Holds the minimum medium size. */
    295         const qulonglong  m_uMediumSizeMin;
    296         /** Holds the maximum medium size. */
    297         const qulonglong  m_uMediumSizeMax;
    298         /** Holds the slider scale. */
    299         const int         m_iSliderScale;
    300280        /** Holds the size label. */
    301         QLabel           *m_pLabelSize;
    302         /** Holds the size slider. */
    303         QSlider          *m_pSliderSize;
    304         /** Holds the minimum size label. */
    305         QLabel           *m_pLabelMinSize;
    306         /** Holds the maximum size label. */
    307         QLabel           *m_pLabelMaxSize;
     281        QLabel             *m_pLabelSize;
    308282        /** Holds the size editor. */
    309         QILineEdit      *m_pEditorSize;
     283        UIMediumSizeEditor *m_pEditorSize;
    310284        /** Holds the size error pane. */
    311         QLabel           *m_pErrorPaneSize;
     285        QLabel             *m_pErrorPaneSize;
    312286
    313287        /** Holds the button-box instance. */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp

    r67923 r67931  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIMediumDetailsWidget class implementation.
     3 * VBox Qt GUI - UIMediumSizeEditor class implementation.
    44 */
    55
     
    2121
    2222/* Qt includes: */
    23 # include <QComboBox>
     23# include <QGridLayout>
    2424# include <QLabel>
    25 # include <QPushButton>
     25# include <QRegExpValidator>
    2626# include <QSlider>
    27 # include <QStackedLayout>
    28 # include <QVBoxLayout>
    2927
    3028/* GUI includes: */
    31 # include "QIDialogButtonBox.h"
    32 # include "QILabel.h"
    3329# include "QILineEdit.h"
    34 # include "QITabWidget.h"
    35 # include "UIConverter.h"
    36 # include "UIFilePathSelector.h"
    37 # include "UIIconPool.h"
    38 # include "UIMediumDetailsWidget.h"
     30# include "UIMediumSizeEditor.h"
    3931# include "VBoxGlobal.h"
    4032
     
    4537
    4638
    47 UIMediumDetailsWidget::UIMediumDetailsWidget(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */)
     39UIMediumSizeEditor::UIMediumSizeEditor(QWidget *pParent /* = 0 */)
    4840    : QIWithRetranslateUI<QWidget>(pParent)
    49     , m_enmEmbedding(enmEmbedding)
    50     , m_oldData(UIDataMedium())
    51     , m_newData(UIDataMedium())
    52     , m_pTabWidget(0)
    53     , m_pLabelType(0), m_pComboBoxType(0), m_pErrorPaneType(0)
    54     , m_pLabelLocation(0), m_pSelectorLocation(0), m_pErrorPaneLocation(0)
    55     , m_uMediumSizeMin(_4M)
    56     , m_uMediumSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize())
    57     , m_iSliderScale(calculateSliderScale(m_uMediumSizeMax))
    58     , m_pLabelSize(0), m_pSliderSize(0), m_pLabelMinSize(0), m_pLabelMaxSize(0), m_pEditorSize(0), m_pErrorPaneSize(0)
    59     , m_pButtonBox(0)
    60     , m_pLayoutDetails(0)
     41    , m_uSizeMin(_4M)
     42    , m_uSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize())
     43    , m_iSliderScale(calculateSliderScale(m_uSizeMax))
     44    , m_pSlider(0)
     45    , m_pLabelMinSize(0)
     46    , m_pLabelMaxSize(0)
     47    , m_pEditor(0)
    6148{
    6249    /* Prepare: */
     
    6451}
    6552
    66 void UIMediumDetailsWidget::setCurrentType(UIMediumType enmType)
    67 {
    68     /* If known type was requested => raise corresponding container: */
    69     if (m_aContainers.contains(enmType))
    70         m_pLayoutDetails->setCurrentWidget(infoContainer(enmType));
    71 }
    72 
    73 void UIMediumDetailsWidget::setData(const UIDataMedium &data)
    74 {
    75     /* Cache old/new data: */
    76     m_oldData = data;
    77     m_newData = m_oldData;
    78 
    79     /* Load options data: */
    80     loadDataForOptions();
    81     /* Load details data: */
    82     loadDataForDetails();
    83 }
    84 
    85 void UIMediumDetailsWidget::retranslateUi()
    86 {
    87     /* Translate tab-widget: */
    88     m_pTabWidget->setTabText(0, tr("&Attributes"));
    89     m_pTabWidget->setTabText(1, tr("&Information"));
    90 
    91     /* Translate 'Options' tab content. */
    92 
     53void UIMediumSizeEditor::setMediumSize(qulonglong uSize)
     54{
     55    /* Remember the new size: */
     56    m_uSize = uSize;
     57    /* And assign it to the slider, editor will be auto-updated: */
     58    m_pSlider->setValue(sizeMBToSlider(m_uSize, m_iSliderScale));
     59}
     60
     61void UIMediumSizeEditor::retranslateUi()
     62{
    9363    /* Translate labels: */
    94     m_pLabelType->setText(tr("&Type:"));
    95     m_pLabelLocation->setText(tr("&Location:"));
    96     m_pLabelSize->setText(tr("&Size:"));
    97     m_pLabelMinSize->setText(vboxGlobal().formatSize(m_uMediumSizeMin));
    98     m_pLabelMaxSize->setText(vboxGlobal().formatSize(m_uMediumSizeMax));
     64    m_pLabelMinSize->setText(vboxGlobal().formatSize(m_uSizeMin));
     65    m_pLabelMaxSize->setText(vboxGlobal().formatSize(m_uSizeMax));
    9966
    10067    /* Translate fields: */
    101     m_pComboBoxType->setToolTip(tr("Holds the type of this medium."));
    102     for (int i = 0; i < m_pComboBoxType->count(); ++i)
    103         m_pComboBoxType->setItemText(i, gpConverter->toString(m_pComboBoxType->itemData(i).value<KMediumType>()));
    104     m_pSelectorLocation->setToolTip(tr("Holds the location of this medium."));
    105     m_pSliderSize->setToolTip(tr("Holds the size of this medium."));
    106     m_pEditorSize->setToolTip(tr("Holds the size of this medium."));
    107 
    108     /* Translate button-box: */
    109     if (m_pButtonBox)
    110     {
    111         m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Reset"));
    112         m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Apply"));
    113         m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
    114         m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
    115         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Reset changes in current medium details"));
    116         m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Apply changes in current medium details"));
    117         m_pButtonBox->button(QDialogButtonBox::Cancel)->
    118             setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString()));
    119         m_pButtonBox->button(QDialogButtonBox::Ok)->
    120             setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
    121     }
    122 
    123     /* Translate 'Details' tab content. */
    124 
    125     /* Retranslate validation: */
    126     retranslateValidation();
    127 }
    128 
    129 void UIMediumDetailsWidget::sltTypeIndexChanged(int iIndex)
    130 {
    131     m_newData.m_options.m_enmType = m_pComboBoxType->itemData(iIndex).value<KMediumType>();
    132     revalidate(m_pErrorPaneType);
    133     updateButtonStates();
    134 }
    135 
    136 void UIMediumDetailsWidget::sltLocationPathChanged(const QString &strPath)
    137 {
    138     m_newData.m_options.m_strLocation = strPath;
    139     revalidate(m_pErrorPaneLocation);
    140     updateButtonStates();
    141 }
    142 
    143 void UIMediumDetailsWidget::sltSizeSliderChanged(int iValue)
    144 {
    145     m_newData.m_options.m_uLogicalSize = sliderToSizeMB(iValue, m_iSliderScale);
    146     m_pEditorSize->blockSignals(true);
    147     m_pEditorSize->setText(vboxGlobal().formatSize(m_newData.m_options.m_uLogicalSize));
    148     m_pEditorSize->blockSignals(false);
    149     revalidate(m_pErrorPaneSize);
    150     updateSizeToolTips(m_newData.m_options.m_uLogicalSize);
    151     updateButtonStates();
    152 }
    153 
    154 void UIMediumDetailsWidget::sltSizeEditorChanged(const QString &strValue)
    155 {
    156     m_newData.m_options.m_uLogicalSize = vboxGlobal().parseSize(strValue);
    157     m_pSliderSize->blockSignals(true);
    158     m_pSliderSize->setValue(sizeMBToSlider(m_newData.m_options.m_uLogicalSize, m_iSliderScale));
    159     m_pSliderSize->blockSignals(false);
    160     revalidate(m_pErrorPaneSize);
    161     updateSizeToolTips(m_newData.m_options.m_uLogicalSize);
    162     updateButtonStates();
    163 }
    164 
    165 void UIMediumDetailsWidget::sltHandleButtonBoxClick(QAbstractButton *pButton)
    166 {
    167     /* Make sure button-box exists: */
    168     AssertPtrReturnVoid(m_pButtonBox);
    169 
    170     /* Disable buttons first of all: */
    171     m_pButtonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
    172     m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
    173 
    174     /* Compare with known buttons: */
    175     if (pButton == m_pButtonBox->button(QDialogButtonBox::Cancel))
    176         emit sigDataChangeRejected();
    177     else
    178     if (pButton == m_pButtonBox->button(QDialogButtonBox::Ok))
    179         emit sigDataChangeAccepted();
    180 }
    181 
    182 void UIMediumDetailsWidget::prepare()
    183 {
    184     /* Prepare this: */
    185     prepareThis();
    186 
    187     /* Apply language settings: */
    188     retranslateUi();
    189 
    190     /* Update button states finally: */
    191     updateButtonStates();
    192 }
    193 
    194 void UIMediumDetailsWidget::prepareThis()
     68    m_pSlider->setToolTip(tr("Holds the size of this medium."));
     69    m_pEditor->setToolTip(tr("Holds the size of this medium."));
     70
     71    /* Translate tool-tips: */
     72    updateSizeToolTips(m_uSize);
     73}
     74
     75void UIMediumSizeEditor::sltSizeSliderChanged(int iValue)
     76{
     77    /* Update the current size: */
     78    m_uSize = sliderToSizeMB(iValue, m_iSliderScale);
     79    /* Update the other widget: */
     80    m_pEditor->blockSignals(true);
     81    m_pEditor->setText(vboxGlobal().formatSize(m_uSize));
     82    m_pEditor->blockSignals(false);
     83    /* Update the tool-tips: */
     84    updateSizeToolTips(m_uSize);
     85    /* Notify the listeners: */
     86    emit sigSizeChanged(m_uSize);
     87}
     88
     89void UIMediumSizeEditor::sltSizeEditorChanged(const QString &strValue)
     90{
     91    /* Update the current size: */
     92    m_uSize = vboxGlobal().parseSize(strValue);
     93    /* Update the other widget: */
     94    m_pSlider->blockSignals(true);
     95    m_pSlider->setValue(sizeMBToSlider(m_uSize, m_iSliderScale));
     96    m_pSlider->blockSignals(false);
     97    /* Update the tool-tips: */
     98    updateSizeToolTips(m_uSize);
     99    /* Notify the listeners: */
     100    emit sigSizeChanged(m_uSize);
     101}
     102
     103void UIMediumSizeEditor::prepare()
    195104{
    196105    /* Create layout: */
    197     QVBoxLayout *pLayout = new QVBoxLayout(this);
     106    QGridLayout *pLayout = new QGridLayout(this);
    198107    AssertPtrReturnVoid(pLayout);
    199108    {
    200109        /* Configure layout: */
    201110        pLayout->setContentsMargins(0, 0, 0, 0);
    202 
    203         /* Prepare tab-widget: */
    204         prepareTabWidget();
     111        pLayout->setColumnStretch(0, 1);
     112        pLayout->setColumnStretch(1, 1);
     113        pLayout->setColumnStretch(2, 0);
     114
     115        /* Create size slider: */
     116        m_pSlider = new QSlider;
     117        AssertPtrReturnVoid(m_pSlider);
     118        {
     119            /* Configure slider: */
     120            m_pSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     121            m_pSlider->setOrientation(Qt::Horizontal);
     122            m_pSlider->setTickPosition(QSlider::TicksBelow);
     123            m_pSlider->setFocusPolicy(Qt::StrongFocus);
     124            m_pSlider->setPageStep(m_iSliderScale);
     125            m_pSlider->setSingleStep(m_iSliderScale / 8);
     126            m_pSlider->setTickInterval(0);
     127            m_pSlider->setMinimum(sizeMBToSlider(m_uSizeMin, m_iSliderScale));
     128            m_pSlider->setMaximum(sizeMBToSlider(m_uSizeMax, m_iSliderScale));
     129            connect(m_pSlider, &QSlider::valueChanged,
     130                    this, &UIMediumSizeEditor::sltSizeSliderChanged);
     131
     132            /* Add into layout: */
     133            pLayout->addWidget(m_pSlider, 0, 0, 1, 2);
     134        }
     135
     136        /* Create minimum size label: */
     137        m_pLabelMinSize = new QLabel;
     138        AssertPtrReturnVoid(m_pLabelMinSize);
     139        {
     140            /* Configure label: */
     141            m_pLabelMinSize->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
     142
     143            /* Add into layout: */
     144            pLayout->addWidget(m_pLabelMinSize, 1, 0);
     145        }
     146
     147        /* Create maximum size label: */
     148        m_pLabelMaxSize = new QLabel;
     149        AssertPtrReturnVoid(m_pLabelMaxSize);
     150        {
     151            /* Configure label: */
     152            m_pLabelMaxSize->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
     153
     154            /* Add into layout: */
     155            pLayout->addWidget(m_pLabelMaxSize, 1, 1);
     156        }
     157
     158        /* Create size editor: */
     159        m_pEditor = new QILineEdit;
     160        AssertPtrReturnVoid(m_pEditor);
     161        {
     162            /* Configure editor: */
     163            m_pEditor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     164            m_pEditor->setFixedWidthByText("88888.88 MB");
     165            m_pEditor->setAlignment(Qt::AlignRight);
     166            m_pEditor->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
     167            connect(m_pEditor, &QILineEdit::textChanged,
     168                    this, &UIMediumSizeEditor::sltSizeEditorChanged);
     169
     170            /* Add into layout: */
     171            pLayout->addWidget(m_pEditor, 0, 2);
     172        }
    205173    }
    206 }
    207 
    208 void UIMediumDetailsWidget::prepareTabWidget()
    209 {
    210     /* Create tab-widget: */
    211     m_pTabWidget = new QITabWidget;
    212     AssertPtrReturnVoid(m_pTabWidget);
    213     {
    214         /* Prepare 'Options' tab: */
    215         prepareTabOptions();
    216         /* Prepare 'Details' tab: */
    217         prepareTabDetails();
    218 
    219         /* Add into layout: */
    220         layout()->addWidget(m_pTabWidget);
    221     }
    222 }
    223 
    224 void UIMediumDetailsWidget::prepareTabOptions()
    225 {
    226     /* Create 'Options' tab: */
    227     QWidget *pTabOptions = new QWidget;
    228     AssertPtrReturnVoid(pTabOptions);
    229     {
    230         /* Create 'Options' layout: */
    231         QGridLayout *pLayoutOptions = new QGridLayout(pTabOptions);
    232         AssertPtrReturnVoid(pLayoutOptions);
    233         {
    234 #ifdef VBOX_WS_MAC
    235             /* Configure layout: */
    236             pLayoutOptions->setSpacing(10);
    237             pLayoutOptions->setContentsMargins(10, 10, 10, 10);
    238 #endif
    239 
    240             /* Get the required icon metric: */
    241             const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    242 
    243             /* Create type label: */
    244             m_pLabelType = new QLabel;
    245             AssertPtrReturnVoid(m_pLabelType);
    246             {
    247                 /* Configure label: */
    248                 m_pLabelType->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    249 
    250                 /* Add into layout: */
    251                 pLayoutOptions->addWidget(m_pLabelType, 0, 0);
    252             }
    253 
    254             /* Create type layout: */
    255             QHBoxLayout *pLayoutType = new QHBoxLayout;
    256             AssertPtrReturnVoid(pLayoutType);
    257             {
    258                 /* Configure layout: */
    259                 pLayoutType->setContentsMargins(0, 0, 0, 0);
    260 
    261                 /* Create type editor: */
    262                 m_pComboBoxType = new QComboBox;
    263                 AssertPtrReturnVoid(m_pComboBoxType);
    264                 {
    265                     /* Configure editor: */
    266                     m_pLabelType->setBuddy(m_pComboBoxType);
    267                     m_pComboBoxType->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    268                     connect(m_pComboBoxType, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
    269                             this, &UIMediumDetailsWidget::sltTypeIndexChanged);
    270 
    271                     /* Add into layout: */
    272                     pLayoutType->addWidget(m_pComboBoxType);
    273                 }
    274 
    275                 /* Create type error pane: */
    276                 m_pErrorPaneType = new QLabel;
    277                 AssertPtrReturnVoid(m_pErrorPaneType);
    278                 {
    279                     /* Configure label: */
    280                     m_pErrorPaneType->setAlignment(Qt::AlignCenter);
    281                     m_pErrorPaneType->setPixmap(UIIconPool::iconSet(":/status_error_16px.png")
    282                                                 .pixmap(QSize(iIconMetric, iIconMetric)));
    283 
    284                     /* Add into layout: */
    285                     pLayoutType->addWidget(m_pErrorPaneType);
    286                 }
    287 
    288                 /* Add into layout: */
    289                 pLayoutOptions->addLayout(pLayoutType, 0, 1);
    290             }
    291 
    292             /* Create location label: */
    293             m_pLabelLocation = new QLabel;
    294             AssertPtrReturnVoid(m_pLabelLocation);
    295             {
    296                 /* Configure label: */
    297                 m_pLabelLocation->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    298 
    299                 /* Add into layout: */
    300                 pLayoutOptions->addWidget(m_pLabelLocation, 1, 0);
    301             }
    302 
    303             /* Create location layout: */
    304             QHBoxLayout *pLayoutLocation = new QHBoxLayout;
    305             AssertPtrReturnVoid(pLayoutLocation);
    306             {
    307                 /* Configure layout: */
    308                 pLayoutLocation->setContentsMargins(0, 0, 0, 0);
    309 
    310                 /* Create location editor: */
    311                 m_pSelectorLocation = new UIFilePathSelector;
    312                 AssertPtrReturnVoid(m_pSelectorLocation);
    313                 {
    314                     /* Configure editor: */
    315                     m_pLabelLocation->setBuddy(m_pSelectorLocation);
    316                     m_pSelectorLocation->setResetEnabled(false);
    317                     m_pSelectorLocation->setMode(UIFilePathSelector::Mode_File_Save);
    318                     m_pSelectorLocation->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    319                     connect(m_pSelectorLocation, &UIFilePathSelector::pathChanged,
    320                             this, &UIMediumDetailsWidget::sltLocationPathChanged);
    321 
    322                     /* Add into layout: */
    323                     pLayoutLocation->addWidget(m_pSelectorLocation);
    324                 }
    325 
    326                 /* Create location error pane: */
    327                 m_pErrorPaneLocation = new QLabel;
    328                 AssertPtrReturnVoid(m_pErrorPaneLocation);
    329                 {
    330                     /* Configure label: */
    331                     m_pErrorPaneLocation->setAlignment(Qt::AlignCenter);
    332                     m_pErrorPaneLocation->setPixmap(UIIconPool::iconSet(":/status_error_16px.png")
    333                                                     .pixmap(QSize(iIconMetric, iIconMetric)));
    334                     /* Add into layout: */
    335                     pLayoutLocation->addWidget(m_pErrorPaneLocation);
    336                 }
    337 
    338                 /* Add into layout: */
    339                 pLayoutOptions->addLayout(pLayoutLocation, 1, 1);
    340             }
    341 
    342             /* Create size label: */
    343             m_pLabelSize = new QLabel;
    344             AssertPtrReturnVoid(m_pLabelSize);
    345             {
    346                 /* Configure label: */
    347                 m_pLabelSize->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    348 
    349                 /* Add into layout: */
    350                 pLayoutOptions->addWidget(m_pLabelSize, 2, 0);
    351             }
    352 
    353             /* Create size layout: */
    354             QGridLayout *pLayoutSize = new QGridLayout;
    355             AssertPtrReturnVoid(pLayoutSize);
    356             {
    357                 /* Configure layout: */
    358                 pLayoutSize->setContentsMargins(0, 0, 0, 0);
    359                 pLayoutSize->setColumnStretch(0, 1);
    360                 pLayoutSize->setColumnStretch(1, 1);
    361                 pLayoutSize->setColumnStretch(2, 0);
    362                 pLayoutSize->setColumnStretch(3, 0);
    363 
    364                 /* Create size slider: */
    365                 m_pSliderSize = new QSlider;
    366                 AssertPtrReturnVoid(m_pSliderSize);
    367                 {
    368                     /* Configure slider: */
    369                     m_pSliderSize->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    370                     m_pSliderSize->setOrientation(Qt::Horizontal);
    371                     m_pSliderSize->setTickPosition(QSlider::TicksBelow);
    372                     m_pSliderSize->setFocusPolicy(Qt::StrongFocus);
    373                     m_pSliderSize->setPageStep(m_iSliderScale);
    374                     m_pSliderSize->setSingleStep(m_iSliderScale / 8);
    375                     m_pSliderSize->setTickInterval(0);
    376                     m_pSliderSize->setMinimum(sizeMBToSlider(m_uMediumSizeMin, m_iSliderScale));
    377                     m_pSliderSize->setMaximum(sizeMBToSlider(m_uMediumSizeMax, m_iSliderScale));
    378                     connect(m_pSliderSize, &QSlider::valueChanged,
    379                             this, &UIMediumDetailsWidget::sltSizeSliderChanged);
    380 
    381                     /* Add into layout: */
    382                     pLayoutSize->addWidget(m_pSliderSize, 0, 0, 1, 2);
    383                 }
    384 
    385                 /* Create minimum size label: */
    386                 m_pLabelMinSize = new QLabel;
    387                 AssertPtrReturnVoid(m_pLabelMinSize);
    388                 {
    389                     /* Configure label: */
    390                     m_pLabelMinSize->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    391 
    392                     /* Add into layout: */
    393                     pLayoutSize->addWidget(m_pLabelMinSize, 1, 0);
    394                 }
    395 
    396                 /* Create maximum size label: */
    397                 m_pLabelMaxSize = new QLabel;
    398                 AssertPtrReturnVoid(m_pLabelMaxSize);
    399                 {
    400                     /* Configure label: */
    401                     m_pLabelMaxSize->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    402 
    403                     /* Add into layout: */
    404                     pLayoutSize->addWidget(m_pLabelMaxSize, 1, 1);
    405                 }
    406 
    407                 /* Create size editor: */
    408                 m_pEditorSize = new QILineEdit;
    409                 AssertPtrReturnVoid(m_pEditorSize);
    410                 {
    411                     /* Configure editor: */
    412                     m_pLabelSize->setBuddy(m_pEditorSize);
    413                     m_pEditorSize->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    414                     m_pEditorSize->setFixedWidthByText("88888.88 MB");
    415                     m_pEditorSize->setAlignment(Qt::AlignRight);
    416                     m_pEditorSize->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
    417                     connect(m_pEditorSize, &QILineEdit::textChanged,
    418                             this, &UIMediumDetailsWidget::sltSizeEditorChanged);
    419 
    420                     /* Add into layout: */
    421                     pLayoutSize->addWidget(m_pEditorSize, 0, 2);
    422                 }
    423 
    424                 /* Create size error pane: */
    425                 m_pErrorPaneSize = new QLabel;
    426                 AssertPtrReturnVoid(m_pErrorPaneSize);
    427                 {
    428                     /* Configure label: */
    429                     m_pErrorPaneSize->setAlignment(Qt::AlignCenter);
    430                     m_pErrorPaneSize->setPixmap(UIIconPool::iconSet(":/status_error_16px.png")
    431                                                     .pixmap(QSize(iIconMetric, iIconMetric)));
    432 
    433                     /* Add into layout: */
    434                     pLayoutSize->addWidget(m_pErrorPaneSize, 0, 3);
    435                 }
    436 
    437                 /* Add into layout: */
    438                 pLayoutOptions->addLayout(pLayoutSize, 2, 1, 2, 1);
    439             }
    440 
    441             /* Create stretch: */
    442             QSpacerItem *pSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    443             AssertPtrReturnVoid(pSpacer2);
    444             {
    445                 /* Add into layout: */
    446                 pLayoutOptions->addItem(pSpacer2, 4, 0, 1, 2);
    447             }
    448 
    449             /* If parent embedded into stack: */
    450             if (m_enmEmbedding == EmbedTo_Stack)
    451             {
    452                 /* Create button-box: */
    453                 m_pButtonBox = new QIDialogButtonBox;
    454                 AssertPtrReturnVoid(m_pButtonBox);
    455                 /* Configure button-box: */
    456                 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
    457                 connect(m_pButtonBox, &QIDialogButtonBox::clicked, this, &UIMediumDetailsWidget::sltHandleButtonBoxClick);
    458 
    459                 /* Add into layout: */
    460                 pLayoutOptions->addWidget(m_pButtonBox, 5, 0, 1, 2);
    461             }
    462         }
    463 
    464         /* Add to tab-widget: */
    465         m_pTabWidget->addTab(pTabOptions, QString());
    466     }
    467 }
    468 
    469 void UIMediumDetailsWidget::prepareTabDetails()
    470 {
    471     /* Create 'Details' tab: */
    472     QWidget *pTabDetails = new QWidget;
    473     AssertPtrReturnVoid(pTabDetails);
    474     {
    475         /* Create stacked layout: */
    476         m_pLayoutDetails = new QStackedLayout(pTabDetails);
    477         AssertPtrReturnVoid(m_pLayoutDetails);
    478         {
    479             /* Create information-containers: */
    480             for (int i = (int)UIMediumType_HardDisk; i < (int)UIMediumType_All; ++i)
    481             {
    482                 const UIMediumType enmType = (UIMediumType)i;
    483                 prepareInformationContainer(enmType, enmType == UIMediumType_HardDisk ? 6 : 3); /// @todo Remove hard-coded values.
    484             }
    485         }
    486 
    487         /* Add to tab-widget: */
    488         m_pTabWidget->addTab(pTabDetails, QString());
    489     }
    490 }
    491 
    492 void UIMediumDetailsWidget::prepareInformationContainer(UIMediumType enmType, int cFields)
    493 {
    494     /* Create information-container: */
    495     m_aContainers[enmType] = new QWidget;
    496     QWidget *pContainer = infoContainer(enmType);
    497     AssertPtrReturnVoid(pContainer);
    498     {
    499         /* Create layout: */
    500         new QGridLayout(pContainer);
    501         QGridLayout *pLayout = qobject_cast<QGridLayout*>(pContainer->layout());
    502         AssertPtrReturnVoid(pLayout);
    503         {
    504             /* Configure layout: */
    505             pLayout->setVerticalSpacing(0);
    506             pLayout->setContentsMargins(5, 5, 5, 5);
    507             pLayout->setColumnStretch(1, 1);
    508 
    509             /* Create labels & fields: */
    510             int i = 0;
    511             for (; i < cFields; ++i)
    512             {
    513                 /* Create label: */
    514                 m_aLabels[enmType] << new QLabel;
    515                 QLabel *pLabel = infoLabel(enmType, i);
    516                 AssertPtrReturnVoid(pLabel);
    517                 {
    518                     /* Add into layout: */
    519                     pLayout->addWidget(pLabel, i, 0);
    520                 }
    521 
    522                 /* Create field: */
    523                 m_aFields[enmType] << new QILabel;
    524                 QILabel *pField = infoField(enmType, i);
    525                 AssertPtrReturnVoid(pField);
    526                 {
    527                     /* Configure field: */
    528                     pField->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
    529                     pField->setFullSizeSelection(true);
    530 
    531                     /* Add into layout: */
    532                     pLayout->addWidget(pField, i, 1);
    533                 }
    534             }
    535 
    536             /* Create stretch: */
    537             QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    538             AssertPtrReturnVoid(pSpacer);
    539             {
    540                 /* Add into layout: */
    541                 pLayout->addItem(pSpacer, i, 0, 1, 2);
    542             }
    543         }
    544 
    545         /* Add into layout: */
    546         m_pLayoutDetails->addWidget(pContainer);
    547     }
    548 }
    549 
    550 void UIMediumDetailsWidget::loadDataForOptions()
    551 {
    552     /* Clear type combo-box: */
    553     m_pLabelType->setEnabled(m_newData.m_fValid);
    554     m_pComboBoxType->setEnabled(m_newData.m_fValid);
    555     m_pComboBoxType->clear();
    556     if (m_newData.m_fValid)
    557     {
    558         /* Populate type combo-box: */
    559         switch (m_newData.m_enmType)
    560         {
    561             case UIMediumType_DVD:
    562             case UIMediumType_Floppy:
    563                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_Readonly));
    564                 break;
    565             case UIMediumType_HardDisk:
    566                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_Normal));
    567                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_Immutable));
    568                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_Writethrough));
    569                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_Shareable));
    570                 m_pComboBoxType->addItem(QString(), QVariant::fromValue(KMediumType_MultiAttach));
    571                 break;
    572             default:
    573                 break;
    574         }
    575         /* Translate type combo-box: */
    576         for (int i = 0; i < m_pComboBoxType->count(); ++i)
    577             m_pComboBoxType->setItemText(i, gpConverter->toString(m_pComboBoxType->itemData(i).value<KMediumType>()));
    578     }
    579 
    580     /* Choose the item with required type to be the current one: */
    581     for (int i = 0; i < m_pComboBoxType->count(); ++i)
    582         if (m_pComboBoxType->itemData(i).value<KMediumType>() == m_newData.m_options.m_enmType)
    583             m_pComboBoxType->setCurrentIndex(i);
    584     sltTypeIndexChanged(m_pComboBoxType->currentIndex());
    585 
    586     /* Load location: */
    587     m_pLabelLocation->setEnabled(m_newData.m_fValid);
    588     m_pSelectorLocation->setEnabled(m_newData.m_fValid);
    589     m_pSelectorLocation->setPath(m_newData.m_options.m_strLocation);
    590     sltLocationPathChanged(m_pSelectorLocation->path());
    591 
    592     /* Load size: */
    593     m_pLabelSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    594     m_pSliderSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    595     m_pLabelMinSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    596     m_pLabelMaxSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    597     m_pEditorSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk);
    598     m_pEditorSize->setText(vboxGlobal().formatSize(m_newData.m_options.m_uLogicalSize));
    599 }
    600 
    601 void UIMediumDetailsWidget::loadDataForDetails()
    602 {
    603     /* Get information-labels just to acquire their number: */
    604     const QList<QLabel*> aLabels = m_aLabels.value(m_newData.m_enmType, QList<QLabel*>());
    605     /* Get information-fields just to acquire their number: */
    606     const QList<QILabel*> aFields = m_aFields.value(m_newData.m_enmType, QList<QILabel*>());
    607     /* For each the label => update contents: */
    608     for (int i = 0; i < aLabels.size(); ++i)
    609         infoLabel(m_newData.m_enmType, i)->setText(m_newData.m_details.m_aLabels.value(i, QString()));
    610     /* For each the field => update contents: */
    611     for (int i = 0; i < aFields.size(); ++i)
    612     {
    613         infoField(m_newData.m_enmType, i)->setText(m_newData.m_details.m_aFields.value(i, QString()));
    614         infoField(m_newData.m_enmType, i)->setEnabled(!infoField(m_newData.m_enmType, i)->text().trimmed().isEmpty());
    615     }
    616 }
    617 
    618 void UIMediumDetailsWidget::revalidate(QWidget *pWidget /* = 0 */)
    619 {
    620     /* Validate 'Options' tab content: */
    621     if (!pWidget || pWidget == m_pErrorPaneType)
    622     {
    623         /* Always valid for now: */
    624         const bool fError = false;
    625         m_pErrorPaneType->setVisible(fError);
    626     }
    627     if (!pWidget || pWidget == m_pErrorPaneLocation)
    628     {
    629         /* Always valid for now: */
    630         const bool fError = false;
    631         m_pErrorPaneLocation->setVisible(fError);
    632     }
    633     if (!pWidget || pWidget == m_pErrorPaneSize)
    634     {
    635         /* Always valid for now: */
    636         const bool fError = false;
    637         m_pErrorPaneSize->setVisible(fError);
    638     }
    639 
    640     /* Retranslate validation: */
    641     retranslateValidation(pWidget);
    642 }
    643 
    644 void UIMediumDetailsWidget::retranslateValidation(QWidget * /* pWidget = 0 */)
    645 {
    646     /* Translate 'Interface' tab content: */
    647 //    if (!pWidget || pWidget == m_pErrorPaneType)
    648 //        m_pErrorPaneType->setToolTip(tr("Cannot change from type <b>%1</b> to <b>%2</b>.")
    649 //                                     .arg(m_oldData.m_options.m_enmType).arg(m_newData.m_options.m_enmType));
    650 //    if (!pWidget || pWidget == m_pErrorPaneLocation)
    651 //        m_pErrorPaneLocation->setToolTip(tr("Cannot change medium location from <b>%1</b> to <b>%2</b>.")
    652 //                                         .arg(m_oldData.m_options.m_strLocation).arg(m_newData.m_options.m_strLocation));
    653 //    if (!pWidget || pWidget == m_pErrorPaneSize)
    654 //        m_pErrorPaneSize->setToolTip(tr("Cannot change medium size from <b>%1</b> to <b>%2</b>.")
    655 //                                         .arg(m_oldData.m_options.m_uLogicalSize).arg(m_newData.m_options.m_uLogicalSize));
    656 }
    657 
    658 void UIMediumDetailsWidget::updateButtonStates()
    659 {
    660 //    if (m_oldData != m_newData)
    661 //        printf("Type: %d\n",
    662 //               (int)m_newData.m_enmType);
    663 
    664     /* Update 'Apply' / 'Reset' button states: */
    665     if (m_pButtonBox)
    666     {
    667         m_pButtonBox->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
    668         m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
    669     }
    670 
    671     /* Notify listeners as well: */
    672     emit sigDataChanged(m_oldData != m_newData);
    673 }
    674 
    675 /* static */
    676 int UIMediumDetailsWidget::calculateSliderScale(qulonglong uMaximumMediumSize)
     174
     175    /* Apply language settings: */
     176    retranslateUi();
     177}
     178
     179/* static */
     180int UIMediumSizeEditor::calculateSliderScale(qulonglong uMaximumMediumSize)
    677181{
    678182    /* Detect how many steps to recognize between adjacent powers of 2
     
    700204
    701205/* static */
    702 int UIMediumDetailsWidget::log2i(qulonglong uValue)
     206int UIMediumSizeEditor::log2i(qulonglong uValue)
    703207{
    704208    int iPower = -1;
     
    712216
    713217/* static */
    714 int UIMediumDetailsWidget::sizeMBToSlider(qulonglong uValue, int iSliderScale)
     218int UIMediumSizeEditor::sizeMBToSlider(qulonglong uValue, int iSliderScale)
    715219{
    716220    /* Make sure *any* slider value is multiple of 512: */
     
    729233
    730234/* static */
    731 qulonglong UIMediumDetailsWidget::sliderToSizeMB(int uValue, int iSliderScale)
     235qulonglong UIMediumSizeEditor::sliderToSizeMB(int uValue, int iSliderScale)
    732236{
    733237    /* Calculate result: */
     
    745249}
    746250
    747 void UIMediumDetailsWidget::updateSizeToolTips(qulonglong uSize)
     251void UIMediumSizeEditor::updateSizeToolTips(qulonglong uSize)
    748252{
    749253    const QString strToolTip = tr("<nobr>%1 (%2 B)</nobr>").arg(vboxGlobal().formatSize(uSize)).arg(uSize);
    750     m_pSliderSize->setToolTip(strToolTip);
    751     m_pEditorSize->setToolTip(strToolTip);
    752 }
    753 
    754 QWidget *UIMediumDetailsWidget::infoContainer(UIMediumType enmType) const
    755 {
    756     /* Return information-container for known medium type: */
    757     return m_aContainers.value(enmType, 0);
    758 }
    759 
    760 QLabel *UIMediumDetailsWidget::infoLabel(UIMediumType enmType, int iIndex) const
    761 {
    762     /* Acquire list of labels: */
    763     const QList<QLabel*> aLabels = m_aLabels.value(enmType, QList<QLabel*>());
    764 
    765     /* Return label for known index: */
    766     return aLabels.value(iIndex, 0);
    767 }
    768 
    769 QILabel *UIMediumDetailsWidget::infoField(UIMediumType enmType, int iIndex) const
    770 {
    771     /* Acquire list of fields: */
    772     const QList<QILabel*> aFields = m_aFields.value(enmType, QList<QILabel*>());
    773 
    774     /* Return label for known index: */
    775     return aFields.value(iIndex, 0);
    776 }
    777 
     254    m_pSlider->setToolTip(strToolTip);
     255    m_pEditor->setToolTip(strToolTip);
     256}
     257
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h

    r67923 r67931  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIMediumDetailsWidget class declaration.
     3 * VBox Qt GUI - UIMediumSizeEditor class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___UIMediumDetailsWidget_h___
    19 #define ___UIMediumDetailsWidget_h___
     18#ifndef ___UIMediumSizeEditor_h___
     19#define ___UIMediumSizeEditor_h___
    2020
    2121/* Qt includes: */
     
    2323
    2424/* GUI includes: */
    25 #include "QIManagerDialog.h"
    2625#include "QIWithRetranslateUI.h"
    27 #include "UIMediumDefs.h"
    28 
    29 /* COM includes: */
    30 #include "COMEnums.h"
    3126
    3227/* Forward declarations: */
    33 class QAbstractButton;
    34 class QComboBox;
    3528class QLabel;
    3629class QSlider;
    37 class QStackedLayout;
    38 class QWidget;
    39 class QILabel;
    4030class QILineEdit;
    41 class QITabWidget;
    42 class UIFilePathSelector;
    4331
    4432
    45 /** Virtual Media Manager: Medium options data structure. */
    46 struct UIDataMediumOptions
    47 {
    48     /** Constructs data. */
    49     UIDataMediumOptions()
    50         : m_enmType(KMediumType_Normal)
    51         , m_strLocation(QString())
    52         , m_uLogicalSize(0)
    53     {}
    54 
    55     /** Returns whether the @a other passed data is equal to this one. */
    56     bool equal(const UIDataMediumOptions &other) const
    57     {
    58         return true
    59                && (m_enmType == other.m_enmType)
    60                && (m_strLocation == other.m_strLocation)
    61                && (m_uLogicalSize == other.m_uLogicalSize)
    62                ;
    63     }
    64 
    65     /** Returns whether the @a other passed data is equal to this one. */
    66     bool operator==(const UIDataMediumOptions &other) const { return equal(other); }
    67     /** Returns whether the @a other passed data is different from this one. */
    68     bool operator!=(const UIDataMediumOptions &other) const { return !equal(other); }
    69 
    70     /** Holds the type. */
    71     KMediumType m_enmType;
    72     /** Holds the location. */
    73     QString m_strLocation;
    74     /** Holds the logical size. */
    75     qulonglong m_uLogicalSize;
    76 };
    77 
    78 
    79 /** Virtual Media Manager: Medium details data structure. */
    80 struct UIDataMediumDetails
    81 {
    82     /** Constructs data. */
    83     UIDataMediumDetails()
    84         : m_aLabels(QStringList())
    85         , m_aFields(QStringList())
    86     {}
    87 
    88     /** Returns whether the @a other passed data is equal to this one. */
    89     bool equal(const UIDataMediumDetails &other) const
    90     {
    91         return true
    92                && (m_aLabels == other.m_aLabels)
    93                && (m_aFields == other.m_aFields)
    94                ;
    95     }
    96 
    97     /** Returns whether the @a other passed data is equal to this one. */
    98     bool operator==(const UIDataMediumDetails &other) const { return equal(other); }
    99     /** Returns whether the @a other passed data is different from this one. */
    100     bool operator!=(const UIDataMediumDetails &other) const { return !equal(other); }
    101 
    102     /** Holds the labels list. */
    103     QStringList m_aLabels;
    104     /** Holds the fields list. */
    105     QStringList m_aFields;
    106 };
    107 
    108 
    109 /** Virtual Media Manager: Medium data structure. */
    110 struct UIDataMedium
    111 {
    112     /** Constructs data. */
    113     UIDataMedium()
    114         : m_fValid(false)
    115         , m_enmType(UIMediumType_Invalid)
    116         , m_options(UIDataMediumOptions())
    117         , m_details(UIDataMediumDetails())
    118     {}
    119 
    120     /** Constructs data with passed @enmType. */
    121     UIDataMedium(UIMediumType enmType)
    122         : m_fValid(false)
    123         , m_enmType(enmType)
    124         , m_options(UIDataMediumOptions())
    125         , m_details(UIDataMediumDetails())
    126     {}
    127 
    128     /** Returns whether the @a other passed data is equal to this one. */
    129     bool equal(const UIDataMedium &other) const
    130     {
    131         return true
    132                && (m_fValid == other.m_fValid)
    133                && (m_enmType == other.m_enmType)
    134                && (m_options == other.m_options)
    135                && (m_details == other.m_details)
    136                ;
    137     }
    138 
    139     /** Returns whether the @a other passed data is equal to this one. */
    140     bool operator==(const UIDataMedium &other) const { return equal(other); }
    141     /** Returns whether the @a other passed data is different from this one. */
    142     bool operator!=(const UIDataMedium &other) const { return !equal(other); }
    143 
    144     /** Holds whether data is valid. */
    145     bool m_fValid;
    146     /** Holds the medium type. */
    147     UIMediumType m_enmType;
    148 
    149     /** Holds the medium options. */
    150     UIDataMediumOptions m_options;
    151     /** Holds the details data. */
    152     UIDataMediumDetails m_details;
    153 };
    154 
    155 
    156 /** Virtual Media Manager: Virtual Media Manager details-widget. */
    157 class UIMediumDetailsWidget : public QIWithRetranslateUI<QWidget>
     33/** Medium size editor widget. */
     34class UIMediumSizeEditor : public QIWithRetranslateUI<QWidget>
    15835{
    15936    Q_OBJECT;
     
    16138signals:
    16239
    163     /** Notifies listeners about data changed and whether it @a fDiffers. */
    164     void sigDataChanged(bool fDiffers);
    165 
    166     /** Notifies listeners about data change rejected and should be reseted. */
    167     void sigDataChangeRejected();
    168     /** Notifies listeners about data change accepted and should be applied. */
    169     void sigDataChangeAccepted();
     40    /** Notifies listeners about medium size changed. */
     41    void sigSizeChanged(qulonglong uSize);
    17042
    17143public:
    17244
    173     /** Constructs medium details dialog passing @a pParent to the base-class.
    174       * @param  enmEmbedding  Brings embedding type. */
    175     UIMediumDetailsWidget(EmbedTo enmEmbedding, QWidget *pParent = 0);
     45    /** Constructs medium size editor passing @a pParent to the base-class. */
     46    UIMediumSizeEditor(QWidget *pParent = 0);
    17647
    177     /** Defines the raised details @a enmType. */
    178     void setCurrentType(UIMediumType enmType);
    179 
    180     /** Returns the medium data. */
    181     const UIDataMedium &data() const { return m_newData; }
    182     /** Defines the @a data for passed @a enmType. */
    183     void setData(const UIDataMedium &data);
     48    /** Returns the medium size. */
     49    qulonglong mediumSize() const { return m_uSize; }
     50    /** Defines the @a uSize. */
     51    void setMediumSize(qulonglong uSize);
    18452
    18553protected:
     
    19058private slots:
    19159
    192     /** @name Options stuff.
    193       * @{ */
    194         /** Handles type change. */
    195         void sltTypeIndexChanged(int iIndex);
    196         /** Handles location change. */
    197         void sltLocationPathChanged(const QString &strPath);
    198         /** Handles size slider change. */
    199         void sltSizeSliderChanged(int iValue);
    200         /** Handles size editor change. */
    201         void sltSizeEditorChanged(const QString &strValue);
    202 
    203         /** Handles button-box button click. */
    204         void sltHandleButtonBoxClick(QAbstractButton *pButton);
    205     /** @} */
     60    /** Handles size slider change. */
     61    void sltSizeSliderChanged(int iValue);
     62    /** Handles size editor change. */
     63    void sltSizeEditorChanged(const QString &strValue);
    20664
    20765private:
    20866
    209     /** @name Prepare/cleanup cascade.
    210       * @{ */
    211         /** Prepares all. */
    212         void prepare();
    213         /** Prepares this. */
    214         void prepareThis();
    215         /** Prepares tab-widget. */
    216         void prepareTabWidget();
    217         /** Prepares 'Options' tab. */
    218         void prepareTabOptions();
    219         /** Prepares 'Details' tab. */
    220         void prepareTabDetails();
    221         /** Prepares information-container. */
    222         void prepareInformationContainer(UIMediumType enmType, int cFields);
    223     /** @} */
     67    /** Prepares all. */
     68    void prepare();
    22469
    225     /** @name Loading stuff.
    226       * @{ */
    227         /** Load options data. */
    228         void loadDataForOptions();
    229         /** Load details data. */
    230         void loadDataForDetails();
    231     /** @} */
     70    /** Calculates slider scale according to passed @a uMaximumMediumSize. */
     71    static int calculateSliderScale(qulonglong uMaximumMediumSize);
     72    /** Returns log2 for passed @a uValue. */
     73    static int log2i(qulonglong uValue);
     74    /** Converts passed bytes @a uValue to slides scaled value using @a iSliderScale. */
     75    static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
     76    /** Converts passed slider @a uValue to bytes unscaled value using @a iSliderScale. */
     77    static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
     78    /** Updates slider/editor tool-tips. */
     79    void updateSizeToolTips(qulonglong uSize);
    23280
    233     /** @name Options stuff.
    234       * @{ */
    235         /** Revalidates changes for passed @a pWidget. */
    236         void revalidate(QWidget *pWidget = 0);
    237         /** Retranslates validation for passed @a pWidget. */
    238         void retranslateValidation(QWidget *pWidget = 0);
    239         /** Updates button states. */
    240         void updateButtonStates();
     81    /** Holds the minimum medium size. */
     82    const qulonglong  m_uSizeMin;
     83    /** Holds the maximum medium size. */
     84    const qulonglong  m_uSizeMax;
     85    /** Holds the slider scale. */
     86    const int         m_iSliderScale;
     87    /** Holds the current medium size. */
     88    qulonglong        m_uSize;
    24189
    242         /** Calculates slider scale according to passed @a uMaximumMediumSize. */
    243         static int calculateSliderScale(qulonglong uMaximumMediumSize);
    244         /** Returns log2 for passed @a uValue. */
    245         static int log2i(qulonglong uValue);
    246         /** Converts passed bytes @a uValue to slides scaled value using @a iSliderScale. */
    247         static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
    248         /** Converts passed slider @a uValue to bytes unscaled value using @a iSliderScale. */
    249         static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
    250         /** Updates slider/editor tool-tips. */
    251         void updateSizeToolTips(qulonglong uSize);
    252     /** @} */
    253 
    254     /** @name Details stuff.
    255       * @{ */
    256         /** Returns information-container for passed medium @a enmType. */
    257         QWidget *infoContainer(UIMediumType enmType) const;
    258         /** Returns information-label for passed medium @a enmType and @a iIndex. */
    259         QLabel *infoLabel(UIMediumType enmType, int iIndex) const;
    260         /** Returns information-field for passed medium @a enmType and @a iIndex. */
    261         QILabel *infoField(UIMediumType enmType, int iIndex) const;
    262     /** @} */
    263 
    264     /** @name General variables.
    265       * @{ */
    266         /** Holds the parent widget embedding type. */
    267         const EmbedTo m_enmEmbedding;
    268 
    269         /** Holds the old data copy. */
    270         UIDataMedium  m_oldData;
    271         /** Holds the new data copy. */
    272         UIDataMedium  m_newData;
    273 
    274         /** Holds the tab-widget. */
    275         QITabWidget *m_pTabWidget;
    276     /** @} */
    277 
    278     /** @name Options variables.
    279       * @{ */
    280         /** Holds the type label. */
    281         QLabel    *m_pLabelType;
    282         /** Holds the type combo-box. */
    283         QComboBox *m_pComboBoxType;
    284         /** Holds the type error pane. */
    285         QLabel    *m_pErrorPaneType;
    286 
    287         /** Holds the location label. */
    288         QLabel    *m_pLabelLocation;
    289         /** Holds the location selector. */
    290         UIFilePathSelector *m_pSelectorLocation;
    291         /** Holds the location error pane. */
    292         QLabel    *m_pErrorPaneLocation;
    293 
    294         /** Holds the minimum medium size. */
    295         const qulonglong  m_uMediumSizeMin;
    296         /** Holds the maximum medium size. */
    297         const qulonglong  m_uMediumSizeMax;
    298         /** Holds the slider scale. */
    299         const int         m_iSliderScale;
    300         /** Holds the size label. */
    301         QLabel           *m_pLabelSize;
    302         /** Holds the size slider. */
    303         QSlider          *m_pSliderSize;
    304         /** Holds the minimum size label. */
    305         QLabel           *m_pLabelMinSize;
    306         /** Holds the maximum size label. */
    307         QLabel           *m_pLabelMaxSize;
    308         /** Holds the size editor. */
    309         QILineEdit       *m_pEditorSize;
    310         /** Holds the size error pane. */
    311         QLabel           *m_pErrorPaneSize;
    312 
    313         /** Holds the button-box instance. */
    314         QIDialogButtonBox *m_pButtonBox;
    315     /** @} */
    316 
    317     /** @name Details variables.
    318       * @{ */
    319         /** Holds the details layout: */
    320         QStackedLayout *m_pLayoutDetails;
    321 
    322         /** Holds the map of information-container instances. */
    323         QMap<UIMediumType, QWidget*>          m_aContainers;
    324         /** Holds the map of information-container label instances. */
    325         QMap<UIMediumType, QList<QLabel*> >   m_aLabels;
    326         /** Holds the information-container field instances. */
    327         QMap<UIMediumType, QList<QILabel*> >  m_aFields;
    328     /** @} */
     90    /** Holds the size slider. */
     91    QSlider    *m_pSlider;
     92    /** Holds the minimum size label. */
     93    QLabel     *m_pLabelMinSize;
     94    /** Holds the maximum size label. */
     95    QLabel     *m_pLabelMaxSize;
     96    /** Holds the size editor. */
     97    QILineEdit *m_pEditor;
    32998};
    33099
    331 #endif /* !___UIMediumDetailsWidget_h___ */
     100#endif /* !___UIMediumSizeEditor_h___ */
    332101
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.cpp

    r67507 r67931  
    4040# include "QIToolButton.h"
    4141# include "QILineEdit.h"
     42# include "UIMediumSizeEditor.h"
    4243
    4344/* COM includes: */
     
    5354    , m_uMediumSizeMin(_4M)
    5455    , m_uMediumSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize())
    55     , m_iSliderScale(calculateSliderScale(m_uMediumSizeMax))
    5656{
    5757}
     
    110110}
    111111
    112 void UIWizardNewVDPage3::onSizeSliderValueChanged(int iValue)
    113 {
    114     /* Get full size: */
    115     qulonglong uMediumSize = sliderToSizeMB(iValue, m_iSliderScale);
    116     /* Update tooltips: */
    117     updateSizeToolTips(uMediumSize);
    118     /* Notify size-editor about size had changed (preventing callback): */
    119     m_pSizeEditor->blockSignals(true);
    120     m_pSizeEditor->setText(vboxGlobal().formatSize(uMediumSize));
    121     m_pSizeEditor->blockSignals(false);
    122 }
    123 
    124 void UIWizardNewVDPage3::onSizeEditorTextChanged(const QString &strValue)
    125 {
    126     /* Get full size: */
    127     qulonglong uMediumSize = vboxGlobal().parseSize(strValue);
    128     /* Update tooltips: */
    129     updateSizeToolTips(uMediumSize);
    130     /* Notify size-slider about size had changed (preventing callback): */
    131     m_pSizeSlider->blockSignals(true);
    132     m_pSizeSlider->setValue(sizeMBToSlider(uMediumSize, m_iSliderScale));
    133     m_pSizeSlider->blockSignals(false);
    134 }
    135 
    136112/* static */
    137113QString UIWizardNewVDPage3::toFileName(const QString &strName, const QString &strExtension)
     
    183159}
    184160
    185 /* static */
    186 int UIWizardNewVDPage3::calculateSliderScale(qulonglong uMaximumMediumSize)
    187 {
    188     /* Detect how many steps to recognize between adjacent powers of 2
    189      * to ensure that the last slider step is exactly that we need: */
    190     int iSliderScale = 0;
    191     int iPower = log2i(uMaximumMediumSize);
    192     qulonglong uTickMB = (qulonglong)1 << iPower;
    193     if (uTickMB < uMaximumMediumSize)
    194     {
    195         qulonglong uTickMBNext = (qulonglong)1 << (iPower + 1);
    196         qulonglong uGap = uTickMBNext - uMaximumMediumSize;
    197         iSliderScale = (int)((uTickMBNext - uTickMB) / uGap);
    198 #ifdef VBOX_WS_MAC
    199         // WORKAROUND:
    200         // There is an issue with Qt5 QSlider under OSX:
    201         // Slider tick count (maximum - minimum) is limited with some
    202         // "magical number" - 588351, having it more than that brings
    203         // unpredictable results like slider token jumping and disappearing,
    204         // so we are limiting tick count by lowering slider-scale 128 times.
    205         iSliderScale /= 128;
    206 #endif /* VBOX_WS_MAC */
    207     }
    208     return qMax(iSliderScale, 8);
    209 }
    210 
    211 /* static */
    212 int UIWizardNewVDPage3::log2i(qulonglong uValue)
    213 {
    214     int iPower = -1;
    215     while (uValue)
    216     {
    217         ++iPower;
    218         uValue >>= 1;
    219     }
    220     return iPower;
    221 }
    222 
    223 /* static */
    224 int UIWizardNewVDPage3::sizeMBToSlider(qulonglong uValue, int iSliderScale)
    225 {
    226     /* Make sure *any* slider value is multiple of 512: */
    227     uValue /= 512;
    228 
    229     /* Calculate result: */
    230     int iPower = log2i(uValue);
    231     qulonglong uTickMB = qulonglong (1) << iPower;
    232     qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    233     int iStep = (uValue - uTickMB) * iSliderScale / (uTickMBNext - uTickMB);
    234     int iResult = iPower * iSliderScale + iStep;
    235 
    236     /* Return result: */
    237     return iResult;
    238 }
    239 
    240 /* static */
    241 qulonglong UIWizardNewVDPage3::sliderToSizeMB(int uValue, int iSliderScale)
    242 {
    243     /* Calculate result: */
    244     int iPower = uValue / iSliderScale;
    245     int iStep = uValue % iSliderScale;
    246     qulonglong uTickMB = qulonglong (1) << iPower;
    247     qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    248     qulonglong uResult = uTickMB + (uTickMBNext - uTickMB) * iStep / iSliderScale;
    249 
    250     /* Make sure *any* slider value is multiple of 512: */
    251     uResult *= 512;
    252 
    253     /* Return result: */
    254     return uResult;
    255 }
    256 
    257 void UIWizardNewVDPage3::updateSizeToolTips(qulonglong uSize)
    258 {
    259     QString strToolTip = UIWizardNewVD::tr("<nobr>%1 (%2 B)</nobr>").arg(vboxGlobal().formatSize(uSize)).arg(uSize);
    260     m_pSizeSlider->setToolTip(strToolTip);
    261     m_pSizeEditor->setToolTip(strToolTip);
    262 }
    263 
    264161QString UIWizardNewVDPage3::mediumPath() const
    265162{
     
    269166qulonglong UIWizardNewVDPage3::mediumSize() const
    270167{
    271     return sliderToSizeMB(m_pSizeSlider->value(), m_iSliderScale);
     168    return m_pEditorSize->mediumSize();
    272169}
    273170
    274171void UIWizardNewVDPage3::setMediumSize(qulonglong uMediumSize)
    275172{
    276     /* Block signals: */
    277     m_pSizeSlider->blockSignals(true);
    278     m_pSizeEditor->blockSignals(true);
    279     /* Set values: */
    280     m_pSizeSlider->setValue(sizeMBToSlider(uMediumSize, m_iSliderScale));
    281     m_pSizeEditor->setText(vboxGlobal().formatSize(uMediumSize));
    282     updateSizeToolTips(uMediumSize);
    283     /* Unblock signals: */
    284     m_pSizeSlider->blockSignals(false);
    285     m_pSizeEditor->blockSignals(false);
     173    m_pEditorSize->setMediumSize(uMediumSize);
    286174}
    287175
     
    305193        }
    306194        m_pSizeLabel = new QIRichTextLabel(this);
    307         QGridLayout *m_pSizeLayout = new QGridLayout;
    308         {
    309             m_pSizeSlider = new QSlider(this);
    310             {
    311                 m_pSizeSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    312                 m_pSizeSlider->setOrientation(Qt::Horizontal);
    313                 m_pSizeSlider->setTickPosition(QSlider::TicksBelow);
    314                 m_pSizeSlider->setFocusPolicy(Qt::StrongFocus);
    315                 m_pSizeSlider->setPageStep(m_iSliderScale);
    316                 m_pSizeSlider->setSingleStep(m_iSliderScale / 8);
    317                 m_pSizeSlider->setTickInterval(0);
    318                 m_pSizeSlider->setMinimum(sizeMBToSlider(m_uMediumSizeMin, m_iSliderScale));
    319                 m_pSizeSlider->setMaximum(sizeMBToSlider(m_uMediumSizeMax, m_iSliderScale));
    320             }
    321             m_pSizeEditor = new QILineEdit(this);
    322             {
    323                 m_pSizeEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    324                 m_pSizeEditor->setFixedWidthByText("88888.88 MB");
    325                 m_pSizeEditor->setAlignment(Qt::AlignRight);
    326                 m_pSizeEditor->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
    327             }
    328             QLabel *m_pSizeMin = new QLabel(this);
    329             {
    330                 m_pSizeMin->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    331                 m_pSizeMin->setText(vboxGlobal().formatSize(m_uMediumSizeMin));
    332             }
    333             QLabel *m_pSizeMax = new QLabel(this);
    334             {
    335                 m_pSizeMax->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    336                 m_pSizeMax->setText(vboxGlobal().formatSize(m_uMediumSizeMax));
    337             }
    338             m_pSizeLayout->addWidget(m_pSizeSlider, 0, 0, 1, 3);
    339             m_pSizeLayout->addWidget(m_pSizeEditor, 0, 3);
    340             m_pSizeLayout->addWidget(m_pSizeMin, 1, 0);
    341             m_pSizeLayout->setColumnStretch(1, 1);
    342             m_pSizeLayout->addWidget(m_pSizeMax, 1, 2);
    343         }
     195        m_pEditorSize = new UIMediumSizeEditor;
    344196        setMediumSize(uDefaultSize);
    345197        pMainLayout->addWidget(m_pLocationLabel);
    346198        pMainLayout->addLayout(pLocationLayout);
    347199        pMainLayout->addWidget(m_pSizeLabel);
    348         pMainLayout->addLayout(m_pSizeLayout);
     200        pMainLayout->addWidget(m_pEditorSize);
    349201        pMainLayout->addStretch();
    350202    }
     
    353205    connect(m_pLocationEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    354206    connect(m_pLocationOpenButton, SIGNAL(clicked()), this, SLOT(sltSelectLocationButtonClicked()));
    355     connect(m_pSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(sltSizeSliderValueChanged(int)));
    356     connect(m_pSizeEditor, SIGNAL(textChanged(const QString &)), this, SLOT(sltSizeEditorTextChanged(const QString &)));
     207    connect(m_pEditorSize, &UIMediumSizeEditor::sigSizeChanged, this, &UIWizardNewVDPageBasic3::completeChanged);
    357208
    358209    /* Register fields: */
     
    365216    /* Call to base-class: */
    366217    onSelectLocationButtonClicked();
    367 }
    368 
    369 void UIWizardNewVDPageBasic3::sltSizeSliderValueChanged(int iValue)
    370 {
    371     /* Call to base-class: */
    372     onSizeSliderValueChanged(iValue);
    373 
    374     /* Broadcast complete-change: */
    375     emit completeChanged();
    376 }
    377 
    378 void UIWizardNewVDPageBasic3::sltSizeEditorTextChanged(const QString &strValue)
    379 {
    380     /* Call to base-class: */
    381     onSizeEditorTextChanged(strValue);
    382 
    383     /* Broadcast complete-change: */
    384     emit completeChanged();
    385218}
    386219
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.h

    r62493 r67931  
    2626class QLineEdit;
    2727class QIToolButton;
    28 class QSlider;
    29 class QILineEdit;
    3028class QIRichTextLabel;
     29class UIMediumSizeEditor;
    3130
    3231/* 3rd page of the New Virtual Hard Drive wizard (base part): */
     
    4039    /* Handlers: */
    4140    void onSelectLocationButtonClicked();
    42     void onSizeSliderValueChanged(int iValue);
    43     void onSizeEditorTextChanged(const QString &strValue);
    4441
    4542    /* Location-editors stuff: */
     
    4744    static QString absoluteFilePath(const QString &strFileName, const QString &strDefaultPath);
    4845    static QString defaultExtension(const CMediumFormat &mediumFormatRef);
    49 
    50     /* Size-editors stuff: */
    51     static int calculateSliderScale(qulonglong uMaximumMediumSize);
    52     static int log2i(qulonglong uValue);
    53     static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
    54     static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
    55     void updateSizeToolTips(qulonglong uSize);
    5646
    5747    /* Stuff for 'mediumPath' field: */
     
    6858    qulonglong m_uMediumSizeMin;
    6959    qulonglong m_uMediumSizeMax;
    70     int m_iSliderScale;
    7160
    7261    /* Widgets: */
    7362    QLineEdit *m_pLocationEditor;
    7463    QIToolButton *m_pLocationOpenButton;
    75     QSlider *m_pSizeSlider;
    76     QILineEdit *m_pSizeEditor;
     64    UIMediumSizeEditor *m_pEditorSize;
    7765};
    7866
     
    10189    void sltSelectLocationButtonClicked();
    10290
    103     /* Size editors stuff: */
    104     void sltSizeSliderValueChanged(int iValue);
    105     void sltSizeEditorTextChanged(const QString &strValue);
    106 
    10791private:
    10892
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.cpp

    r62493 r67931  
    4141# include "QIToolButton.h"
    4242# include "QILineEdit.h"
     43# include "UIMediumSizeEditor.h"
    4344
    4445/* COM includes: */
     
    7778        {
    7879            m_pSizeCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    79             QGridLayout *pSizeCntLayout = new QGridLayout(m_pSizeCnt);
    80             {
    81                 m_pSizeSlider = new QSlider(m_pSizeCnt);
    82                 {
    83                     m_pSizeSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    84                     m_pSizeSlider->setOrientation(Qt::Horizontal);
    85                     m_pSizeSlider->setTickPosition(QSlider::TicksBelow);
    86                     m_pSizeSlider->setFocusPolicy(Qt::StrongFocus);
    87                     m_pSizeSlider->setPageStep(m_iSliderScale);
    88                     m_pSizeSlider->setSingleStep(m_iSliderScale / 8);
    89                     m_pSizeSlider->setTickInterval(0);
    90                     m_pSizeSlider->setMinimum(sizeMBToSlider(m_uMediumSizeMin, m_iSliderScale));
    91                     m_pSizeSlider->setMaximum(sizeMBToSlider(m_uMediumSizeMax, m_iSliderScale));
    92                 }
    93                 m_pSizeEditor = new QILineEdit(m_pSizeCnt);
    94                 {
    95                     m_pSizeEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    96                     m_pSizeEditor->setFixedWidthByText("88888.88 MB");
    97                     m_pSizeEditor->setAlignment(Qt::AlignRight);
    98                     m_pSizeEditor->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
    99                 }
    100                 QLabel *m_pSizeMin = new QLabel(m_pSizeCnt);
    101                 {
    102                     m_pSizeMin->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    103                     m_pSizeMin->setText(vboxGlobal().formatSize(m_uMediumSizeMin));
    104                 }
    105                 QLabel *m_pSizeMax = new QLabel(m_pSizeCnt);
    106                 {
    107                     m_pSizeMax->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    108                     m_pSizeMax->setText(vboxGlobal().formatSize(m_uMediumSizeMax));
    109                 }
    110                 pSizeCntLayout->addWidget(m_pSizeSlider, 0, 0, 1, 3);
    111                 pSizeCntLayout->addWidget(m_pSizeEditor, 0, 3);
    112                 pSizeCntLayout->addWidget(m_pSizeMin, 1, 0);
    113                 pSizeCntLayout->setColumnStretch(1, 1);
    114                 pSizeCntLayout->addWidget(m_pSizeMax, 1, 2);
     80            QVBoxLayout *pSizeCntLayout = new QVBoxLayout(m_pSizeCnt);
     81            {
     82                m_pEditorSize = new UIMediumSizeEditor;
     83                {
     84                    pSizeCntLayout->addWidget(m_pEditorSize);
     85                }
    11586            }
    11687        }
     
    195166    connect(m_pLocationEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    196167    connect(m_pLocationOpenButton, SIGNAL(clicked()), this, SLOT(sltSelectLocationButtonClicked()));
    197     connect(m_pSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(sltSizeSliderValueChanged(int)));
    198     connect(m_pSizeEditor, SIGNAL(textChanged(const QString &)), this, SLOT(sltSizeEditorTextChanged(const QString &)));
     168    connect(m_pEditorSize, &UIMediumSizeEditor::sigSizeChanged, this, &UIWizardNewVDPageExpert::completeChanged);
    199169
    200170    /* Register classes: */
     
    242212    /* Call to base-class: */
    243213    onSelectLocationButtonClicked();
    244 }
    245 
    246 void UIWizardNewVDPageExpert::sltSizeSliderValueChanged(int iValue)
    247 {
    248     onSizeSliderValueChanged(iValue);
    249 
    250     emit completeChanged();
    251 }
    252 
    253 void UIWizardNewVDPageExpert::sltSizeEditorTextChanged(const QString &strValue)
    254 {
    255     onSizeEditorTextChanged(strValue);
    256 
    257     emit completeChanged();
    258214}
    259215
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.h

    r62493 r67931  
    5858    /* Location editors stuff: */
    5959    void sltSelectLocationButtonClicked();
    60     /* Size editors stuff: */
    61     void sltSizeSliderValueChanged(int iValue);
    62     void sltSizeEditorTextChanged(const QString &strValue);
    6360
    6461private:
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette