void MoveToolOptionsWidget::on_spinMoveStep_valueChanged(double UIMoveStep)
{
    const KoUnit selectedUnit = KoUnit::fromListForUi(m_moveStepUnit);
    const double scaledUiMoveStep = (selectedUnit == KoUnit(KoUnit::Pixel)) ?
      UIMoveStep : selectedUnit.fromUserValue(UIMoveStep * m_resolution);
    m_moveStep = qRound(scaledUiMoveStep);
    m_configGroup.writeEntry("moveToolStep", m_moveStep);
}
Example #2
0
QValidator::State KoUnitDoubleSpinBox::validate(QString &input, int &pos) const
{
#ifdef DEBUG_VALIDATOR
    kDebug(30004) <<"KoUnitDoubleSpinBox::validate :" << input <<" at" << pos;
#else
    Q_UNUSED(pos);
#endif

    QRegExp regexp ("([ a-zA-Z]+)$"); // Letters or spaces at end
    const int res = input.indexOf( regexp );

    if ( res == -1 )
    {
        // Nothing like an unit? The user is probably editing the unit
#ifdef DEBUG_VALIDATOR
        kDebug(30004) <<"Intermediate (no unit)";
#endif
        return QValidator::Intermediate;
    }

    // ### TODO: are all the QString::trimmed really necessary?
    const QString number ( input.left( res ).trimmed() );
    const QString unitName ( regexp.cap( 1 ).trimmed().toLower() );

#ifdef DEBUG_VALIDATOR
    kDebug(30004) <<"Split:" << number <<":" << unitName <<":";
#endif

    const double value = valueFromText( number );
    double newVal = 0.0;
    if( value != NAN )
    {
        bool ok;
        KoUnit unit = KoUnit::unit( unitName, &ok );
        if ( ok )
            newVal = unit.fromUserValue( value );
        else
        {
            // Probably the user is trying to edit the unit
#ifdef DEBUG_VALIDATOR
            kDebug(30004) <<"Intermediate (unknown unit)";
#endif
            return QValidator::Intermediate;
        }
    }
    else
    {
        kWarning(30004) << "Not a number: " << number;
        return QValidator::Invalid;
    }
    newVal = KoUnit::ptToUnit( newVal, d->unit );
    //input = textFromValue( newVal ); // don't overwrite for now; the effect is not exactly what I expect...

    return QValidator::Acceptable;
}
Example #3
0
qreal KoUnit::parseValue(const QString& _value, qreal defaultVal)
{
    if (_value.isEmpty())
        return defaultVal;

    QString value(_value.simplified());
    value.remove(QLatin1Char(' '));

    int firstLetter = -1;
    for (int i = 0; i < value.length(); ++i) {
        if (value.at(i).isLetter()) {
            if (value.at(i) == QLatin1Char('e'))
                continue;
            firstLetter = i;
            break;
        }
    }

    if (firstLetter == -1)
        return value.toDouble();

    const QString symbol = value.mid(firstLetter);
    value.truncate(firstLetter);
    const qreal val = value.toDouble();

    if (symbol == QLatin1String("pt"))
        return val;

    bool ok;
    KoUnit u = KoUnit::fromSymbol(symbol, &ok);
    if (ok)
        return u.fromUserValue(val);

    if (symbol == QLatin1String("m"))
        return DM_TO_POINT(val * 10.0);
    else if (symbol == QLatin1String("km"))
        return DM_TO_POINT(val * 10000.0);
    warnOdf << "KoUnit::parseValue: Unit " << symbol << " is not supported, please report.";

    // TODO : add support for mi/ft ?
    return defaultVal;
}