10#include <klocalizedstring.h>
16 static QString str = i18n(
"Percent (%)");
58 QString pUnitSymbol =
"pt",
61 unitSymbol(pUnitSymbol),
62 conversionFactor(pConv)
71 bool conversionFactorIsFixed {
true};
72 mutable double conversionConstant {0};
73 bool conversionConstantIsFixed {
true};
78 mutable bool unitListCached {
false};
81 mutable bool unitListWithNameCached {
false};
84 bool hasHundredPercent {
false};
85 qreal hundredPercent {0};
87 bool canAccessDocument {
false};
115 return d->unitSymbol;
121 return list.indexOf(
d->unitSymbol);
129 if (
d->unitSymbol ==
"px") {
135 if (
d->unitSymbol ==
"px") {
153 if (
d->unitListWithNameCached) {
154 return d->unitListWithName;
157 if (
d->unitListCached) {
189 if (
d->canAccessDocument) {
218 if (
d->canAccessDocument) {
221 list << i18n(
"percent of view width (vw)") << i18n(
"percent of view height (vh)");
223 list <<
"vw" <<
"vh";
231 list << i18n(
"degrees (°)") << i18n(
"radians (rad)") << i18n(
"gons (gon)") << i18n(
"percent of circle (%)");
233 list <<
"°" <<
"rad" <<
"gon" <<
"%";
240 list << i18n(
"frames (f)");
245 if (
d->canAccessDocument) {
247 list << i18n(
"seconds (s)") << i18n(
"percent of animation (%)");
258 d->unitListWithName = list;
259 d->unitListWithNameCached =
true;
262 d->unitListCached =
true;
279 if (!
d->conversionFactorIsFixed) {
283 if(!
d->conversionConstantIsFixed) {
298 if (parent == QModelIndex()) {
306 if (
role == Qt::DisplayRole) {
310 }
else if (
role == Qt::ToolTipRole) {
321 if (!
d->conversionFactorIsFixed) {
325 if(!
d->conversionConstantIsFixed) {
347 if (symbol ==
"px") {
361 if (symbol ==
"px") {
371 if (symbol ==
"rad") {
372 factor =
acos(-1)/90.0;
375 if (symbol ==
"gon") {
403 if (dimension ==
d->dim) {
409 d->conversionFactor = 1.0;
418 QString symbol =
pSymbol.trimmed();
420 if (symbol ==
d->unitSymbol) {
431 if (symbol.toLower() ==
"deg") {
440 if (list.contains(symbol, Qt::CaseInsensitive)) {
441 for (QString
str : list) {
442 if (
str.toLower() == symbol.toLower()) {
456 if (
d->canAccessDocument) {
479 d->conversionFactorIsFixed =
true;
484 d->conversionFactorIsFixed =
false;
488 d->conversionFactorIsFixed =
true;
492 if (
d->dim ==
TIME) {
494 d->conversionConstantIsFixed =
false;
497 d->conversionConstantIsFixed =
true;
515 if (index >= 0 && index <
rowCount()) {
524 if (
d->connectedUnitManagers.indexOf(
other) >= 0) {
534 d->connectedUnitManagers.append(
other);
543 int id =
d->connectedUnitManagers.indexOf(
other);
552 d->connectedUnitManagers.removeAt(
id);
571 return d->canAccessDocument;
583 if (
d->conversionFactorIsFixed) {
598 if (
d->conversionConstantIsFixed) {
613 d->canAccessDocument =
true;
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisSpinBoxUnitManagerBuilder class is the base class, used in the strategy pattern of KisSpinBoxU...
virtual KisSpinBoxUnitManager * buildUnitManager(QObject *parent)=0
static void clearUnitManagerBuilder()
static KisSpinBoxUnitManager * buildDefaultUnitManager(QObject *parent)
static KisSpinBoxUnitManagerBuilder * builder
static void setDefaultUnitManagerBuilder(KisSpinBoxUnitManagerBuilder *pBuilder)
set a builder the factory can use. The factory should take on the lifecycle of the builder,...
The KisSpinBoxUnitManager class is an abstract interface for the unitspinboxes classes to manage diff...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QStringList unitListWithName
void unitDimensionChanged(int dimCode)
int getUnitDimensionType() const
KisSpinBoxUnitManager(QObject *parent=0)
virtual qreal getConversionConstant(int dim, QString symbol) const
some units conversions are done via an affine transform, not just a linear transform....
void setApparentUnitFromSymbol(QString pSymbol)
static const QStringList documentRelativeLengthUnitSymbols
void syncWithOtherUnitManager(KisSpinBoxUnitManager *other)
void newUnitSymbolToUnitIndex(QString symbol)
convert a unitChanged signal with a QString to one with an index.
virtual qreal getConversionFactor(int dim, QString symbol) const
gets the conversion factor of a managed unit, or -1 in case of error. This method is the one that nee...
int getApparentUnitRecommendedDecimals() const
get a hint of how many decimals the spinbox needs to display.
void selectApparentUnitFromIndex(int index)
void recomputeConversionFactor() const
~KisSpinBoxUnitManager() override
void setUnitDimension(UnitDimension dimension)
KisSpinBoxUnitManager::UnitDimension dim
Private(KisSpinBoxUnitManager::UnitDimension pDim=KisSpinBoxUnitManager::LENGTH, QString pUnitSymbol="pt", double pConv=1.0)
void conversionFactorChanged(qreal newConversionFactor, qreal oldConversionFactor) const
void grantDocumentRelativeUnits()
calling this method gives access to document relative units. Only subclasses that manage those units ...
void conversionConstantChanged(qreal newConversionFactor, qreal oldConversionFactor) const
qreal getApparentValue(double refValue) const
static const QStringList referenceUnitSymbols
this list holds the symbols of the reference unit per dimension. The index is equal to the value in U...
qreal getReferenceValue(double apparentValue) const
static const QStringList documentRelativeTimeUnitSymbols
void clearSyncWithOtherUnitManager(KisSpinBoxUnitManager *other)
QVector< KisSpinBoxUnitManager * > connectedUnitManagers
void recomputeConversionConstant() const
virtual bool hasPercent(int unitDim) const
indicate if the unit manager has some kind of way of using a percent unit, used by the main class to ...
int getApparentUnitId() const
get the position of the apparent unit in the list of units. It is useful if we want to build a model ...
QString getApparentUnitSymbol() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QString getReferenceUnitSymbol() const
virtual QStringList getsUnitSymbolList(bool withName=false) const
void unitChanged(QString symbol)
static QString unitDescription(KoUnit::Type type)
Get the description string of the given unit.
qreal toUserValuePrecise(const qreal ptValue) const
static KoUnit fromSymbol(const QString &symbol, bool *ok=0)
QString symbol() const
Get the symbol string of the unit.
static QString percentStr()