Allow the user to change the active unit in the KisDoubleParseUnitSpinBoxes. I'm not sure it's worth merging now, but I want to get sure the design I choosed is not problematic. Ref T1621
ClosedPublic

Authored by jospin on Sep 14 2016, 10:18 AM.

Details

Summary

The main change, is the new class KisSpinBoxUnitManager. This is an abstract interface to let the spinboxes use different sorts of units from KoUnit, but also document relative lenght units (vw, vh), angle units and time units.

This force some little tricks in the design, since the spinboxes must stay in the widget library, but a lot of needed info for relative units can't be acessed from this library.

So the idea is to subclass the KisSpinBoxUnitManager where it can acess thoses datas, then send a pointer to the spinboxes. With polymorphism we can make all of this work.

So now it's possible to change the unit by writing the symbol of this unit at the end of a KisDoubleParseUnitSpinBox.

There's a few problem left, for example in some places the spinbox is destroyed and rebuilt everytime the user want to use it, so the active unit is not kept.

There's also a few refactoring needed in a lot of places that use simple parse spinboxes with a suffix rather than unit spinbox.

Test Plan

Activate all Karbon tool in your kritarc (not needed, But I've checked it works with them too).

Launch krita

Create a new document

Create a new vector layer (the unit spinbox is used essentially for Karbon tools for the moment).

You can try the freehand path and draw path karbon tool, set a size in any unit you want and start to draw.

Then you can use the default tool (moving, resizing objects, setting a shadow). In all thoses steps you can use units like mm, cm, pt, ... but also px, vw, vh).

Finally open the add shape and shape propeties docker. Add a few shapes and try to change the properties. deselect the shape reselect if, you'll found that the unit is reset to px (the spin box has been destroyed, then recreated).
(I had a lots of problem with this docker, it needs a few refactoring to work with the new spinboxes).

Close krita and check there's not segfault caused by the patch (I had this problem a few time, and had to find way to prevent it).

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jospin updated this revision to Diff 6723.Sep 14 2016, 10:18 AM
jospin retitled this revision from to Allow the user to change the active unit in the KisDoubleParseUnitSpinBoxes. I'm not sure it's worth merging now, but I want to get sure the design I choosed is not problematic. Ref T1621.
jospin updated this object.
jospin edited the test plan for this revision. (Show Details)
jospin added reviewers: Krita, dkazakov.
jospin added a subscriber: rempt.
dkazakov edited edge metadata.Sep 17 2016, 5:45 AM

I'm not sure I'll be able to test more during the weekend. I guess at least the two things should be fixed until we can let the users to use it:

  1. Make it really translatable: units + separators. What is more, the user should be able to use both versions: localized and C.
  2. Make Size Canvas, Scale Canvas, Crop Tool support this feature. These are the tools that are the most expected to have units in them.
libs/ui/utils/kis_document_aware_spin_box_unit_manager.cpp
101

The symbols should be translatable. What is more, the user should be able to write in both variants: english and localized versions of the units. Just to avoid switching languages. The same applies to ',' and '.' decimal separators

Do you have any reference about internationalized units abrevations, I found nothing on google (not sure I search correctly). Anyway, are you sure it's needed to internationalized that ? It may makes the doc overcomplicated no ?

I think what dmitry means is that there might be alternative scripts for units. So centimeter in cyrilic and chinese, that type of stuff :)

Yes, I just mean that the abbreviations should handle local languages as well. It means that I should be able to write

15mm <-> 15мм
20 cm <-> 20 см
10 px <-> 10 пикс

The same applies to the decimal separator, the following numbers should be the same:

10.5 cm <-> 10,5 cm

Yes, but I did not found any example of how thoses abreviation are translated,

I just want to check if there's some particularity to take into account, or if I can just compare the suffix to both the internationalized and untranslated strings.

In D2771#52337, @jospin wrote:

Yes, but I did not found any example of how thoses abreviation are translated,

I just want to check if there's some particularity to take into account, or if I can just compare the suffix to both the internationalized and untranslated strings.

The only difficulty here is decimal separator, because it is not translatable with i18n(). You can use QLocale or something to fetch that. And for the suffixes, I guess it is enough just to compare to both variants.

As far as I know, the best example of such translation is AutoCad :)

This revision was automatically updated to reflect the committed changes.