void Slider::reloadSlider() { slider->hide(); if (orientation == 0) { slider->setOrientation(Qt::Horizontal); slider->setGeometry(x()+10, height()/2-10, width()-20, 20); } else if (orientation == 1) { slider->setOrientation(Qt::Vertical); slider->setGeometry(width()/2-10, 10, 20, height()-20); } slider->setMinValue(-32768); slider->show(); setTickmarks (tickmarks); setTickInterval (tickInterval); setTracking (tracking); setPageStep(pageStep); setMainColor(mainColor); setTickmarksColor(tickmarksColor); setMinValue(minValue); setMaxValue(maxValue); if (direction == 0) slider->setValue((int)(-32768 + (value-minValue)/lineStep)); else if (direction == 1) slider->setValue((int)(-32768 + (maxValue-value)/lineStep)); setNewMask(); }
Controller::Controller(Game *game, QWidget *parent):QWidget(parent),_game(game) { auto button1 = new QPushButton("Start"); auto button2 = new QPushButton("Pause"); auto button3 = new QPushButton("Reset"); auto speed = new QSlider(Qt::Horizontal ); speed->setMinimum(1); speed->setMaximum(100); speed->setTickInterval(1); speed->setValue(game->speed()); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(button1); layout->addWidget(button2); layout->addWidget(button3); layout->addWidget(speed); //render layout buttons //setLayout(layout); connect(button1,SIGNAL(clicked()),this,SLOT(start())); connect(button2,SIGNAL(clicked()),this,SLOT(pause())); connect(button3,SIGNAL(clicked()),this,SLOT(reset())); connect(speed,SIGNAL(valueChanged(int)),this, SLOT(changeSpeed(int))); }
Slider::Slider( QWidget *parent, const char *name,Qt::WFlags flag) :VtlWidget( parent, name, flag) { resize(100,40); slider = new QSlider(this); slider->setOrientation(Qt::Horizontal); slider->setGeometry(10,10,80,20); slider->setMinValue(-32768); slider->show(); orientation = Qt::Horizontal; direction = LeftToRight; minValue = 0; maxValue = 100; value = 0; tracking = Disabled; tickmarks = 0; tickInterval = 10; lineStep = 10; pageStep = 10; mainColor = Qt::white; tickmarksColor = Qt::black; precision = 1; setTickmarks (tickmarks); setTickInterval (tickInterval); setTracking (tracking); setDirection(direction); setLineStep(lineStep); setPageStep(pageStep); setMainColor(mainColor); setTickmarksColor(tickmarksColor); setNewMask(); MDIRef = NULL; connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(setNewMask())); }
int QSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QAbstractSlider::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 2) qt_static_metacall(this, _c, _id, _a); _id -= 2; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< TickPosition*>(_v) = tickPosition(); break; case 1: *reinterpret_cast< int*>(_v) = tickInterval(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setTickPosition(*reinterpret_cast< TickPosition*>(_v)); break; case 1: setTickInterval(*reinterpret_cast< int*>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
OptionSlider::OptionSlider(double min, double max, int steps):QSlider(Qt::Horizontal), rMin(min), rMax(max - min), steps(steps) { setRange(0, steps); setTickInterval(1); }
void VBoxGuestRAMSlider::init() { ulong fullSize = vboxGlobal().host().GetMemorySize(); CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties(); mMinRAM = sys.GetMinGuestRAM(); mMaxRAM = RT_MIN (RT_ALIGN (fullSize, _1G / _1M), sys.GetMaxGuestRAM()); /* Come up with some nice round percent boundaries relative to * the system memory. A max of 75% on a 256GB config is ridiculous, * even on an 8GB rig reserving 2GB for the OS is way to conservative. * The max numbers can be estimated using the following program: * * double calcMaxPct(uint64_t cbRam) * { * double cbRamOverhead = cbRam * 0.0390625; // 160 bytes per page. * double cbRamForTheOS = RT_MAX(RT_MIN(_512M, cbRam * 0.25), _64M); * double OSPct = (cbRamOverhead + cbRamForTheOS) * 100.0 / cbRam; * double MaxPct = 100 - OSPct; * return MaxPct; * } * * int main() * { * uint64_t cbRam = _1G; * for (; !(cbRam >> 33); cbRam += _1G) * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); * for (; !(cbRam >> 51); cbRam <<= 1) * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); * return 0; * } * * Note. We might wanna put these calculations somewhere global later. */ /* System RAM amount test */ mMaxRAMAlw = (uint)(0.75 * fullSize); mMaxRAMOpt = (uint)(0.50 * fullSize); if (fullSize < 3072) /* done */; else if (fullSize < 4096) /* 3GB */ mMaxRAMAlw = (uint)(0.80 * fullSize); else if (fullSize < 6144) /* 4-5GB */ { mMaxRAMAlw = (uint)(0.84 * fullSize); mMaxRAMOpt = (uint)(0.60 * fullSize); } else if (fullSize < 8192) /* 6-7GB */ { mMaxRAMAlw = (uint)(0.88 * fullSize); mMaxRAMOpt = (uint)(0.65 * fullSize); } else if (fullSize < 16384) /* 8-15GB */ { mMaxRAMAlw = (uint)(0.90 * fullSize); mMaxRAMOpt = (uint)(0.70 * fullSize); } else if (fullSize < 32768) /* 16-31GB */ { mMaxRAMAlw = (uint)(0.93 * fullSize); mMaxRAMOpt = (uint)(0.75 * fullSize); } else if (fullSize < 65536) /* 32-63GB */ { mMaxRAMAlw = (uint)(0.94 * fullSize); mMaxRAMOpt = (uint)(0.80 * fullSize); } else if (fullSize < 131072) /* 64-127GB */ { mMaxRAMAlw = (uint)(0.95 * fullSize); mMaxRAMOpt = (uint)(0.85 * fullSize); } else /* 128GB- */ { mMaxRAMAlw = (uint)(0.96 * fullSize); mMaxRAMOpt = (uint)(0.90 * fullSize); } /* Now check the calculated maximums are out of the range for the guest * RAM. If so change it accordingly. */ mMaxRAMAlw = RT_MIN (mMaxRAMAlw, mMaxRAM); mMaxRAMOpt = RT_MIN (mMaxRAMOpt, mMaxRAM); setPageStep (calcPageStep (mMaxRAM)); setSingleStep (pageStep() / 4); setTickInterval (pageStep()); /* Setup the scale so that ticks are at page step boundaries */ setMinimum ((mMinRAM / pageStep()) * pageStep()); setMaximum (mMaxRAM); setSnappingEnabled (true); setOptimalHint (mMinRAM, mMaxRAMOpt); setWarningHint (mMaxRAMOpt, mMaxRAMAlw); setErrorHint (mMaxRAMAlw, mMaxRAM); }
bool Slider::onPropertyChanged(const QString& name, const QVariant& val) { if ( VtlWidget::onPropertyChanged(name, val) ) return TRUE; VtlActionHandler* actHandler = ((VtlWindow*)this->parentWidget())->actionHandler(); if (name == (QString) "PROCNAME") { processName = val.toString(); } else if (name == (QString) "ORIENTATION") { actHandler->setProperty(this, name, QVariant(orientation), val); setOrientation(val.toInt()); } else if (name == (QString) "MINVALUE") { actHandler->setProperty(this, name, QVariant(minValue), val); setMinValue(val.toDouble()); } else if (name == (QString) "MAXVALUE") { actHandler->setProperty(this, name, QVariant(maxValue), val); setMaxValue(val.toDouble()); } else if (name == (QString) "DIRECTION") { actHandler->setProperty(this, name, QVariant(direction), val); setDirection(val.toInt()); } else if (name == (QString )"SOURCER") { if ( val.toString() != "None" ) { _sourcer = SourcerConnector<VtlWidget>::change (this, _sourcer, val.toString() ); } else _sourcer = 0; } else if (name == (QString) "TRACKING") { actHandler->setProperty(this, name, QVariant(tracking), val); setTracking(val.toInt()); } else if (name == (QString) "TICKMARKS") { actHandler->setProperty(this, name, QVariant(tickmarks), val); setTickmarks(val.toInt()); } else if (name == (QString) "TICKINTERVAL") { actHandler->setProperty(this, name, QVariant(tickInterval), val); setTickInterval(val.toInt()); } else if (name == (QString) "LINESTEP") { actHandler->setProperty(this, name, QVariant(lineStep), val); setLineStep(val.toDouble()); } else if (name == (QString) "PAGESTEP") { actHandler->setProperty(this, name, QVariant(pageStep), val); setPageStep(val.toInt()); } else if (name == (QString) "MAIN_COLOR") { actHandler->setProperty(this, name, QVariant(mainColor), val); setMainColor(val.toColor()); } else if (name == (QString) "TICKMARKS_COLOR") { actHandler->setProperty(this, name, QVariant(tickmarksColor), val); setTickmarksColor(val.toColor()); } else if (name == (QString) "PRECISION") { actHandler->setProperty(this, name, QVariant(precision), val); setPrecision(val.toInt()); } repaint(); return TRUE; }