Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/kis_double_parse_unit_spin_box.cpp
Show All 18 Lines | |||||
19 | #include "kis_double_parse_unit_spin_box.h" | 19 | #include "kis_double_parse_unit_spin_box.h" | ||
20 | #include "kis_spin_box_unit_manager.h" | 20 | #include "kis_spin_box_unit_manager.h" | ||
21 | 21 | | |||
22 | #include <QLineEdit> | 22 | #include <QLineEdit> | ||
23 | 23 | | |||
24 | class Q_DECL_HIDDEN KisDoubleParseUnitSpinBox::Private | 24 | class Q_DECL_HIDDEN KisDoubleParseUnitSpinBox::Private | ||
25 | { | 25 | { | ||
26 | public: | 26 | public: | ||
27 | Private(double low, double up, double step) | 27 | Private(double low, double up, double step, KisSpinBoxUnitManager* unitManager) | ||
28 | : lowerInPoints(low), | 28 | : lowerInPoints(low), | ||
29 | upperInPoints(up), | 29 | upperInPoints(up), | ||
30 | stepInPoints(step), | 30 | stepInPoints(step), | ||
31 | unit(KoUnit(KoUnit::Point)), | 31 | unit(KoUnit(KoUnit::Point)), | ||
32 | unitManager(new KisSpinBoxUnitManager()), | 32 | unitManager(unitManager), | ||
33 | defaultUnitManager(unitManager), | 33 | defaultUnitManager(unitManager), | ||
34 | isDeleting(false), | 34 | isDeleting(false), | ||
35 | unitHasBeenChangedFromOutSideOnce(false), | 35 | unitHasBeenChangedFromOutSideOnce(false), | ||
36 | letUnitBeChangedFromOutsideMoreThanOnce(true) | 36 | letUnitBeChangedFromOutsideMoreThanOnce(true) | ||
37 | { | 37 | { | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | double lowerInPoints; ///< lowest value in points | 40 | double lowerInPoints; ///< lowest value in points | ||
41 | double upperInPoints; ///< highest value in points | 41 | double upperInPoints; ///< highest value in points | ||
42 | double stepInPoints; ///< step in points | 42 | double stepInPoints; ///< step in points | ||
43 | KoUnit unit; | 43 | KoUnit unit; | ||
44 | 44 | | |||
45 | KisSpinBoxUnitManager* unitManager; //manage more units than permitted by KoUnit. | 45 | KisSpinBoxUnitManager* unitManager; //manage more units than permitted by KoUnit. | ||
46 | KisSpinBoxUnitManager* defaultUnitManager; //the default unit manager is the one the spinbox rely on and go back to if a connected unit manager is destroyed before the spinbox. | 46 | KisSpinBoxUnitManager* defaultUnitManager; //the default unit manager is the one the spinbox rely on and go back to if a connected unit manager is destroyed before the spinbox. | ||
47 | 47 | | |||
48 | bool isDeleting; | 48 | bool isDeleting; | ||
49 | 49 | | |||
50 | bool unitHasBeenChangedFromOutSideOnce; //in some part of the code the unit is reset. We want to prevent this overriding the unit defined by the user. We use this switch to do so. | 50 | bool unitHasBeenChangedFromOutSideOnce; //in some part of the code the unit is reset. We want to prevent this overriding the unit defined by the user. We use this switch to do so. | ||
51 | bool letUnitBeChangedFromOutsideMoreThanOnce; | 51 | bool letUnitBeChangedFromOutsideMoreThanOnce; | ||
52 | 52 | | |||
53 | }; | 53 | }; | ||
54 | 54 | | |||
55 | KisDoubleParseUnitSpinBox::KisDoubleParseUnitSpinBox(QWidget *parent) : | 55 | KisDoubleParseUnitSpinBox::KisDoubleParseUnitSpinBox(QWidget *parent) : | ||
56 | KisDoubleParseSpinBox(parent), | 56 | KisDoubleParseSpinBox(parent), | ||
57 | d(new Private(-9999, 9999, 1)) | 57 | d(new Private(-9999, 9999, 1, KisSpinBoxUnitManagerFactory::buildDefaultUnitManager(this))) | ||
58 | { | 58 | { | ||
59 | setUnit( KoUnit(KoUnit::Point) ); | 59 | setUnit( KoUnit(KoUnit::Point) ); | ||
60 | setAlignment( Qt::AlignRight ); | 60 | setAlignment( Qt::AlignRight ); | ||
61 | 61 | | |||
62 | connect(this, SIGNAL(valueChanged( double )), SLOT(privateValueChanged())); | 62 | connect(this, SIGNAL(valueChanged( double )), SLOT(privateValueChanged())); | ||
63 | connect(lineEdit(), SIGNAL(textChanged(QString)), | 63 | connect(lineEdit(), SIGNAL(textChanged(QString)), | ||
64 | this, SLOT(detectUnitChanges()) ); | 64 | this, SLOT(detectUnitChanges()) ); | ||
65 | 65 | | |||
66 | 66 | | |||
67 | | ||||
68 | | ||||
67 | } | 69 | } | ||
68 | 70 | | |||
69 | KisDoubleParseUnitSpinBox::~KisDoubleParseUnitSpinBox() | 71 | KisDoubleParseUnitSpinBox::~KisDoubleParseUnitSpinBox() | ||
70 | { | 72 | { | ||
71 | d->isDeleting = true; | 73 | d->isDeleting = true; | ||
72 | delete d->defaultUnitManager; | 74 | delete d->defaultUnitManager; | ||
73 | delete d; | 75 | delete d; | ||
74 | } | 76 | } | ||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Line(s) | |||||
312 | void KisDoubleParseUnitSpinBox::detectUnitChanges() | 314 | void KisDoubleParseUnitSpinBox::detectUnitChanges() | ||
313 | { | 315 | { | ||
314 | QString unitSymb = detectUnit(); | 316 | QString unitSymb = detectUnit(); | ||
315 | 317 | | |||
316 | if (unitSymb.isEmpty()) { | 318 | if (unitSymb.isEmpty()) { | ||
317 | return; | 319 | return; | ||
318 | } | 320 | } | ||
319 | 321 | | |||
322 | QString oldUnitSymb = d->unitManager->getApparentUnitSymbol(); | ||||
323 | | ||||
320 | setUnit(unitSymb); | 324 | setUnit(unitSymb); | ||
321 | setValue(valueFromText(cleanText())); //change value keep the old value, but converted to new unit... which is different from the value the user entered in the new unit. So we need to set the new value. | 325 | setValue(valueFromText(cleanText())); //change value keep the old value, but converted to new unit... which is different from the value the user entered in the new unit. So we need to set the new value. | ||
326 | | ||||
327 | if (oldUnitSymb != d->unitManager->getApparentUnitSymbol()) { | ||||
328 | // the user has changed the unit, so we block changes from outside. | ||||
329 | setUnitChangeFromOutsideBehavior(false); | ||||
330 | } | ||||
322 | } | 331 | } | ||
323 | 332 | | |||
324 | QString KisDoubleParseUnitSpinBox::makeTextClean(QString const& txt) const | 333 | QString KisDoubleParseUnitSpinBox::makeTextClean(QString const& txt) const | ||
325 | { | 334 | { | ||
326 | QString expr = txt; | 335 | QString expr = txt; | ||
327 | QString symbol = d->unitManager->getApparentUnitSymbol(); | 336 | QString symbol = d->unitManager->getApparentUnitSymbol(); | ||
328 | 337 | | |||
329 | if ( expr.endsWith(suffix()) ) { | 338 | if ( expr.endsWith(suffix()) ) { | ||
Show All 19 Lines |