Changeset 67931 in vbox
- Timestamp:
- Jul 12, 2017 1:11:31 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 116923
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r67750 r67931 435 435 src/widgets/UIHotKeyEditor.h \ 436 436 src/widgets/UILineTextEdit.h \ 437 src/widgets/UIMediumSizeEditor.h \ 437 438 src/widgets/UIMenuBar.h \ 438 439 src/widgets/UIPopupBox.h \ … … 748 749 src/widgets/UIHotKeyEditor.cpp \ 749 750 src/widgets/UILineTextEdit.cpp \ 751 src/widgets/UIMediumSizeEditor.cpp \ 750 752 src/widgets/UIMenuBar.cpp \ 751 753 src/widgets/UIPopupBox.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDetailsWidget.cpp
r67923 r67931 37 37 # include "UIIconPool.h" 38 38 # include "UIMediumDetailsWidget.h" 39 # include "UIMediumSizeEditor.h" 39 40 # include "VBoxGlobal.h" 40 41 … … 53 54 , m_pLabelType(0), m_pComboBoxType(0), m_pErrorPaneType(0) 54 55 , 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) 59 57 , m_pButtonBox(0) 60 58 , m_pLayoutDetails(0) … … 95 93 m_pLabelLocation->setText(tr("&Location:")); 96 94 m_pLabelSize->setText(tr("&Size:")); 97 m_pLabelMinSize->setText(vboxGlobal().formatSize(m_uMediumSizeMin));98 m_pLabelMaxSize->setText(vboxGlobal().formatSize(m_uMediumSizeMax));99 95 100 96 /* Translate fields: */ … … 103 99 m_pComboBoxType->setItemText(i, gpConverter->toString(m_pComboBoxType->itemData(i).value<KMediumType>())); 104 100 m_pSelectorLocation->setToolTip(tr("Holds the location of this medium.")); 105 m_pSliderSize->setToolTip(tr("Holds the size of this medium."));106 101 m_pEditorSize->setToolTip(tr("Holds the size of this medium.")); 107 102 … … 141 136 } 142 137 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); 138 void UIMediumDetailsWidget::sltSizeEditorChanged(qulonglong uSize) 139 { 140 m_newData.m_options.m_uLogicalSize = uSize; 149 141 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 142 updateButtonStates(); 163 143 } … … 357 337 /* Configure layout: */ 358 338 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 339 407 340 /* Create size editor: */ 408 m_pEditorSize = new QILineEdit;341 m_pEditorSize = new UIMediumSizeEditor; 409 342 AssertPtrReturnVoid(m_pEditorSize); 410 343 { 411 344 /* Configure editor: */ 412 345 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, 418 348 this, &UIMediumDetailsWidget::sltSizeEditorChanged); 419 349 420 350 /* Add into layout: */ 421 pLayoutSize->addWidget(m_pEditorSize, 0, 2);351 pLayoutSize->addWidget(m_pEditorSize, 0, 0, 2, 1); 422 352 } 423 353 … … 432 362 433 363 /* Add into layout: */ 434 pLayoutSize->addWidget(m_pErrorPaneSize, 0, 3);364 pLayoutSize->addWidget(m_pErrorPaneSize, 0, 1); 435 365 } 436 366 … … 592 522 /* Load size: */ 593 523 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 524 m_pEditorSize->setEnabled(m_newData.m_fValid && m_newData.m_enmType == UIMediumType_HardDisk); 598 m_pEditorSize->set Text(vboxGlobal().formatSize(m_newData.m_options.m_uLogicalSize));525 m_pEditorSize->setMediumSize(m_newData.m_options.m_uLogicalSize); 599 526 } 600 527 … … 673 600 } 674 601 675 /* static */676 int UIMediumDetailsWidget::calculateSliderScale(qulonglong uMaximumMediumSize)677 {678 /* Detect how many steps to recognize between adjacent powers of 2679 * 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_MAC689 // WORKAROUND:690 // There is an issue with Qt5 QSlider under OSX:691 // Slider tick count (maximum - minimum) is limited with some692 // "magical number" - 588351, having it more than that brings693 // 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 754 602 QWidget *UIMediumDetailsWidget::infoContainer(UIMediumType enmType) const 755 603 { -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDetailsWidget.h
r67923 r67931 34 34 class QComboBox; 35 35 class QLabel; 36 class QSlider;37 36 class QStackedLayout; 38 37 class QWidget; 39 38 class QILabel; 40 class QILineEdit;41 39 class QITabWidget; 42 40 class UIFilePathSelector; 41 class UIMediumSizeEditor; 43 42 44 43 … … 196 195 /** Handles location change. */ 197 196 void sltLocationPathChanged(const QString &strPath); 198 /** Handles size slider change. */199 void sltSizeSliderChanged(int iValue);200 197 /** Handles size editor change. */ 201 void sltSizeEditorChanged( const QString &strValue);198 void sltSizeEditorChanged(qulonglong uSize); 202 199 203 200 /** Handles button-box button click. */ … … 239 236 /** Updates button states. */ 240 237 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);252 238 /** @} */ 253 239 … … 292 278 QLabel *m_pErrorPaneLocation; 293 279 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 280 /** 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; 308 282 /** Holds the size editor. */ 309 QILineEdit*m_pEditorSize;283 UIMediumSizeEditor *m_pEditorSize; 310 284 /** Holds the size error pane. */ 311 QLabel *m_pErrorPaneSize;285 QLabel *m_pErrorPaneSize; 312 286 313 287 /** Holds the button-box instance. */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp
r67923 r67931 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIMedium DetailsWidgetclass implementation.3 * VBox Qt GUI - UIMediumSizeEditor class implementation. 4 4 */ 5 5 … … 21 21 22 22 /* Qt includes: */ 23 # include <Q ComboBox>23 # include <QGridLayout> 24 24 # include <QLabel> 25 # include <Q PushButton>25 # include <QRegExpValidator> 26 26 # include <QSlider> 27 # include <QStackedLayout>28 # include <QVBoxLayout>29 27 30 28 /* GUI includes: */ 31 # include "QIDialogButtonBox.h"32 # include "QILabel.h"33 29 # 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" 39 31 # include "VBoxGlobal.h" 40 32 … … 45 37 46 38 47 UIMedium DetailsWidget::UIMediumDetailsWidget(EmbedTo enmEmbedding,QWidget *pParent /* = 0 */)39 UIMediumSizeEditor::UIMediumSizeEditor(QWidget *pParent /* = 0 */) 48 40 : 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) 61 48 { 62 49 /* Prepare: */ … … 64 51 } 65 52 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 53 void 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 61 void UIMediumSizeEditor::retranslateUi() 62 { 93 63 /* 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)); 99 66 100 67 /* 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 75 void 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 89 void 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 103 void UIMediumSizeEditor::prepare() 195 104 { 196 105 /* Create layout: */ 197 Q VBoxLayout *pLayout = new QVBoxLayout(this);106 QGridLayout *pLayout = new QGridLayout(this); 198 107 AssertPtrReturnVoid(pLayout); 199 108 { 200 109 /* Configure layout: */ 201 110 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 } 205 173 } 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 */ 180 int UIMediumSizeEditor::calculateSliderScale(qulonglong uMaximumMediumSize) 677 181 { 678 182 /* Detect how many steps to recognize between adjacent powers of 2 … … 700 204 701 205 /* static */ 702 int UIMedium DetailsWidget::log2i(qulonglong uValue)206 int UIMediumSizeEditor::log2i(qulonglong uValue) 703 207 { 704 208 int iPower = -1; … … 712 216 713 217 /* static */ 714 int UIMedium DetailsWidget::sizeMBToSlider(qulonglong uValue, int iSliderScale)218 int UIMediumSizeEditor::sizeMBToSlider(qulonglong uValue, int iSliderScale) 715 219 { 716 220 /* Make sure *any* slider value is multiple of 512: */ … … 729 233 730 234 /* static */ 731 qulonglong UIMedium DetailsWidget::sliderToSizeMB(int uValue, int iSliderScale)235 qulonglong UIMediumSizeEditor::sliderToSizeMB(int uValue, int iSliderScale) 732 236 { 733 237 /* Calculate result: */ … … 745 249 } 746 250 747 void UIMedium DetailsWidget::updateSizeToolTips(qulonglong uSize)251 void UIMediumSizeEditor::updateSizeToolTips(qulonglong uSize) 748 252 { 749 253 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 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIMedium DetailsWidgetclass declaration.3 * VBox Qt GUI - UIMediumSizeEditor class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ___UIMedium DetailsWidget_h___19 #define ___UIMedium DetailsWidget_h___18 #ifndef ___UIMediumSizeEditor_h___ 19 #define ___UIMediumSizeEditor_h___ 20 20 21 21 /* Qt includes: */ … … 23 23 24 24 /* GUI includes: */ 25 #include "QIManagerDialog.h"26 25 #include "QIWithRetranslateUI.h" 27 #include "UIMediumDefs.h"28 29 /* COM includes: */30 #include "COMEnums.h"31 26 32 27 /* Forward declarations: */ 33 class QAbstractButton;34 class QComboBox;35 28 class QLabel; 36 29 class QSlider; 37 class QStackedLayout;38 class QWidget;39 class QILabel;40 30 class QILineEdit; 41 class QITabWidget;42 class UIFilePathSelector;43 31 44 32 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. */ 34 class UIMediumSizeEditor : public QIWithRetranslateUI<QWidget> 158 35 { 159 36 Q_OBJECT; … … 161 38 signals: 162 39 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); 170 42 171 43 public: 172 44 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); 176 47 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); 184 52 185 53 protected: … … 190 58 private slots: 191 59 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); 206 64 207 65 private: 208 66 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(); 224 69 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); 232 80 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; 241 89 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; 329 98 }; 330 99 331 #endif /* !___UIMedium DetailsWidget_h___ */100 #endif /* !___UIMediumSizeEditor_h___ */ 332 101 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.cpp
r67507 r67931 40 40 # include "QIToolButton.h" 41 41 # include "QILineEdit.h" 42 # include "UIMediumSizeEditor.h" 42 43 43 44 /* COM includes: */ … … 53 54 , m_uMediumSizeMin(_4M) 54 55 , m_uMediumSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize()) 55 , m_iSliderScale(calculateSliderScale(m_uMediumSizeMax))56 56 { 57 57 } … … 110 110 } 111 111 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 136 112 /* static */ 137 113 QString UIWizardNewVDPage3::toFileName(const QString &strName, const QString &strExtension) … … 183 159 } 184 160 185 /* static */186 int UIWizardNewVDPage3::calculateSliderScale(qulonglong uMaximumMediumSize)187 {188 /* Detect how many steps to recognize between adjacent powers of 2189 * 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_MAC199 // WORKAROUND:200 // There is an issue with Qt5 QSlider under OSX:201 // Slider tick count (maximum - minimum) is limited with some202 // "magical number" - 588351, having it more than that brings203 // 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 264 161 QString UIWizardNewVDPage3::mediumPath() const 265 162 { … … 269 166 qulonglong UIWizardNewVDPage3::mediumSize() const 270 167 { 271 return sliderToSizeMB(m_pSizeSlider->value(), m_iSliderScale);168 return m_pEditorSize->mediumSize(); 272 169 } 273 170 274 171 void UIWizardNewVDPage3::setMediumSize(qulonglong uMediumSize) 275 172 { 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); 286 174 } 287 175 … … 305 193 } 306 194 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; 344 196 setMediumSize(uDefaultSize); 345 197 pMainLayout->addWidget(m_pLocationLabel); 346 198 pMainLayout->addLayout(pLocationLayout); 347 199 pMainLayout->addWidget(m_pSizeLabel); 348 pMainLayout->add Layout(m_pSizeLayout);200 pMainLayout->addWidget(m_pEditorSize); 349 201 pMainLayout->addStretch(); 350 202 } … … 353 205 connect(m_pLocationEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged())); 354 206 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); 357 208 358 209 /* Register fields: */ … … 365 216 /* Call to base-class: */ 366 217 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();385 218 } 386 219 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.h
r62493 r67931 26 26 class QLineEdit; 27 27 class QIToolButton; 28 class QSlider;29 class QILineEdit;30 28 class QIRichTextLabel; 29 class UIMediumSizeEditor; 31 30 32 31 /* 3rd page of the New Virtual Hard Drive wizard (base part): */ … … 40 39 /* Handlers: */ 41 40 void onSelectLocationButtonClicked(); 42 void onSizeSliderValueChanged(int iValue);43 void onSizeEditorTextChanged(const QString &strValue);44 41 45 42 /* Location-editors stuff: */ … … 47 44 static QString absoluteFilePath(const QString &strFileName, const QString &strDefaultPath); 48 45 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);56 46 57 47 /* Stuff for 'mediumPath' field: */ … … 68 58 qulonglong m_uMediumSizeMin; 69 59 qulonglong m_uMediumSizeMax; 70 int m_iSliderScale;71 60 72 61 /* Widgets: */ 73 62 QLineEdit *m_pLocationEditor; 74 63 QIToolButton *m_pLocationOpenButton; 75 QSlider *m_pSizeSlider; 76 QILineEdit *m_pSizeEditor; 64 UIMediumSizeEditor *m_pEditorSize; 77 65 }; 78 66 … … 101 89 void sltSelectLocationButtonClicked(); 102 90 103 /* Size editors stuff: */104 void sltSizeSliderValueChanged(int iValue);105 void sltSizeEditorTextChanged(const QString &strValue);106 107 91 private: 108 92 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.cpp
r62493 r67931 41 41 # include "QIToolButton.h" 42 42 # include "QILineEdit.h" 43 # include "UIMediumSizeEditor.h" 43 44 44 45 /* COM includes: */ … … 77 78 { 78 79 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 } 115 86 } 116 87 } … … 195 166 connect(m_pLocationEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged())); 196 167 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); 199 169 200 170 /* Register classes: */ … … 242 212 /* Call to base-class: */ 243 213 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();258 214 } 259 215 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.h
r62493 r67931 58 58 /* Location editors stuff: */ 59 59 void sltSelectLocationButtonClicked(); 60 /* Size editors stuff: */61 void sltSizeSliderValueChanged(int iValue);62 void sltSizeEditorTextChanged(const QString &strValue);63 60 64 61 private:
Note:
See TracChangeset
for help on using the changeset viewer.