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); }
void KoUnitDoubleSpinBox::setUnit( KoUnit unit ) { double oldvalue = d->unit.fromUserValue( QDoubleSpinBox::value() ); QDoubleSpinBox::setMinimum( unit.toUserValue( d->lowerInPoints ) ); QDoubleSpinBox::setMaximum( unit.toUserValue( d->upperInPoints ) ); QDoubleSpinBox::setSingleStep( unit.toUserValue( d->stepInPoints ) ); d->unit = unit; QDoubleSpinBox::setValue( KoUnit::ptToUnit( oldvalue, unit ) ); setSuffix( KoUnit::unitName( unit ).prepend( ' ' ) ); }
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; }
qreal KoUnit::convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } }
void KWApplicationConfig::setUnit(const KoUnit &unit) { KSharedConfigPtr config = KGlobal::config(); KConfigGroup misc = config->group("Misc"); misc.writeEntry("Units", unit.symbol()); misc.sync(); }
QDebug operator<<(QDebug debug, const KoUnit &unit) { #ifndef NDEBUG debug.nospace() << unit.symbol(); #else Q_UNUSED(unit); #endif return debug.space(); }
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; }
void MoveToolOptionsWidget::updateUIUnit(int newUnit) { const KoUnit selectedUnit = KoUnit::fromListForUi(newUnit); qreal valueForUI; if (selectedUnit != KoUnit(KoUnit::Pixel)) { spinMoveStep->setRange(0.0001, 10000.000); spinMoveStep->setSingleStep(.1); spinMoveStep->setDecimals(4); valueForUI = selectedUnit.toUserValue((qreal)m_moveStep / (qreal)m_resolution); } else { spinMoveStep->setRange(1, 10000); spinMoveStep->setSingleStep(1); spinMoveStep->setDecimals(0); valueForUI = m_moveStep; } spinMoveStep->blockSignals(true); spinMoveStep->setValue(valueForUI); spinMoveStep->blockSignals(false); }
ImageExportOptionsWidget::ImageExportOptionsWidget(QSizeF pointSize, QWidget * parent) : QWidget(parent), m_pointSize(pointSize) { KoUnit unit; widget.setupUi(this); widget.pxWidth->setRange(1, 10000); widget.pxWidth->setAlignment(Qt::AlignRight); widget.pxWidth->setSuffix(" px"); widget.pxHeight->setRange(1, 10000); widget.pxHeight->setAlignment(Qt::AlignRight); widget.pxHeight->setSuffix(" px"); widget.unitWidth->setMinMaxStep(0, 10000, 1); widget.unitHeight->setMinMaxStep(0, 10000, 1); widget.dpi->setRange(1, 10000); widget.dpi->setValue(KoDpi::dpiX()); widget.dpi->setAlignment(Qt::AlignRight); widget.dpi->setSuffix(" DPI"); widget.pxAspect->setKeepAspectRatio(true); widget.unitAspect->setKeepAspectRatio(true); widget.unit->addItems(KoUnit::listOfUnitNameForUi(KoUnit::HidePixel)); widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); widget.backColor->setColor(Qt::white); widget.opacity->setMinimum(0.0); widget.opacity->setMaximum(100.0); widget.opacity->setValue(0.0); widget.unitWidth->changeValue(pointSize.width()); widget.unitHeight->changeValue(pointSize.height()); updateFromPointSize(pointSize); connect(widget.unitWidth, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitWidthChanged(qreal))); connect(widget.unitHeight, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitHeightChanged(qreal))); connect(widget.pxWidth, SIGNAL(valueChanged(int)), this, SLOT(pxWidthChanged(int))); connect(widget.pxHeight, SIGNAL(valueChanged(int)), this, SLOT(pxHeightChanged(int))); connect(widget.dpi, SIGNAL(valueChanged(int)), this, SLOT(dpiChanged(int))); connect(widget.unit, SIGNAL(activated(int)), this, SLOT(unitChanged(int))); connect(widget.pxAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); connect(widget.unitAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); }
void KoPageLayoutWidget::setUnit(const KoUnit &unit) { if (d->unit == unit) return; d->unit = unit; d->widget.width->setUnit(unit); d->widget.height->setUnit(unit); d->widget.topMargin->setUnit(unit); d->widget.bottomMargin->setUnit(unit); d->widget.bindingEdgeMargin->setUnit(unit); d->widget.pageEdgeMargin->setUnit(unit); d->widget.units->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); emit unitChanged(d->unit); }
void ImageExportOptionsWidget::setUnit(const KoUnit &unit) { widget.unitWidth->setUnit(unit); widget.unitHeight->setUnit(unit); widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); }