Changeset 79996 in vbox
- Timestamp:
- Jul 26, 2019 11:12:25 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBaseMemoryEditor.cpp
r79959 r79996 27 27 #include "UIBaseMemorySlider.h" 28 28 29 /* Other VBox includes: */30 #include "iprt/assert.h"31 29 32 33 UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent) 30 UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */) 34 31 : QIWithRetranslateUI<QWidget>(pParent) 32 , m_fWithLabel(fWithLabel) 35 33 , m_pLabelMemory(0) 36 34 , m_pSlider(0) … … 44 42 void UIBaseMemoryEditor::setValue(int iValue) 45 43 { 46 AssertPtrReturnVoid(m_pSlider);47 m_pSlider->setValue(iValue);44 if (m_pSlider) 45 m_pSlider->setValue(iValue); 48 46 } 49 47 50 48 int UIBaseMemoryEditor::value() const 51 49 { 52 AssertPtrReturn(m_pSlider, 0); 53 return m_pSlider->value(); 50 return m_pSlider ? m_pSlider->value() : 0; 51 } 52 53 uint UIBaseMemoryEditor::maxRAMOpt() const 54 { 55 return m_pSlider ? m_pSlider->maxRAMOpt() : 0; 56 } 57 58 uint UIBaseMemoryEditor::maxRAMAlw() const 59 { 60 return m_pSlider ? m_pSlider->maxRAMAlw() : 0; 54 61 } 55 62 56 63 void UIBaseMemoryEditor::retranslateUi() 57 64 { 58 AssertPtrReturnVoid(m_pSlider); 59 AssertPtrReturnVoid(m_pSpinBox); 60 61 m_pLabelMemory->setText(tr("Base &Memory:")); 62 m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_pSlider->minRAM())); 63 m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_pSlider->maxRAM())); 64 m_pSpinBox->setSuffix(QString(" %1").arg(tr("MB"))); 65 if (m_pLabelMemory) 66 m_pLabelMemory->setText(tr("Base &Memory:")); 67 if (m_pLabelMemoryMin) 68 m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_pSlider->minRAM())); 69 if (m_pLabelMemoryMax) 70 m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_pSlider->maxRAM())); 71 if (m_pSpinBox) 72 m_pSpinBox->setSuffix(QString(" %1").arg(tr("MB"))); 65 73 } 66 74 67 75 void UIBaseMemoryEditor::sltHandleSliderChange() 68 76 { 69 AssertPtrReturnVoid(m_pSlider);70 AssertPtrReturnVoid(m_pSpinBox);71 72 77 /* Apply spin-box value keeping it's signals disabled: */ 73 m_pSpinBox->blockSignals(true); 74 m_pSpinBox->setValue(m_pSlider->value()); 75 m_pSpinBox->blockSignals(false); 78 if (m_pSpinBox && m_pSlider) 79 { 80 m_pSpinBox->blockSignals(true); 81 m_pSpinBox->setValue(m_pSlider->value()); 82 m_pSpinBox->blockSignals(false); 83 } 76 84 77 85 /* Revalidate to send signal to listener: */ … … 81 89 void UIBaseMemoryEditor::sltHandleSpinBoxChange() 82 90 { 83 AssertPtrReturnVoid(m_pSlider);84 AssertPtrReturnVoid(m_pSpinBox);85 86 91 /* Apply slider value keeping it's signals disabled: */ 87 m_pSlider->blockSignals(true); 88 m_pSlider->setValue(m_pSpinBox->value()); 89 m_pSlider->blockSignals(false); 92 if (m_pSpinBox && m_pSlider) 93 { 94 m_pSlider->blockSignals(true); 95 m_pSlider->setValue(m_pSpinBox->value()); 96 m_pSlider->blockSignals(false); 97 } 90 98 91 99 /* Revalidate to send signal to listener: */ … … 100 108 { 101 109 pMainLayout->setContentsMargins(0, 0, 0, 0); 110 int iRow = 0; 102 111 103 112 /* Create memory label: */ 104 m_pLabelMemory = new QLabel(this); 113 if (m_fWithLabel) 114 m_pLabelMemory = new QLabel(this); 105 115 if (m_pLabelMemory) 106 pMainLayout->addWidget(m_pLabelMemory, 0, 0, 1, 1);116 pMainLayout->addWidget(m_pLabelMemory, 0, iRow++, 1, 1); 107 117 108 118 /* Create slider layout: */ … … 146 156 147 157 /* Add slider layout to main layout: */ 148 pMainLayout->addLayout(pSliderLayout, 0, 1, 2, 1);158 pMainLayout->addLayout(pSliderLayout, 0, iRow++, 2, 1); 149 159 } 150 160 … … 153 163 if (m_pSpinBox) 154 164 { 155 m_pLabelMemory->setBuddy(m_pSpinBox); 165 setFocusProxy(m_pSpinBox); 166 if (m_pLabelMemory) 167 m_pLabelMemory->setBuddy(m_pSpinBox); 156 168 m_pSpinBox->setMinimum(m_pSlider->minRAM()); 157 169 m_pSpinBox->setMaximum(m_pSlider->maxRAM()); 158 170 connect(m_pSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), 159 171 this, &UIBaseMemoryEditor::sltHandleSpinBoxChange); 160 pMainLayout->addWidget(m_pSpinBox, 0, 2, 1, 1);172 pMainLayout->addWidget(m_pSpinBox, 0, iRow++, 1, 1); 161 173 } 162 174 } … … 168 180 void UIBaseMemoryEditor::revalidate() 169 181 { 170 emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw()); 182 if (m_pSlider) 183 emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw()); 171 184 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBaseMemoryEditor.h
r79959 r79996 46 46 public: 47 47 48 /** Constructs base-memory editor passing @a pParent to the base-class. */ 49 UIBaseMemoryEditor(QWidget *pParent = 0); 48 /** Constructs base-memory editor passing @a pParent to the base-class. 49 * @param fWithLabel Brings whether we should add label ourselves. */ 50 UIBaseMemoryEditor(QWidget *pParent = 0, bool fWithLabel = false); 50 51 51 52 /** Defines editor @a iValue. */ … … 53 54 /** Returns editor value. */ 54 55 int value() const; 56 57 /** Returns the maximum optimal RAM. */ 58 uint maxRAMOpt() const; 59 /** Returns the maximum allowed RAM. */ 60 uint maxRAMAlw() const; 55 61 56 62 protected: … … 74 80 void revalidate(); 75 81 82 /** Holds whether descriptive label should be created. */ 83 bool m_fWithLabel; 84 76 85 /** Holds the memory label instance. */ 77 86 QLabel *m_pLabelMemory;
Note:
See TracChangeset
for help on using the changeset viewer.