Rewrote the Pan tool based on KisTool
ClosedPublic

Authored by victorw on Jun 16 2017, 10:05 PM.

Details

Summary

Rewrote and simplified the old Pan tool based on KisTool. Added some helper functions to KoCanvasController to make the code a bit cleaner.

This solves bug 365933 (Pan tool only).

Test Plan
  1. Select the pan tool
  2. Click and drag on the canvas
  3. Use arrow keys

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.
victorw created this revision.Jun 16 2017, 10:05 PM
victorw added inline comments.Jun 16 2017, 10:11 PM
plugins/tools/basictools/kis_tool_pan.h
33

Accidental leftover from testing some functions from KisTool. I'll remove Q_SLOTS.

victorw updated this revision to Diff 15511.Jun 17 2017, 9:04 AM
victorw marked an inline comment as done.

removed incorrect "public Q_SLOTS"

victorw added inline comments.Jun 18 2017, 12:26 PM
libs/flake/KoCanvasController.h
260

The old implementation of the pan tool had an implicit dependency on KoCanvasControllerWidget due to having to access the scrollbars. This removes that dependency.

There are other ways of providing this, but given there's only one use-case currently this felt cleanest. Another solution would be something like panDiscrete(int x, int y), though that can easily be added later if there is ever a need.

plugins/tools/basictools/kis_tool_pan.cpp
47

This avoids the pan bug the old implementation suffered from when mirroring is enabled. The old implementation used document coordinates for some reason, and then converted those to view coordinates. The problem with that is that panning is done on a widget level (despite what the docs say), so the view coordinates would be inverted from what the pan function expected.

Since we're only interested in delta cursor movement, we might as well use widget coordinates.

61

This is in keeping with the old behaviour, where panning via keys would track the scrollbars.

rempt accepted this revision.Jun 19 2017, 9:00 AM

The location of the new pan tool is wrong; apart from that, all is fine.

plugins/tools/basictools/kis_tool_pan.cpp
89

Hm... This probably isn't correct: now the pan tool is placed in the middle of the toolbar, instead of at the bottom, like it used to be.

This revision is now accepted and ready to land.Jun 19 2017, 9:00 AM

Hi, @victorw!

Did you do connect the arrow keys in reversed way intentionally? I would expect the right arrow key to move the canvas to the right and left arrow move it to the left. At least that is how most of the applications work... And in your patch it works in a reversed way. The arrows move the scrollbars instead.

victorw added a comment.EditedJun 19 2017, 6:36 PM

Hi, @victorw!

Did you do connect the arrow keys in reversed way intentionally? I would expect the right arrow key to move the canvas to the right and left arrow move it to the left. At least that is how most of the applications work... And in your patch it works in a reversed way. The arrows move the scrollbars instead.

Yes, it's intentional, though only because that's the current behaviour (both in master and 3.1.4). I thought it was a bit weird too, but I guess whoever originally wrote it wanted it to behave like the arrow keys in generic applications, i.e. they move the scrollbars... Then again, the original implementation wasn't Krita specific.

I'm in favour of changing it so it moves the canvas, but I have no strong opinion on the matter. Since this feels like a relatively minor thing, I'll change it if no one objects. :)

Edit: I updated the code to pan the canvas when you use the arrow keys. Arguably it makes more sense, but it's different from the old behaviour. If there are no objections I'll submit this version.

victorw added inline comments.Jun 19 2017, 6:41 PM
plugins/tools/basictools/kis_tool_pan.cpp
89

I can change the section. I only changed it because the comment for TOOL_TYPE_VIEW specifically says it's for "Tools that affect the canvas: pan, zoom, etc."

This section is also used by the measurement tool, which is in the same category. I don't mind either way though IMO it makes sense to group these type of tools. Should I change it back?

In D6245#117374, @rempt wrote:

The location of the new pan tool is wrong; apart from that, all is fine.

You mean the location in the toolbox, or the file?

victorw updated this revision to Diff 15603.Jun 19 2017, 7:46 PM
  • Inverted pan movement when using arrow keys. This is a change from the original behaviour, but could be considered more correct in the given context.
  • Switched section to the old section so the tool icon doesn't move in the toolbox.
victorw added inline comments.Jun 19 2017, 7:55 PM
plugins/tools/basictools/kis_tool_pan.cpp
89

I updated the code to use the old section (navigationToolType()). There seem to be some tech debt here as there are two definitions for sections. One is defined in KoToolFactoryBase.h and one is defined in kis_tool.h.

They should probably be unified, which would require taking inventory of all tools and creating new groups suitable for them. Maybe a future cleanup task?

dkazakov accepted this revision.Jun 20 2017, 11:18 AM

Hi, @victorw!

Now the patch looks perfectly correct! :)

You mean the location in the toolbox, or the file?

I think Boud meant the location of the button on the toolbox. The file is looks to be placed correctly.

plugins/tools/basictools/kis_tool_pan.cpp
89

Yes, that is an artifact of forking from old Calligra code. It might be a future task, yes. But since it still works and satisfies everyone, I wouldn't spend time on it. Next time when painters ask for the tools reordering, we can refactor it as well :)

This revision was automatically updated to reflect the committed changes.