- Timestamp:
- Jul 3, 2009 12:24:28 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/QIAdvancedSlider.h
r21120 r21194 26 26 /* Qt includes */ 27 27 #include <QSlider> 28 29 class CPrivateSlider; 28 30 29 31 class QIAdvancedSlider: public QWidget … … 62 64 bool isSnappingEnabled() const; 63 65 66 void setOptimalHint (int aMin, int aMax); 67 void setWarningHint (int aMin, int aMax); 68 void setErrorHint (int aMin, int aMax); 69 64 70 public slots: 65 71 … … 83 89 84 90 /* Private member vars */ 85 QSlider *mSlider;91 CPrivateSlider *mSlider; 86 92 bool mSnappingEnabled; 87 93 }; -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsSystem.h
r21132 r21194 82 82 uint mMinGuestCPU; 83 83 uint mMaxGuestCPU; 84 85 int mMaxRAMAllowed; 86 int mMaxRAMOptimum; 84 87 }; 85 88 -
trunk/src/VBox/Frontends/VirtualBox/src/QIAdvancedSlider.cpp
r21124 r21194 22 22 23 23 #include "QIAdvancedSlider.h" 24 #include "VBoxGlobal.h" 24 25 25 26 /* Qt includes */ 26 27 #include <QVBoxLayout> 28 #include <QPainter> 29 #include <QStyle> 30 #include <QStyleOptionSlider> 27 31 28 32 /* System includes */ 29 33 #include <math.h> 30 34 35 class CPrivateSlider: public QSlider 36 { 37 public: 38 CPrivateSlider (Qt::Orientation aOrientation, QWidget *aParent = 0) 39 : QSlider (aOrientation, aParent) 40 , mOptColor (0x0, 0xff, 0x0, 0x3c) 41 , mWrnColor (0xff, 0x54, 0x0, 0x3c) 42 , mErrColor (0xff, 0x0, 0x0, 0x3c) 43 , mMinOpt (-1) 44 , mMaxOpt (-1) 45 , mMinWrn (-1) 46 , mMaxWrn (-1) 47 , mMinErr (-1) 48 , mMaxErr (-1) 49 {} 50 51 int positionForValue (int aVal) const 52 { 53 QStyleOptionSlider opt; 54 initStyleOption (&opt); 55 opt.subControls = QStyle::SC_All; 56 int available = style()->pixelMetric (QStyle::PM_SliderSpaceAvailable, &opt, this); 57 return QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, aVal, available); 58 } 59 60 virtual void paintEvent ( QPaintEvent * event ) 61 { 62 QPainter p(this); 63 64 QStyleOptionSlider opt; 65 initStyleOption (&opt); 66 opt.subControls = QStyle::SC_All; 67 68 int available = style()->pixelMetric (QStyle::PM_SliderSpaceAvailable, &opt, this); 69 QSize s = size(); 70 71 QRect ticks = style()->subControlRect (QStyle::CC_Slider, &opt, QStyle::SC_SliderTickmarks, this); 72 if (ticks.isNull() || ticks.isEmpty()) 73 { 74 ticks = style()->subControlRect (QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this) | style()->subControlRect (QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this); 75 ticks.setRect ((s.width() - available) / 2, ticks.bottom() + 1, available, s.height() - ticks.bottom() - 1); 76 } 77 if (mMinOpt != -1 && 78 mMaxOpt != -1) 79 { 80 int posMinOpt = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMinOpt, available); 81 int posMaxOpt = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMaxOpt, available); 82 p.fillRect (ticks.x() + posMinOpt, ticks.y(), posMaxOpt - posMinOpt + 1, ticks.height(), mOptColor); 83 } 84 if (mMinWrn != -1 && 85 mMaxWrn != -1) 86 { 87 int posMinWrn = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMinWrn, available); 88 int posMaxWrn = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMaxWrn, available); 89 p.fillRect (ticks.x() + posMinWrn, ticks.y(), posMaxWrn - posMinWrn + 1, ticks.height(), mWrnColor); 90 } 91 if (mMinErr != -1 && 92 mMaxErr != -1) 93 { 94 int posMinErr = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMinErr, available); 95 int posMaxErr = QStyle::sliderPositionFromValue (opt.minimum, opt.maximum, mMaxErr, available); 96 p.fillRect (ticks.x() + posMinErr, ticks.y(), posMaxErr - posMinErr + 1, ticks.height(), mErrColor); 97 } 98 99 QSlider::paintEvent (event); 100 } 101 102 QColor mOptColor; 103 QColor mWrnColor; 104 QColor mErrColor; 105 106 int mMinOpt; 107 int mMaxOpt; 108 int mMinWrn; 109 int mMaxWrn; 110 int mMinErr; 111 int mMaxErr; 112 }; 31 113 32 114 QIAdvancedSlider::QIAdvancedSlider (QWidget *aParent /* = 0 */) … … 125 207 { 126 208 return mSnappingEnabled; 209 } 210 211 void QIAdvancedSlider::setOptimalHint (int aMin, int aMax) 212 { 213 mSlider->mMinOpt = aMin; 214 mSlider->mMaxOpt = aMax; 215 } 216 217 void QIAdvancedSlider::setWarningHint (int aMin, int aMax) 218 { 219 mSlider->mMinWrn = aMin; 220 mSlider->mMaxWrn = aMax; 221 } 222 223 void QIAdvancedSlider::setErrorHint (int aMin, int aMax) 224 { 225 mSlider->mMinErr = aMin; 226 mSlider->mMaxErr = aMax; 127 227 } 128 228 … … 146 246 void QIAdvancedSlider::init (Qt::Orientation aOrientation /* = Qt::Horizontal */) 147 247 { 148 mSnappingEnabled = true;248 mSnappingEnabled = false; 149 249 150 250 QVBoxLayout *pMainLayout = new QVBoxLayout (this); 151 mSlider = new QSlider (aOrientation, this); 251 VBoxGlobal::setLayoutMargin (pMainLayout, 0); 252 mSlider = new CPrivateSlider (aOrientation, this); 152 253 pMainLayout->addWidget (mSlider); 153 254 … … 164 265 { 165 266 float l2 = log ((float)val)/log (2.0); 166 float snap = 1.0/l2 * 2; /* How much border around the current snaping value (%) */167 267 int newVal = pow ((float)2, (int)qRound (l2)); /* The value to snap on */ 168 if (abs (newVal - val) < (snap * newVal)) /* Snap only if we are in a defined array */ 268 int pos = mSlider->positionForValue (val); /* Get the relative screen pos for the original value */ 269 int newPos = mSlider->positionForValue (newVal); /* Get the relative screen pos for the snap value */ 270 if (abs (newPos - pos) < 5) /* 10 pixel snapping range */ 169 271 { 170 272 val = newVal; … … 177 279 return val; 178 280 } 281 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsDisplay.cpp
r20085 r21194 74 74 mSlMemory->setMinimum ((MinVRAM / mSlMemory->pageStep()) * mSlMemory->pageStep()); 75 75 mSlMemory->setMaximum (MaxVRAM); 76 mSlMemory->setSnappingEnabled (true); 77 quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&mMachine) / _1M; 78 mSlMemory->setErrorHint (0, 1); 79 mSlMemory->setWarningHint (1, needMBytes); 80 mSlMemory->setOptimalHint (needMBytes, MaxVRAM); 76 81 /* Limit min/max. size of QLineEdit */ 77 82 mLeMemory->setFixedWidthByText (QString().fill ('8', 4)); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsSystem.cpp
r21130 r21194 57 57 mMinGuestRAM = sys.GetMinGuestRAM(); 58 58 mMaxGuestRAM = RT_MIN (RT_ALIGN (vboxGlobal().virtualBox().GetHost().GetMemorySize(), _1G / _1M), sys.GetMaxGuestRAM()); 59 uint hostCPUs = vboxGlobal().virtualBox().GetHost().GetProcessorCount(); 59 60 mMinGuestCPU = sys.GetMinGuestCPUCount(); 60 mMaxGuestCPU = RT_MIN (2 * vboxGlobal().virtualBox().GetHost().GetProcessorCount(), sys.GetMaxGuestCPUCount()); 61 mMaxGuestCPU = RT_MIN (2 * hostCPUs, sys.GetMaxGuestCPUCount()); 62 63 /* Come up with some nice round percent boundraries relative to 64 * the system memory. A max of 75% on a 256GB config is ridiculous, 65 * even on an 8GB rig reserving 2GB for the OS is way to conservative. 66 * The max numbers can be estimated using the following program: 67 * 68 * double calcMaxPct(uint64_t cbRam) 69 * { 70 * double cbRamOverhead = cbRam * 0.0390625; // 160 bytes per page. 71 * double cbRamForTheOS = RT_MAX(RT_MIN(_512M, cbRam * 0.25), _64M); 72 * double OSPct = (cbRamOverhead + cbRamForTheOS) * 100.0 / cbRam; 73 * double MaxPct = 100 - OSPct; 74 * return MaxPct; 75 * } 76 * 77 * int main() 78 * { 79 * uint64_t cbRam = _1G; 80 * for (; !(cbRam >> 33); cbRam += _1G) 81 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), 82 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); 83 * for (; !(cbRam >> 51); cbRam <<= 1) 84 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), 85 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); 86 * return 0; 87 * } 88 * 89 * Note. We might wanna put these calculations somewhere global later. */ 90 91 /* System RAM amount test */ 92 ulong fullSize = vboxGlobal().virtualBox().GetHost().GetMemorySize(); 93 mMaxRAMAllowed = 0.75 * fullSize; 94 mMaxRAMOptimum = 0.50 * fullSize; 95 if (fullSize < 3072) 96 /* done */; 97 else if (fullSize < 4096) /* 3GB */ 98 mMaxRAMAllowed = 0.80 * fullSize; 99 else if (fullSize < 6144) /* 4-5GB */ 100 { 101 mMaxRAMAllowed = 0.84 * fullSize; 102 mMaxRAMOptimum = 0.60 * fullSize; 103 } 104 else if (fullSize < 8192) /* 6-7GB */ 105 { 106 mMaxRAMAllowed = 0.88 * fullSize; 107 mMaxRAMOptimum = 0.65 * fullSize; 108 } 109 else if (fullSize < 16384) /* 8-15GB */ 110 { 111 mMaxRAMAllowed = 0.90 * fullSize; 112 mMaxRAMOptimum = 0.70 * fullSize; 113 } 114 else if (fullSize < 32768) /* 16-31GB */ 115 { 116 mMaxRAMAllowed = 0.93 * fullSize; 117 mMaxRAMOptimum = 0.75 * fullSize; 118 } 119 else if (fullSize < 65536) /* 32-63GB */ 120 { 121 mMaxRAMAllowed = 0.94 * fullSize; 122 mMaxRAMOptimum = 0.80 * fullSize; 123 } 124 else if (fullSize < 131072) /* 64-127GB */ 125 { 126 mMaxRAMAllowed = 0.95 * fullSize; 127 mMaxRAMOptimum = 0.85 * fullSize; 128 } 129 else /* 128GB- */ 130 { 131 mMaxRAMAllowed = 0.96 * fullSize; 132 mMaxRAMOptimum = 0.90 * fullSize; 133 } 61 134 62 135 /* Setup validators */ … … 103 176 mSlMemory->setMinimum ((mMinGuestRAM / mSlMemory->pageStep()) * mSlMemory->pageStep()); 104 177 mSlMemory->setMaximum (mMaxGuestRAM); 178 mSlMemory->setSnappingEnabled (true); 179 mSlMemory->setOptimalHint (1, mMaxRAMOptimum); 180 mSlMemory->setWarningHint (mMaxRAMOptimum, mMaxRAMAllowed); 181 mSlMemory->setErrorHint (mMaxRAMAllowed, mMaxGuestRAM); 105 182 /* Limit min/max. size of QLineEdit */ 106 183 mLeMemory->setFixedWidthByText (QString().fill ('8', 5)); … … 115 192 mSlCPU->setMinimum (mMinGuestCPU); 116 193 mSlCPU->setMaximum (mMaxGuestCPU); 194 mSlCPU->setOptimalHint (1, hostCPUs); 195 mSlCPU->setWarningHint (hostCPUs, mMaxGuestCPU); 117 196 /* Limit min/max. size of QLineEdit */ 118 197 mLeCPU->setFixedWidthByText (QString().fill ('8', 3)); … … 274 353 bool VBoxVMSettingsSystem::revalidate (QString &aWarning, QString & /* aTitle */) 275 354 { 276 /* Come up with some nice round percent boundraries relative to277 * the system memory. A max of 75% on a 256GB config is ridiculous,278 * even on an 8GB rig reserving 2GB for the OS is way to conservative.279 * The max numbers can be estimated using the following program:280 *281 * double calcMaxPct(uint64_t cbRam)282 * {283 * double cbRamOverhead = cbRam * 0.0390625; // 160 bytes per page.284 * double cbRamForTheOS = RT_MAX(RT_MIN(_512M, cbRam * 0.25), _64M);285 * double OSPct = (cbRamOverhead + cbRamForTheOS) * 100.0 / cbRam;286 * double MaxPct = 100 - OSPct;287 * return MaxPct;288 * }289 *290 * int main()291 * {292 * uint64_t cbRam = _1G;293 * for (; !(cbRam >> 33); cbRam += _1G)294 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam),295 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20);296 * for (; !(cbRam >> 51); cbRam <<= 1)297 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam),298 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20);299 * return 0;300 * }301 *302 * Note. We might wanna put these calculations somewhere global later. */303 304 /* System RAM amount test */305 355 ulong fullSize = vboxGlobal().virtualBox().GetHost().GetMemorySize(); 306 double maxPct = 0.75; 307 double warnPct = 0.50; 308 if (fullSize < 3072) 309 /* done */; 310 else if (fullSize < 4096) /* 3GB */ 311 maxPct = 0.80; 312 else if (fullSize < 6144) /* 4-5GB */ 313 { 314 maxPct = 0.84; 315 warnPct = 0.60; 316 } 317 else if (fullSize < 8192) /* 6-7GB */ 318 { 319 maxPct = 0.88; 320 warnPct = 0.65; 321 } 322 else if (fullSize < 16384) /* 8-15GB */ 323 { 324 maxPct = 0.90; 325 warnPct = 0.70; 326 } 327 else if (fullSize < 32768) /* 16-31GB */ 328 { 329 maxPct = 0.93; 330 warnPct = 0.75; 331 } 332 else if (fullSize < 65536) /* 32-63GB */ 333 { 334 maxPct = 0.94; 335 warnPct = 0.80; 336 } 337 else if (fullSize < 131072) /* 64-127GB */ 338 { 339 maxPct = 0.95; 340 warnPct = 0.85; 341 } 342 else /* 128GB- */ 343 { 344 maxPct = 0.96; 345 warnPct = 0.90; 346 } 347 348 if (mSlMemory->value() > maxPct * fullSize) 356 if (mSlMemory->value() > mMaxRAMAllowed) 349 357 { 350 358 aWarning = tr ( … … 352 360 "(<b>%2</b>) to the virtual machine. Not enough memory is left " 353 361 "for your host operating system. Please select a smaller amount.") 354 .arg ((unsigned) (maxPct * 100))362 .arg ((unsigned)qRound ((double)mMaxRAMAllowed / fullSize * 100.0)) 355 363 .arg (vboxGlobal().formatSize ((uint64_t)fullSize * _1M)); 356 364 return false; 357 365 } 358 if (mSlMemory->value() > warnPct * fullSize)366 if (mSlMemory->value() > mMaxRAMOptimum) 359 367 { 360 368 aWarning = tr ( … … 362 370 "(<b>%2</b>) to the virtual machine. Not enough memory might be " 363 371 "left for your host operating system. Continue at your own risk.") 364 .arg ((unsigned) (warnPct * 100))372 .arg ((unsigned)qRound ((double)mMaxRAMOptimum / fullSize * 100.0)) 365 373 .arg (vboxGlobal().formatSize ((uint64_t)fullSize * _1M)); 366 374 return true; -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsSystem.ui
r21119 r21194 397 397 </property> 398 398 <item> 399 <widget class="Q Slider" name="mSlCPU">399 <widget class="QIAdvancedSlider" name="mSlCPU"> 400 400 <property name="whatsThis"> 401 401 <string>Controls the number of virtual CPUs in the virtual machine.</string>
Note:
See TracChangeset
for help on using the changeset viewer.