Example #1
0
void IntValueEditor::keyPressEvent(QKeyEvent* e)
{
	switch (e->key())
	{
		case Qt::Key_BracketLeft:
			setSingleStep((int)(singleStep() * 10.0));
			QSettings().setValue(QString("intvalueeditor/%1/singlestep").arg(objectName()), singleStep());
			break;

		case Qt::Key_BracketRight:
			setSingleStep(qMax((int)(default_step * 0.10), 1));
			QSettings().setValue(QString("intvalueeditor/%1/singlestep").arg(objectName()), singleStep());
			break;

		case Qt::Key_Return:
			QSpinBox::keyPressEvent(e);
			emit undoStateSignal();
			break;

		case Qt::Key_Backslash:
			WheelValueEditor::WHEEL_EVENTS_ENABLED
			= ! WheelValueEditor::WHEEL_EVENTS_ENABLED;
			break;

		default:
			QSpinBox::keyPressEvent(e);
	}
}
Example #2
0
void SliderDoubleSpinBox::mousePressEvent(QMouseEvent * event)
{
    if (event->buttons() & Qt::LeftButton) {
        QStyleOptionSpinBox spinOpts = d->spinBoxOptions();
        // mouse in progress area?
        if (d->progressRect(spinOpts).contains(event->pos())
            && ! lineEdit()->isVisible())
        {
            setValue(d->valueForX(event->pos().x()));
        }
        // mouse over up-button?
        else if (d->upButtonRect(spinOpts).contains(event->pos())) {
            setValue(value() + singleStep());
            d->pressedInButton = true;
        }
        // mouse over down-button?
        else if (d->downButtonRect(spinOpts).contains(event->pos())) {
            setValue(value() - singleStep());
            d->pressedInButton = true;
        } else {
            // whatever this mouse press is, just pass it on
            QDoubleSpinBox::mousePressEvent(event);
        }
    } else if (event->buttons() & Qt::RightButton) {
        // right now, RMB switches into line edit mode
        d->showLineEdit();
    }
}
void ModQDoubleSpinBox::stepBy(int steps)
{
	double cpValue = 0, crValue = 0, newValue = 0; double delta = 0;
	if (_discreteValuesMode)
	{
		// Get current round value:
		crValue = pow(10,-decimals()) * round( value()*pow(10,decimals()) );
		if (singleStep() < pow(10, -decimals()))
		{
			// Calculate new value:
			newValue = crValue + (steps * pow(10, -decimals()));
			newValue = roundToNextDiscreteValue( newValue );
		}
		else
		{
			// Get current precise value:
			cpValue = roundToNextDiscreteValue( value() );
			// Correct nr of steps (if necessary):
			if (steps > 0)
				delta = cpValue - crValue;
			else // < 0 (= 0 ???)
				delta = crValue - cpValue;
			if (delta >= (pow(10, -decimals()) - _precCorrVal))
				steps -= steps/abs(steps);
			// Calculate new value:
			newValue = cpValue + (steps * singleStep());
		}
		// Set new value (automatic round to decimals):
		QDoubleSpinBox::setValue( newValue );
	}
	else
		QDoubleSpinBox::stepBy(steps);
}
Example #4
0
void SliderDoubleSpinBox::keyPressEvent(QKeyEvent * event)
{
    if (lineEdit()->isVisible()) {
        // on Escape, just hide the line edit and do nothing
        if (event->key() == Qt::Key_Escape) {
            lineEdit()->hide();
        }
        QDoubleSpinBox::keyPressEvent(event);
        return;
    }

    switch (event->key()) {
        case Qt::Key_Up:
        case Qt::Key_Right:
            setValue(value() + singleStep());
            break;
        case Qt::Key_Down:
        case Qt::Key_Left:
            setValue(value() - singleStep());
            break;
        case Qt::Key_Escape:
            // do nothing
            break;
        default:
            // for all other keys, show the line edit and pass the event to
            // the line edit so that the typed digit already counts as input
            d->showLineEdit();
            lineEdit()->event(event);
            break;
    }
}
Example #5
0
//! A size hint
QSize QwtCounter::sizeHint() const
{
    QString tmp;

    int w = tmp.setNum( minimum() ).length();
    int w1 = tmp.setNum( maximum() ).length();
    if ( w1 > w )
        w = w1;
    w1 = tmp.setNum( minimum() + singleStep() ).length();
    if ( w1 > w )
        w = w1;
    w1 = tmp.setNum( maximum() - singleStep() ).length();
    if ( w1 > w )
        w = w1;

    tmp.fill( '9', w );

    QFontMetrics fm( d_data->valueEdit->font() );
    w = fm.width( tmp ) + 2;
    if ( d_data->valueEdit->hasFrame() )
        w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth );

    // Now we replace default sizeHint contribution of d_data->valueEdit by
    // what we really need.

    w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();

    const int h = qMin( QWidget::sizeHint().height(),
        d_data->valueEdit->minimumSizeHint().height() );
    return QSize( w, h );
}
Example #6
0
void IntValueEditor::restoreSettings()
{
	if (objectName().isEmpty())
		logWarn("IntValueEditor::restoreSettings : nameless object found");

	setSingleStep(QSettings().value(
		QString("intvalueeditor/%1/singlestep").arg(objectName()), singleStep()).toInt());

	default_step = singleStep();
}
void CSliderMultiPos::triggerAction(QAbstractSlider::SliderAction action){
    bool noAction = false;
    int newPos = 0;
    int minPos;
    int maxPos;

    if( lastPressedIndex==0 ){
        minPos = minimum();
    }
    else{
        minPos = handles.at(lastPressedIndex-1).getPosition();
    }
    if( lastPressedIndex==(nbValues()-1) ){
        maxPos = maximum();
    }
    else{
        minPos = handles.at(lastPressedIndex-1).getPosition();
    }

    blockTracking = true;
    switch( action ){
        case QAbstractSlider::SliderSingleStepAdd :
            newPos = qBound( minPos,minPos + singleStep(),maxPos );
            break;
        case QAbstractSlider::SliderSingleStepSub :
            newPos = qBound( minPos,maxPos - singleStep(),maxPos );
            break;
        case QAbstractSlider::SliderToMinimum :
            newPos = minPos;
            break;
        case QAbstractSlider::SliderToMaximum :
            newPos = maxPos;
            break;
        case QAbstractSlider::SliderMove :
        case QAbstractSlider::SliderNoAction :
            noAction = true;
            break;
        default :
            qWarning( "QxtSpanSliderPrivate::triggerAction: Unknown action" );
            break;
    }

    if( noAction ){
        // Nothing to do for this action
    }
    else{
        newPos = collisionDetection(newPos);
        setCurPosition( lastPressedIndex,newPos );
    }
    blockTracking = false;
}
void DoubleValueEditor::restoreSettings()
{
	QSettings settings;

	if (objectName().isEmpty())
		logWarn("DoubleValueEditor::restoreSettings : nameless object found");

	setSingleStep(settings.value(
		QString("doublevalueeditor/%1/singlestep").arg(objectName()), singleStep()).toDouble());
	setDecimals(settings.value(
		QString("doublevalueeditor/%1/decimals").arg(objectName()), decimals()).toInt());

	default_step = singleStep();
}
Example #9
0
/******************************************************************************
* Return the initial adjustment to the value for a shift step up or down, for
* the main (visible) spin box.
* Normally this is a line step, but with a right-to-left language where the
* button functions are reversed, this is a page step.
*/
int SpinBox2::MainSpinBox::shiftStepAdjustment(int oldValue, int shiftStep)
{
    if (owner->reverseButtons())
    {
        // The button pairs have the opposite function from normal.
        // Page shift stepping - step up or down to a multiple of the
        // shift page increment, leaving unchanged the part of the value
        // which is the remainder from the page increment.
        if (oldValue >= 0)
            oldValue -= oldValue % singleStep();
        else
            oldValue += (-oldValue) % singleStep();
    }
    return SpinBox::shiftStepAdjustment(oldValue, shiftStep);
}
Example #10
0
// normal sizeHint doesn't always work right for our case, 
// because the min/max/special text aren't necessarily the longest text
QSize MinSecSpinBox::sizeHint() const
{
    QSize normal = QSpinBox::sizeHint();
    
    //this first portion copied from QAbstractSpinBox
    const QFontMetrics fm(fontMetrics());
    int w = 0;
    QString s;
    s = prefix() + textFromValue(minimum()) + suffix() + QLatin1Char(' ');
    s.truncate(18);
    w = qMax(w, fm.width(s));
    s = prefix() + textFromValue(maximum()) + suffix() + QLatin1Char(' ');
    s.truncate(18);
    w = qMax(w, fm.width(s));
    if (specialValueText().size()) {
        s = specialValueText();
        w = qMax(w, fm.width(s));
    }
    w += 2; // cursor blinking space
    
    //new part (see if max - singlestep is longer)
    s = textFromValue(maximum()-singleStep()) + QLatin1Char(' ');
    int longwidth = fm.width(s) + 2;
    int dif = longwidth - w;
    if (dif > 0)
        normal += QSize(dif, 0);
    
    return normal;
}
Example #11
0
void IntValueEditor::wheelEvent(QWheelEvent* e)
{
	if (!QSpinBox::isActiveWindow())
		QSpinBox::activateWindow();
	QSpinBox::setFocus(Qt::MouseFocusReason);

	int step = default_step = singleStep();
	if (e->modifiers() & Qt::ShiftModifier)
	{
		if (step >= 10.0)
			setSingleStep(step = (int)(step / 10.0));
	}
	else if (e->modifiers() & Qt::ControlModifier)
		setSingleStep(step = step * 10);

	if (e->delta() > 0)
		stepUp();
	else
		stepDown();

	if (step != default_step)
		setSingleStep(default_step);

	if (wheelEventSignal && WheelValueEditor::WHEEL_EVENTS_ENABLED)
		emit valueUpdated();
}
void ModQDoubleSpinBox::recalcPrecCorrValue()
{
	int base_decimals = static_cast<int>(-floor(log10(_DVMbaseValue)));
	int singleStep_decimals = static_cast<int>(-floor(log10(singleStep())));
	int corrVal_decimals = 1 + std::max(decimals(), std::max(base_decimals, singleStep_decimals));
	_precCorrVal = pow(10,-corrVal_decimals);
}
Example #13
0
/*!
  \brief Set the minimum and maximum values

  The maximum is adjusted if necessary to ensure that the range remains valid.
  The value might be modified to be inside of the range.

  \param min Minimum value
  \param max Maximum value

  \sa minimum(), maximum()
 */
void QwtCounter::setRange( double min, double max )
{
    max = qMax( min, max );

    if ( d_data->maximum == max && d_data->minimum == min )
        return;

    d_data->minimum = min;
    d_data->maximum = max;

    setSingleStep( singleStep() );

    const double value = qBound( min, d_data->value, max );

    if ( value != d_data->value )
    {
        d_data->value = value;

        if ( d_data->isValid )
        {
            showNumber( value );
            Q_EMIT valueChanged( value );
        }
    }

    updateButtons();
}
Example #14
0
void DoubleValueEditor::mouseMoveEvent(QMouseEvent* e)
{
	if (e->buttons() & Qt::LeftButton)
	{
		double dy = e->y() - last_pos.y();
		double step = default_step = singleStep();
		last_pos = e->posF();
		last_press = 0;

		if (e->modifiers() & Qt::ShiftModifier)
			setSingleStep(step /= 10.0);
		else if (e->modifiers() & Qt::ControlModifier)
			setSingleStep(step *= 10.0);

		if (dy < 0)
		{
			stepUp();
			emit valueUpdated();
		}
		else if (dy > 0)
		{
			stepDown();
			emit valueUpdated();
		}

		if (step != default_step)
			setSingleStep(default_step);
	}
}
double ModQDoubleSpinBox::roundToNextDiscreteValue(double inValue)
{
	double d_new = 0;
	double kcorr = 0;
	if (singleStep() != 0)
	{
		if ((inValue >= 0))
			kcorr = _precCorrVal;
		if ((inValue < 0))
			kcorr = - _precCorrVal;
		d_new = singleStep() * round(((inValue - _DVMbaseValue + kcorr) / singleStep())) + _DVMbaseValue;
	}
	else
		d_new = inValue;
	return d_new;
}
Example #16
0
// Function copied from qslider.cpp and modified to make it compile
void Slider::initStyleOption_Qt430( QStyleOptionSlider *option ) const
{
	if (!option)
		return;

	option->initFrom( this );
	option->subControls       = QStyle::SC_None;
	option->activeSubControls = QStyle::SC_None;
	option->orientation       = orientation();
	option->maximum           = maximum();
	option->minimum           = minimum();
	option->tickPosition      = (QSlider::TickPosition) tickPosition();
	option->tickInterval      = tickInterval();
	option->upsideDown        = (orientation() == Qt::Horizontal) ?
								   (invertedAppearance() != (option->direction == Qt::RightToLeft))
								 : (!invertedAppearance());
	option->direction         = Qt::LeftToRight; // we use the upsideDown option instead
	option->sliderPosition    = sliderPosition();
	option->sliderValue       = value();
	option->singleStep        = singleStep();
	option->pageStep          = pageStep();

	if (orientation() == Qt::Horizontal)
		option->state |= QStyle::State_Horizontal;
}
Example #17
0
void CalculationThread::run() {

    seedmap->resetMatches();

    while(singleStep()) {}


}
void VariableDoubleSpinBox::stepBy(int steps)
{
    double oldValue = value();
	
	// Default new value
	int i = -99;
	double newValue = oldValue + singleStep() * steps;

	// If a single digit is selected, increment or decrement that digit
	if (lineEdit()->hasSelectedText())
	{
		if (lineEdit()->selectedText().length() == 1)
		{
			if (lineEdit()->selectedText()[0].isDigit())
			{
				i = cleanText().length() - lineEdit()->selectionStart();
				int j = cleanText().length() - lineEdit()->selectionStart() - decimals();
				if (decimals() > 0)
				{
					j--;
				}
				if (j >= 0)
				{
					j--;
				}
				newValue = oldValue + pow(10.0, j) * steps;
			}
		}
	}

	// Check for out of bounds and set the new value
	if (newValue < minimum())
	{
		return;
	}
	else if (newValue > maximum())
	{
		return;
	}
	setValue(newValue);

	// For unknown reasons, after the new value is set the selected text changes in unpredictable ways
	// Fix it
	if (i == -99)
	{
		lineEdit()->selectAll();
	}
	else
	{
		i = cleanText().length() - i;
		if (i < 0)
		{
			i = 0;
		}
		lineEdit()->setSelection(i, 1);
	}
}
Example #19
0
void DoubleValueEditor::keyPressEvent(QKeyEvent* e)
{
	switch (e->key())
	{
		case Qt::Key_BracketLeft:
			setSingleStep(singleStep() * 10.0);
			QSettings().setValue(QString("doublevalueeditor/%1/singlestep").arg(objectName()), singleStep());
			break;

		case Qt::Key_BracketRight:
			setSingleStep(singleStep() * 0.10);
			QSettings().setValue(QString("doublevalueeditor/%1/singlestep").arg(objectName()), singleStep());
			break;

		case Qt::Key_Return:
			QDoubleSpinBox::keyPressEvent(e);
			emit undoStateSignal();
			break;

		case Qt::Key_Backslash:
			WheelValueEditor::WHEEL_EVENTS_ENABLED
					= ! WheelValueEditor::WHEEL_EVENTS_ENABLED;
			break;

		case Qt::Key_Plus:
			if (e->modifiers() & Qt::ControlModifier)
			{
				setDecimals(decimals() + 1);
				QSettings().setValue(QString("doublevalueeditor/%1/decimals").arg(objectName()), decimals());
			}
			break;

		case Qt::Key_Minus:
			if (e->modifiers() & Qt::ControlModifier)
			{
				setDecimals(qMax(1, decimals() - 1));
				QSettings().setValue(QString("doublevalueeditor/%1/decimals").arg(objectName()), decimals());
			}
			break;

		default:
			QDoubleSpinBox::keyPressEvent(e);
	}
}
Example #20
0
int main() {
	unsigned int step;
	initialize();
	debugPrint();
	for (step = 0; step < M; step++)
		singleStep();
	debugPrint();
	debugGnuplot();
	return 0;
}
Example #21
0
QWidget * BigNumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
    BigNumSpin* result = new BigNumSpin(parent);
    result->setMinimum(minimum());
    result->setMaximum(maximum());
    result->setDecimals(decimals());
    result->setSingleStep(singleStep());
    result->setPrefix(prefix());
    result->setSuffix(suffix());
    return result;
}
Example #22
0
int QDoubleSpinBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractSpinBox::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 3)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 3;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = prefix(); break;
        case 1: *reinterpret_cast< QString*>(_v) = suffix(); break;
        case 2: *reinterpret_cast< QString*>(_v) = cleanText(); break;
        case 3: *reinterpret_cast< int*>(_v) = decimals(); break;
        case 4: *reinterpret_cast< double*>(_v) = minimum(); break;
        case 5: *reinterpret_cast< double*>(_v) = maximum(); break;
        case 6: *reinterpret_cast< double*>(_v) = singleStep(); break;
        case 7: *reinterpret_cast< double*>(_v) = value(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setPrefix(*reinterpret_cast< QString*>(_v)); break;
        case 1: setSuffix(*reinterpret_cast< QString*>(_v)); break;
        case 3: setDecimals(*reinterpret_cast< int*>(_v)); break;
        case 4: setMinimum(*reinterpret_cast< double*>(_v)); break;
        case 5: setMaximum(*reinterpret_cast< double*>(_v)); break;
        case 6: setSingleStep(*reinterpret_cast< double*>(_v)); break;
        case 7: setValue(*reinterpret_cast< double*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #23
0
void StepperMotor::turn(byte reverse, int degrees, byte stepmode){
	byte _reverse = reverse;
	
	//flip direction if degrees are negative
	if(degrees<0){
		_reverse = !reverse;
	}
	
	//perform the required amount of steps
	for(unsigned int i = 0;i<degrees*STEPS_PER_DEGREE;i++){
		singleStep(_reverse,stepmode);
	}
}
Example #24
0
void TcpConnected::writeStateBinary(const SingleStep& step) {
    String singleStep("01234\n");

    uint8_t index = 0;
    singleStep.setCharAt(index++, count);
    singleStep.setCharAt(index++, step.values[SingleStep::IrValue]);
    singleStep.setCharAt(index++,step.values[SingleStep::LightValue]);
    singleStep.setCharAt(index++,step.values[SingleStep::IrThreshold]);
    singleStep.setCharAt(index++,step.values[SingleStep::LightThreshold]);
    singleStep.setCharAt(index++,'\n');

    parent->getTcp()->write(singleStep);
}
    int readOrSkip (void* buffer, int bytesToRead, bool skip)
    {
        if (bytesToRead <= 0)
            return 0;

        size_t pos = 0;
        size_t len = static_cast<size_t> (bytesToRead);

        while (len > 0)
        {
            size_t bufferBytes = curlBuffer.getSize();
            bool removeSection = true;

            if (bufferBytes == 0)
            {
                // do not call curl again if we are finished
                {
                    const ScopedLock lock (cleanupLock);

                    if (finished || curl == nullptr)
                        return static_cast<int> (pos);
                }

                skipBytes = skip ? len : 0;
                singleStep();

                // update the amount that was read/skipped from curl
                bufferBytes = skip ? len - skipBytes : curlBuffer.getSize();
                removeSection = ! skip;
            }

            // can we copy data from the internal buffer?
            if (bufferBytes > 0)
            {
                size_t max = jmin (len, bufferBytes);

                if (! skip)
                    memcpy (addBytesToPointer (buffer, pos), curlBuffer.getData(), max);

                pos += max;
                streamPos += static_cast<int64> (max);
                len -= max;

                if (removeSection)
                    curlBuffer.removeSection (0, max);
            }
        }

        return static_cast<int> (pos);
    }
Example #26
0
//espande la chiave
void expFunc(std::vector<unsigned> &keyArray, std::vector<unsigned> &expKeyArray){
	if ( keyArray.size()!=32 && keyArray.size()!=16 )
		throw std::string("expFunc: key array of wrong dimension");
	if ( expKeyArray.size()!=240 && expKeyArray.size()!=176 )
		throw std::string("expFunc: expanded key array of wrong dimension");

	copy(keyArray.begin(), keyArray.end(), expKeyArray.begin());

	unsigned cycles = (expKeyArray.size()!=240) ? 11 : 8;

	for (unsigned i=1; i<cycles; ++i){
		singleStep(expKeyArray, i);
	}
}
Example #27
0
void
QvisOpacitySlider::wheelEvent(QWheelEvent * e)
{
    static float offset = 0;
    static QvisOpacitySlider* offset_owner = 0;
    if(offset_owner != this)
    {
        offset_owner = this;
        offset = 0;
    }
    offset += -e->delta()*qMax(pageStep(),singleStep())/120;
    if(qAbs(offset)<1)
        return;
    setValue( value() + int(offset) );
    offset -= int(offset);
}
int Gui::InputField::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QLineEdit::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 6)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 6;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QByteArray*>(_v) = paramGrpPath(); break;
        case 1: *reinterpret_cast< double*>(_v) = singleStep(); break;
        case 2: *reinterpret_cast< double*>(_v) = maximum(); break;
        case 3: *reinterpret_cast< double*>(_v) = minimum(); break;
        case 4: *reinterpret_cast< int*>(_v) = historySize(); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setParamGrpPath(*reinterpret_cast< QByteArray*>(_v)); break;
        case 1: setSingleStep(*reinterpret_cast< double*>(_v)); break;
        case 2: setMaximum(*reinterpret_cast< double*>(_v)); break;
        case 3: setMinimum(*reinterpret_cast< double*>(_v)); break;
        case 4: setHistorySize(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 5;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #29
0
void ZoomSlider::paintEvent(QPaintEvent *ev) {
    // adapted from QCommonStyle::drawComplexControl case CC_Slider
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    int thickness = style()->pixelMetric(QStyle::PM_SliderControlThickness, &opt, this);
    int len = style()->pixelMetric(QStyle::PM_SliderLength, &opt, this);
    int available = style()->pixelMetric(QStyle::PM_SliderSpaceAvailable, &opt, this);
    int interval = opt.tickInterval;
    if (interval <= 0) {
        interval = singleStep();
        if (QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, interval, available)
            - QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, 0, available) < 3)
            interval = opt.pageStep;
    }
    if (!interval) {
        interval = 1;
    }
    int fudge = len / 2;
    int pos;
    // Since there is no subrect for tickmarks do a translation here.
    QPainter painter(this);
    painter.save();
    painter.translate(opt.rect.x(), opt.rect.y());
    painter.setFont(QFont(painter.font().family(), 8 * devicePixelRatio()));
    painter.setPen(opt.palette.foreground().color());
    int v = opt.minimum;
    int drawnTicks = 0;
    while (v <= opt.maximum + 1 && drawnTicks < numTicks) {
        if (v == opt.maximum + 1 && interval == 1) {
            break;
        }
        QString label = QString::number(highestMag / std::pow(2, drawnTicks));
        drawnTicks++;
        const int v_ = qMin(v, opt.maximum);
        pos = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, v_, available) + fudge;
        painter.drawLine(pos, thickness / 2, pos,  thickness);
        painter.drawText(pos + interval/2 - QFontMetrics(painter.font()).width(label) / 2., thickness, label);
        // in the case where maximum is max int
        int nextInterval = v + interval;
        if (nextInterval < v) {
            break;
        }
        v = nextInterval;
    }
    painter.restore();
    QSlider::paintEvent(ev);
}
Example #30
0
// Returns 1 if the event matched, 0 if it did not.
static int cosimStep(Core *core, uint32_t threadId)
{
	int count = 0;

	cosimError = false;
	cosimEventTriggered = false;
	for (count = 0; count < 500 && !cosimEventTriggered; count++)
		singleStep(core, threadId);

	if (!cosimEventTriggered)
	{
		printf("Simulator program in infinite loop? No event occurred.  Was expecting:\n");
		printCosimExpected();
	}
	
	return cosimEventTriggered && !cosimError;
}