Changeset 80859 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Sep 17, 2019 1:08:09 PM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp
r79365 r80859 48 48 /* Prepare: */ 49 49 prepare(); 50 QString strRegEx = QString("[^(\\d|%1)]").arg(uiCommon().decimalSep()); 51 m_regExNonDigitOrSeparator = QRegularExpression(strRegEx); 50 52 } 51 53 … … 97 99 } 98 100 99 void UIMediumSizeEditor::sltSizeEditor EditingFinished()101 void UIMediumSizeEditor::sltSizeEditorTextChanged() 100 102 { 101 103 QString strSizeString = ensureSizeSuffix(m_pEditor->text()); 102 104 103 if (strSizeString != m_pEditor->text()) 104 {105 m_pEditor->blockSignals(true);106 m_pEditor->setText(strSizeString);107 m_pEditor->blockSignals(false);108 }105 106 m_pEditor->blockSignals(true); 107 m_pEditor->setText(strSizeString); 108 /* Reposition the cursor to the front of the size suffix (and 1 char for the space) */ 109 m_pEditor->setCursorPosition(strSizeString.length() - (gpConverter->toString(m_enmSizeSuffix).length() + 1)); 110 m_pEditor->blockSignals(false); 109 111 110 112 /* Update the current size: */ … … 123 125 QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString) 124 126 { 127 /* Try to update the m_enmSizeSuffix: */ 125 128 if (uiCommon().hasSizeSuffix(strSizeString)) 126 {127 /* Update the m_enmSizeSuffix: */128 129 m_enmSizeSuffix = uiCommon().parseSizeSuffix(strSizeString); 129 return strSizeString; 130 }131 132 return QString("%1 %2").arg(str SizeString).arg(gpConverter->toString(m_enmSizeSuffix));130 131 QString strOnlyDigits(strSizeString); 132 /* Remove any chars from the string except digits and decimal separator and then add a space and size suffix: */ 133 return QString("%1 %2").arg(strOnlyDigits.remove(m_regExNonDigitOrSeparator)).arg(gpConverter->toString(m_enmSizeSuffix)); 133 134 } 134 135 … … 193 194 { 194 195 /* Configure editor: */ 196 m_pEditor->installEventFilter(this); 195 197 m_pEditor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); 196 198 m_pEditor->setFixedWidthByText("88888.88 MB"); 197 199 m_pEditor->setAlignment(Qt::AlignRight); 198 200 m_pEditor->setValidator(new QRegExpValidator(QRegExp(uiCommon().sizeRegexp()), this)); 199 connect(m_pEditor, &QILineEdit:: editingFinished,200 this, &UIMediumSizeEditor::sltSizeEditor EditingFinished);201 connect(m_pEditor, &QILineEdit::textChanged, 202 this, &UIMediumSizeEditor::sltSizeEditorTextChanged); 201 203 202 204 /* Add into layout: */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h
r77556 r80859 23 23 24 24 /* Qt includes: */ 25 #include <QRegularExpression> 25 26 #include <QWidget> 26 27 … … 54 55 /** Returns the medium size. */ 55 56 qulonglong mediumSize() const { return m_uSize; } 56 /** Defines the @a uSize. */57 /** Sets the initial medium size as the widget is created. */ 57 58 void setMediumSize(qulonglong uSize); 58 59 … … 67 68 void sltSizeSliderChanged(int iValue); 68 69 /** Handles size editor text edit finished signal. */ 69 void sltSizeEditor EditingFinished();70 void sltSizeEditorTextChanged(); 70 71 71 72 private: … … 108 109 /** Holds the size editor. */ 109 110 QILineEdit *m_pEditor; 111 112 /* A regular expression used to remove any character from a QString which is neither a digit nor decimal separator. */ 113 QRegularExpression m_regExNonDigitOrSeparator; 110 114 }; 111 115
Note:
See TracChangeset
for help on using the changeset viewer.