Changeset 14540 in vbox
- Timestamp:
- Nov 24, 2008 6:44:17 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h
r14509 r14540 124 124 }; 125 125 126 /** Size formatting types. */ 127 enum FormatSize 128 { 129 FormatSize_Round, 130 FormatSize_RoundDown, 131 FormatSize_RoundUp 132 }; 133 126 134 static const char* GUI_LastWindowPosition; 127 135 static const char* GUI_LastWindowPosition_Max; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
r14511 r14540 844 844 845 845 static quint64 parseSize (const QString &); 846 static QString formatSize (quint64, int aMode = 0); 846 static QString formatSize (quint64 aSize, uint aDecimal = 2, 847 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round); 847 848 848 849 static quint64 requiredVideoMemory (CMachine *aMachine = 0); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
r14511 r14540 3825 3825 * in form of <tt>####[.##] B|KB|MB|GB|TB|PB</tt>. 3826 3826 * 3827 * The \a mode parameter is used for r esulting numbers that get a fractional3828 * partafter converting the \a size to KB, MB etc:3827 * The \a mode parameter is used for rounding the resulting number 3828 * after converting the \a size to KB, MB etc: 3829 3829 * <ul> 3830 * <li>When \a mode is 0, the result is rounded to the closest number3831 * c ontaining two decimaldigits.3830 * <li>When \a mode is FormatSize_Round, the result is rounded to the 3831 * closest number containing \a decimal number of digits. 3832 3832 * </li> 3833 * <li>When \a mode is -1, the result is rounded to the largest two decimal 3834 * digit number that is not greater than the result. This guarantees that 3835 * converting the resulting string back to the integer value in bytes 3836 * will not produce a value greater that the initial \a size parameter. 3833 * <li>When \a mode is FormatSize_RoundDown, the result is rounded to the 3834 * largest \a decimal number of digits that is not greater than the 3835 * result. This guarantees that converting the resulting string back 3836 * to the integer value in bytes will not produce a value greater that 3837 * the initial \a size parameter. 3837 3838 * </li> 3838 * <li>When \a mode is 1, the result is rounded to the smallest two decimal 3839 * digit number that is not less than the result. This guarantees that 3840 * converting the resulting string back to the integer value in bytes 3841 * will not produce a value less that the initial \a size parameter. 3839 * <li>When \a mode is FormatSize_RoundUp, the result is rounded to the 3840 * smallest \a decimal number of digits that is not less than the 3841 * result. This guarantees that converting the resulting string back 3842 * to the integer value in bytes will not produce a value less that 3843 * the initial \a size parameter. 3842 3844 * </li> 3843 3845 * </ul> 3844 3846 * 3845 * @param aSize size value in bytes 3846 * @param aMode convertion mode (-1, 0 or 1) 3847 * @return human-readable size string 3847 * @param aSize size value in bytes 3848 * @param aMode convertion mode (FormatSize_Round, FormatSize_RoundDown, 3849 * FormatSize_RoundUp) 3850 * @param aDecimal the number of decimal digits in result 3851 * @return human-readable size string 3848 3852 */ 3849 3853 /* static */ 3850 QString VBoxGlobal::formatSize (quint64 aSize, int aMode /* = 0 */) 3854 QString VBoxGlobal::formatSize (quint64 aSize, uint aDecimal /* = 2 */, 3855 VBoxDefs::FormatSize aMode /* = FormatSize_Round */) 3851 3856 { 3852 3857 static const char *Suffixes [] = { "B", "KB", "MB", "GB", "TB", "PB", NULL }; … … 3887 3892 3888 3893 quint64 intg = aSize / denom; 3889 quint64 hund = aSize % denom; 3894 quint64 decm = aSize % denom; 3895 quint64 mult = 1; 3896 for (uint i = 0; i < aDecimal; ++ i) mult *= 10; 3890 3897 3891 3898 QString number; 3892 3899 if (denom > 1) 3893 3900 { 3894 if ( hund)3895 { 3896 hund *= 100;3901 if (decm) 3902 { 3903 decm *= mult; 3897 3904 /* not greater */ 3898 if (aMode < 0) hund = hund / denom; 3905 if (aMode == VBoxDefs::FormatSize_RoundDown) 3906 decm = decm / denom; 3899 3907 /* not less */ 3900 else if (aMode > 0) hund = (hund + denom - 1) / denom; 3908 else if (aMode == VBoxDefs::FormatSize_RoundUp) 3909 decm = (decm + denom - 1) / denom; 3901 3910 /* nearest */ 3902 else hund = (hund+ denom / 2) / denom;3911 else decm = (decm + denom / 2) / denom; 3903 3912 } 3904 3913 /* check for the fractional part overflow due to rounding */ 3905 if ( hund == 100)3906 { 3907 hund= 0;3914 if (decm == mult) 3915 { 3916 decm = 0; 3908 3917 ++ intg; 3909 3918 /* check if we've got 1024 XB after rounding and scale down if so */ … … 3914 3923 } 3915 3924 } 3916 number = QString ("%1%2%3").arg (intg).arg (decimalSep()) 3917 .arg (QString::number (hund).rightJustified (2, '0')); 3925 number = QString::number (intg); 3926 if (aDecimal) number += QString ("%1%2").arg (decimalSep()) 3927 .arg (QString::number (decm).rightJustified (aDecimal, '0')); 3918 3928 } 3919 3929 else -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxNewHDWzd.cpp
r13580 r14540 128 128 } 129 129 mSliderScale = qMax (mSliderScale, 8); 130 mLeName->setValidator (new QRegExpValidator (QRegExp ( ".+"), this));131 mLeSize->setValidator (new QRegExpValidator (QRegExp (vboxGlobal().sizeRegexp()), this));130 mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this)); 131 mLeSize->setValidator (new QRegExpValidator (QRegExp (vboxGlobal().sizeRegexp()), this)); 132 132 mLeSize->setAlignment (Qt::AlignRight); 133 133 mWValNameAndSize = new QIWidgetValidator (mPageNameAndSize, this); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsGeneral.cpp
r14444 r14540 392 392 "the minimum amount required to switch the virtual machine to " 393 393 "fullscreen or seamless mode.") 394 .arg (vboxGlobal().formatSize (needBytes ));394 .arg (vboxGlobal().formatSize (needBytes, 0, VBoxDefs::FormatSize_RoundUp)); 395 395 return true; 396 396 } -
trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxNewHDWzd.ui
r13580 r14540 603 603 </sizepolicy> 604 604 </property> 605 <property name="text" >606 <string/>607 </property>608 605 <property name="alignment" > 609 606 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> … … 634 631 <verstretch>0</verstretch> 635 632 </sizepolicy> 636 </property>637 <property name="text" >638 <string/>639 633 </property> 640 634 <property name="alignment" >
Note:
See TracChangeset
for help on using the changeset viewer.