Make Layer Docker's tree indentation adjustable
The request to lower the tree indentation of the layer docker seems to come up regularly (BUG:438457, Krita-Artists example 1, example 2) so I finally decided to give it a try.
Warning: long lamentation ahead
This was a bit of an odyssey.
It should've been an afternoon experiment but the existing code made it impossible for me to change anything without breaking everything.
The reason is that the NodeView makes it look like the visibility icons is its own column left of the tree, while the model only has a single column, so it had to trick QTreeView in many (fragile) ways. Then I started making it a proper column, only to later find out that it already had been just like that years ago. Dmitry changed that in early 2016, without naming a specific reason, and probably doesn't know it anymore either because in 2020 he wrote:
Perhaps we could refactor our code and use "columns" feature of the tree view instead of rendering everything in one column. But I have a feeling that I tried this approach when rewriting the docker the last time, and it didn't work for some reason.
Anyway, I didn't encounter any unsolvable issue, and am not willing to spend more time on forensics. While examining the current behavior, I noticed that in nested groups, clicking the thumbnail would collapse/expand the group, because that's where QTreeView expects the branch joint. The hacks also don't quite work with right-to-left layout, depending on thumbnail size, the visibility icons are cut off.
These quirks are gone, but a small one remains. For some reason, QTreeView starts a drag action even on columns that can't be selected, so you can (sometimes) start dragging on a visibility icon. I have some idea how it could be solved, but there's still a layer of overrides on viewport events. I'd need to try to remove that first, and study the details of QTreeView some more.
The actual change for users
So, I just added a second slider below that lonely "Thumbnail Size" slider in the option menu. It sets the indentation relative to the thumbnail size, ranging from 20% to 100% (with a minimum of 8 pixels).
A comparison of the old 100% and 50%:
And if you look closely, it also removes some excess branch lines. Below the "skin" group (that is nested in a "character" group you can't see here) there are no more siblings, yet the old code drew more branch segments.
I also optimized the rendering a bit, but the main difference would come from removing the hack that essentially drew everything twice because the delegate needed to paint outside the rect provided by QTreeView.
Test Plan
Use the layer docker as hard as you can, I guess...try all the actions on the layer view that you can think of.
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.