Skip to content

KisDoubleParseUnitSpinBox improvements

Grum 999 requested to merge grum/krita:grum999/KisDoubleParseUnitSpinBox into master

With this MR, some small improvements are made for KisDoubleParseUnitSpinBox.

Small bug about unit change

First, there's a small bug fixed related to decimals and rounding values.

Example:
KisDoubleParseUnitSpinBox_KO

  • Document @300DPI
  • Size = 300.00px
  • Change unit to mm => 25.40mm
  • Change unit back to px => 300px
  • Change unit to mm => 25.00mm instead of 25.40mm

The problem was related to setDecimals() that apply the most appropriate decimal value according to unit.
For pixels, it's 0.
Then we can see in video, initialy it's 300.00px (2 decimals because setDecimals() was hard-coded in UI init) and after it's 300px (zero decimals, because unit manager apply the best decimal value).

The fix consists, when the unit is changed to set the number of decimals (for new unit) before the conversion to new unit is made; this avoid invalid round value.

Ensure step value is valid

When unit is changed, internally the step value is recalculated (from internal "Pt" value to apparent value).

In some case, the step value was equal to zero.

The setSingleStep() is improved to ensure, when unit is changed, the step value is always greater or equal to the value for precision
Examples:

  • decimals = 0, step value can't be lower than 1
  • decimals = 1, step value can't be lower than 0.1
  • decimals = 2, step value can't be lower than 0.01
  • decimals = 3, step value can't be lower than 0.001

New methods

To be consistent with existing methods setLineStep() / setLineStepPt(), the same has been implemented for:

  • setMinimum() / setMinimumPt()
  • setMaximum() / setMaximumPt()
  • setMinMaxStep() / setMinMaxStepPt()
  • changeValue() / changeValuePt()
  • value() / valuePt()

Context menu - add unit

In some UI widgets, there's an associated combobox to input field, allowing to change & convert unit.

For (design) reason, the combobox is not always provided.
Then, to allow user being able to convert value from current unit to another one, a context menu has been added (manage units from unit manager linked to KisDoubleParseUnitSpinBox)

image

Update UI

All widgets/UI using a KisDoubleParseUnitSpinBox have been checked and:

  • If there was no reason to get decimals values on pixel unit, hard-coded "2 decimals" has been removed (let the unit manager update the number of decimals)
  • If decimals is really expected for pixels, hard-coded "2 decimals" has been kept/added and use of preventDecimalsChangeFromUnitManager() applied to ensure the unit manager don't update the number of decimals
  • The KisAspectRatioLocker has been updated too, ensure both connected KisDoubleParseUnitSpinBox to always communicate with the same unit (Pt) whatever the return unit is set to

Test Plan

To test the context menu, just go in any KisDoubleParseUnitSpinBox and right click:

  • get the context menu updated, with the right selected item (checkbox) in menu
  • select any unit, the input field is updated (unit + converted display value)

To test problem with decimals

  • Create a document 300x300 pixels, @300DPI
  • Go to "Resize canvas"
  • Change unit to mm => 25.40mm
  • Change unit back to px => 300px
  • Change unit to mm => 25.40mm (and not 25.00mm like it was before bug fix)

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
  • Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.

Edited by Grum 999

Merge request reports

Loading