Changeset 77556 in vbox
- Timestamp:
- Mar 4, 2019 1:33:06 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 129161
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r77377 r77556 971 971 else 972 972 return 0; 973 } 974 975 /* static */ 976 SizeSuffix VBoxGlobal::parseSizeSuffix(const QString &strText) 977 { 978 /* Text should be in form of B|KB|MB|GB|TB|PB. */ 979 QRegExp regexp(sizeRegexp()); 980 int iPos = regexp.indexIn(strText); 981 if (iPos != -1) 982 { 983 QString strInteger = regexp.cap(1); 984 QString strSuff = regexp.cap(2); 985 if (strInteger.isEmpty()) 986 { 987 strInteger = regexp.cap(3); 988 strSuff = regexp.cap(5); 989 } 990 991 SizeSuffix enmSizeSuffix = SizeSuffix_Byte; 992 993 if (strSuff.isEmpty() || strSuff == tr("B", "size suffix Bytes")) 994 enmSizeSuffix = SizeSuffix_Byte; 995 else if (strSuff == tr("KB", "size suffix KBytes=1024 Bytes")) 996 enmSizeSuffix = SizeSuffix_KiloByte; 997 else if (strSuff == tr("MB", "size suffix MBytes=1024 KBytes")) 998 enmSizeSuffix = SizeSuffix_MegaByte; 999 else if (strSuff == tr("GB", "size suffix GBytes=1024 MBytes")) 1000 enmSizeSuffix = SizeSuffix_GigaByte; 1001 else if (strSuff == tr("TB", "size suffix TBytes=1024 GBytes")) 1002 enmSizeSuffix = SizeSuffix_TeraByte; 1003 else if (strSuff == tr("PB", "size suffix PBytes=1024 TBytes")) 1004 enmSizeSuffix = SizeSuffix_PetaByte; 1005 return enmSizeSuffix; 1006 } 1007 else 1008 return SizeSuffix_Byte; 1009 } 1010 1011 /* static */ 1012 bool VBoxGlobal::hasSizeSuffix(const QString &strText) 1013 { 1014 /* Text should be in form of B|KB|MB|GB|TB|PB. */ 1015 QRegExp regexp(sizeRegexp()); 1016 int iPos = regexp.indexIn(strText); 1017 if (iPos != -1) 1018 { 1019 QString strInteger = regexp.cap(1); 1020 QString strSuff = regexp.cap(2); 1021 if (strInteger.isEmpty()) 1022 { 1023 strInteger = regexp.cap(3); 1024 strSuff = regexp.cap(5); 1025 } 1026 1027 if (strSuff.isEmpty()) 1028 return false; 1029 if (strSuff == tr("B", "size suffix Bytes") || 1030 strSuff == tr("KB", "size suffix KBytes=1024 Bytes") || 1031 strSuff == tr("MB", "size suffix MBytes=1024 KBytes") || 1032 strSuff == tr("GB", "size suffix GBytes=1024 MBytes") || 1033 strSuff == tr("TB", "size suffix TBytes=1024 GBytes") || 1034 strSuff == tr("PB", "size suffix PBytes=1024 TBytes")) 1035 return true; 1036 return false; 1037 } 1038 else 1039 return false; 973 1040 } 974 1041 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r77291 r77556 320 320 /** Parses the given size strText and returns the size value in bytes. */ 321 321 static quint64 parseSize(const QString &strText); 322 /** Parses the given size strText and returns the size suffix. */ 323 static SizeSuffix parseSizeSuffix(const QString &strText); 324 /** Parses the given string @a strText and returns true if it includes a size suffix. */ 325 static bool hasSizeSuffix(const QString &strText); 322 326 /** Formats the given @a uSize value in bytes to a human readable string. 323 327 * @param uSize Brings the size value in bytes. -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp
r76606 r77556 25 25 #include "QILineEdit.h" 26 26 #include "VBoxGlobal.h" 27 #include "UIConverter.h" 27 28 #include "UIMediumSizeEditor.h" 28 29 … … 38 39 , m_uSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize()) 39 40 , m_iSliderScale(calculateSliderScale(m_uSizeMax)) 41 , m_uSize(0) 42 , m_enmSizeSuffix(SizeSuffix_Byte) 40 43 , m_pSlider(0) 41 44 , m_pLabelMinSize(0) … … 58 61 m_pEditor->blockSignals(true); 59 62 m_pEditor->setText(vboxGlobal().formatSize(m_uSize)); 63 m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(m_pEditor->text()); 60 64 m_pEditor->blockSignals(false); 61 65 … … 85 89 m_pEditor->blockSignals(true); 86 90 m_pEditor->setText(vboxGlobal().formatSize(m_uSize)); 91 m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(m_pEditor->text()); 87 92 m_pEditor->blockSignals(false); 88 93 /* Update the tool-tips: */ … … 92 97 } 93 98 94 void UIMediumSizeEditor::sltSizeEditorChanged(const QString &strValue) 95 { 99 void UIMediumSizeEditor::sltSizeEditorEditingFinished() 100 { 101 QString strSizeString = ensureSizeSuffix(m_pEditor->text()); 102 103 if (strSizeString != m_pEditor->text()) 104 { 105 m_pEditor->blockSignals(true); 106 m_pEditor->setText(strSizeString); 107 m_pEditor->blockSignals(false); 108 } 109 96 110 /* Update the current size: */ 97 m_uSize = vboxGlobal().parseSize(strValue); 111 m_uSize = checkSectorSizeAlignment(vboxGlobal().parseSize(strSizeString)); 112 98 113 /* Update the other widget: */ 99 114 m_pSlider->blockSignals(true); … … 106 121 } 107 122 108 void UIMediumSizeEditor::sltSizeEditorEditingFinished() 109 { 110 qulonglong uSize = checkSectorSizeAlignment(m_uSize); 111 112 /* The size is already aligned to sector size: */ 113 if (uSize == m_uSize) 114 return; 115 setMediumSize(uSize); 123 QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString) 124 { 125 if (vboxGlobal().hasSizeSuffix(strSizeString)) 126 { 127 /* Update the m_enmSizeSuffix: */ 128 m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(strSizeString); 129 return strSizeString; 130 } 131 132 return QString("%1 %2").arg(strSizeString).arg(gpConverter->toString(m_enmSizeSuffix)); 116 133 } 117 134 … … 180 197 m_pEditor->setAlignment(Qt::AlignRight); 181 198 m_pEditor->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this)); 182 connect(m_pEditor, &QILineEdit::textChanged,183 this, &UIMediumSizeEditor::sltSizeEditorChanged);184 199 connect(m_pEditor, &QILineEdit::editingFinished, 185 200 this, &UIMediumSizeEditor::sltSizeEditorEditingFinished); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h
r76581 r77556 27 27 /* GUI includes: */ 28 28 #include "QIWithRetranslateUI.h" 29 #include "UIDefs.h" 29 30 #include "UILibraryDefs.h" 30 31 … … 65 66 /** Handles size slider change. */ 66 67 void sltSizeSliderChanged(int iValue); 67 /** Handles size editor change. */ 68 void sltSizeEditorChanged(const QString &strValue); 68 /** Handles size editor text edit finished signal. */ 69 69 void sltSizeEditorEditingFinished(); 70 70 … … 86 86 /** Checks if the uSize is divisible by m_uSectorSize */ 87 87 qulonglong checkSectorSizeAlignment(qulonglong uSize); 88 QString ensureSizeSuffix(const QString &strSizeString); 88 89 89 90 /* Holds the block size. We force m_uSize to be multiple of this number. */ … … 97 98 /** Holds the current medium size. */ 98 99 qulonglong m_uSize; 100 SizeSuffix m_enmSizeSuffix; 99 101 100 102 /** Holds the size slider. */
Note:
See TracChangeset
for help on using the changeset viewer.