Add selection support for already taken screenshots
Needs ReviewPublic

Authored by czeidler on May 9 2020, 9:50 AM.

Details

Reviewers
davidre
meven
Group Reviewers
Spectacle
Summary

Motivation: Arguably, the usual flow to take a screenshot is to simply press the screenshot button. When only a selection of the so taken screenshot is needed I found it not very intuitive to select a different capture mode and take another screenshot. Personally, I always went through the round trip of using an external image editor to select a smaller part of the screenshot. Beside taking a second screenshot is often an unnecessary step, in the worst case the screen that needed to be captured has changed, e.g. a video.

This patch allows users to select a rectangular section of a screenshot from the KSImageWidget. The selection can be exported as usual, i.e. drag and drop, copied to clipboard or saved.

KSImageWidget is now zoomable (ctrl + mouse wheel) and movable (ctrl + left button or middle button). This is useful to do exact selections. However, the magnifier from the rectangular capture mode is still available. To start a new selection region a new UI button has been added. Selection can be cancelled by clicking outside of the selection rect.

Implementation details: For the new selection mode the code from the QuickEditor widget is reused. This is done by first moving most code (mostly unchanged) from QuickEditor to a QGraphicsObject (for easier zooming, scaling, translating of the scene). This QGraphicsObject is then used in KSImageWidget as well in the original QuickEditor. For this to work some code for correct scaling of the UI elements was added. Furthermore, some parameters of the QuickEditor are now changeable programmatically, for example to disable unneeded help text.

Diff Detail

Repository
R166 Spectacle
Branch
post-screenshot-selection (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 26687
Build 26705: arc lint + arc unit
czeidler created this revision.May 9 2020, 9:50 AM
Restricted Application added a project: Spectacle. · View Herald TranscriptMay 9 2020, 9:50 AM
Restricted Application added a subscriber: Spectacle. · View Herald Transcript
czeidler requested review of this revision.May 9 2020, 9:50 AM

Very cool! However I can't seem to figure out a way to select a selection.
How do you think does this relate to D22074? Maybe we can integrate both patches somehow?

czeidler added a comment.EditedMay 11 2020, 8:36 AM

There should be a 'Select' button on the right side of the window (see below). Once you click it you can start a selection. During the time of the first selection the button is disabled. Happy to get feedback for the button location, label or better position.

Didn't know about D22074 but looks cool and useful. Had a quick look at the code and if I get it right it simply swaps out the whole KSWidget layout with the external KImageAnnotator widget. So that should make it easy to work together with my patch.

I guess once a selection has been done the annotation tool should work on this selection. This is not a problem because I changed the ExportManager to only return the selection. However, we probably need to consider cases where the selection is very small and the annotator has not enough space to be useful... Apart from making both patches compile together I don't seen any problems.

Ah I see, the select button will change the pixmap what is saved/copied but not the displayed one?

Yes thats correct. That makes it possible to save multiple different selections from the same screenshot... Maybe I should make it more clear that only the selection is saved, or is that clear? However, when dragging the selection only the selected part is visible in the drag image.

czeidler updated this revision to Diff 82499.May 11 2020, 9:19 AM
  • Fix KSImageWidget cursor when there is no selection
  • Send out a selectionChanged event when selection is cleared
ngraham edited reviewers, added: Spectacle, meven; removed: bgupta.May 12 2020, 4:22 PM
meven added a comment.May 12 2020, 6:13 PM

That's a nice feature.

This is going to conflict with D29282 :/

Do you see fundamental problems combining both patches? e.g. in the KSImageWidget the mScreenRegion could simply be a single rectangle of the size of the screenshot pixmap?

Or some other option to reuse the drawing and user interaction from QuickEditor?

meven added a comment.May 13 2020, 7:47 AM

Do you see fundamental problems combining both patches? e.g. in the KSImageWidget the mScreenRegion could simply be a single rectangle of the size of the screenshot pixmap?

Fundamentally no, the other patch essentially rewrites QuickEditor::paintEvent to support Wayland per-screen scaling/dpr.
The full screen rectangular selection and the in-KSImageWidget would need to have separate paint functions essentially.

But since this patch moves files around this alone introduce a lot of rework in my branch should my patch land after yours.

I had another thought on it and think having all the functionality for both cases in one class is probably a bit too big and both use cases are actually too different. The common part that can be shared between both cases is the selectable rectangle + the magnifier. I think all other functionality / logic should go into QuickEditor and KSImageWidget respectively. I am wondering if that is an option, i.e. refactor a selection primitive to select a rectangular area (possibly implemented as QGraphicsObject). I assume that's what you need as well, right? i.e. you want a rectangular selection rather than a region? We could make this new selection class customizable with an isValidSelection hook / lambda so that in your case you can reject selections that are invalid. (correct me if you need something different, I am still not 100% sure if I understood your problem right, if you have a screenshot of a distorted / problematic screen that would be great!)