Let window size depend on the screenshot aspect ratio
ClosedPublic

Authored by anemeth on Feb 7 2018, 11:54 PM.

Details

Summary

Now the window width size changes with the aspect ratio of the captured image.
Maximum width is 1000 pixels for this automatic resize.

Test Plan

Diff Detail

Repository
R166 Spectacle
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
anemeth requested review of this revision.Feb 7 2018, 11:54 PM
anemeth created this revision.
anemeth edited the summary of this revision. (Show Details)Feb 8 2018, 12:02 AM
anemeth edited the test plan for this revision. (Show Details)
anemeth added reviewers: ngraham, Spectacle.
anemeth added a project: Spectacle.
anemeth added a subscriber: ngraham.

Something went wrong the diff creation and my local version is out of date too.
I'll fix it soon.

anemeth updated this revision to Diff 26737.Feb 8 2018, 12:21 AM

Updated base and fixed my old code

Tested it out. This is radically better than what we had before, thanks for the excellent work! Just a few niggles. Also, in the previous patch, I think you further reduced the padding to the right of the right column in order to not have to increase the minimum width so much, which I would approve of doing here.

src/Gui/KSImageWidget.cpp
28

Unrelated change?

src/Gui/KSImageWidget.h
63

Unrelated change?

src/Gui/KSMainWindow.cpp
49

1000 seems a bit high for a default, no?

anemeth added inline comments.Feb 8 2018, 2:35 AM
src/Gui/KSImageWidget.cpp
28

See my answer for your other comment for line 62 in KSImageWidget.h

src/Gui/KSImageWidget.h
63

Absolutely not unrelated.
This is not THAT blur :)
This is for the 5 pixel wide shadow around the image.
It just happens that it's called blur radius.

See mDSEffect->setBlurRadius on line 29 of KSImageWidget.cpp. This was here before this change.
We need this variable because we want to access the shadow (blur) radius in a different class for calculating the window size.

src/Gui/KSMainWindow.cpp
49

The window size gets overriden by setScreenshotAndShow() as soon we get a picture, which is basically the case every time we open Spectacle. There may be a case where spectacle opens without capturing an image first (maybe with an argument?) but that very rarely happens.
Also this value is used as maximum auto resize width.
Should I change it to MAXIMUM_WINDOW_WIDTH and add a DEFAULT_WINDOW_WIDTH with a lower value?

anemeth added a comment.EditedFeb 8 2018, 2:43 AM

Also, in the previous patch, I think you further reduced the padding to the right of the right column in order to not have to increase the minimum width so much, which I would approve of doing here.

It is included here too.
See line 150 and 151 of KSWidget.cpp where I changed the minimum width from 400 to 320 pixels.

Also I hope my work gets to appear in your blog again. Part 5 maybe? :)

ngraham accepted this revision.Feb 8 2018, 3:29 AM
ngraham added a subscriber: rkflx.

My mistake about everything, looks good. Works great, too. I love this. If you don't want to wait for @rkflx's review before committing, you'll have to promise to address any of his requests in a follow-up patch. :)

Also I hope my work gets to appear in your blog again. Part 5 maybe? :)

I think that's a given!

This revision is now accepted and ready to land.Feb 8 2018, 3:29 AM
anemeth marked 4 inline comments as done.Feb 8 2018, 10:48 AM

I think I'll wait for @rkflx 's opinion first.

rkflx requested changes to this revision.Feb 8 2018, 8:32 PM

Much better than the previous approach, works really great for me (for HiDPI too, BTW).

Just a couple of comments on the code, nothing serious though.

src/Gui/KSImageWidget.h
49

This whole member variable + getter function thing looks a bit odd. Could you try and find a way to use static const int like it's done here?

63

I stumbled upon this naming too, maybe include "shadow" somewhere. (See also my other comment.)

src/Gui/KSMainWindow.cpp
49

There may be a case where spectacle opens without capturing an image first

spectacle -r, then press Esc. But don't worry, it works fine (just don't try to drag the image :).

50

My comment about static const int applies to #defines too.

Sizes itself seem fine to me.

199

Add comment about what you are trying to achieve with this calculation in terms of the overall UI layout.

201

In general I'd add const for every variable which is not supposed to be changed later on.

202

How about naming these imageHeight and imageWidth?

206

Is this-> needed?

src/Gui/KSMainWindow.h
56

Add const at the end.

Perhaps windowWidth would be a better name, i.e. more in line with Qt conventions?

src/Gui/KSWidget.cpp
167

If it's not a member variable, why prefix with m?

Also, I'd initialize with 0, as you are not checking for -1 but using them for addition.

src/Gui/KSWidget.h
48

const

This revision now requires changes to proceed.Feb 8 2018, 8:32 PM
anemeth updated this revision to Diff 26794.Feb 8 2018, 9:26 PM

Implemented the changes suggested by @rkflx

anemeth marked 12 inline comments as done.Feb 8 2018, 9:29 PM
anemeth added inline comments.
src/Gui/KSImageWidget.h
49

I'm not quite sure what you meant here.
Is this what you wanted?

rkflx added a comment.Feb 8 2018, 9:52 PM

Thanks, nearly there. I suppose you don't have commit access?

src/Gui/KSImageWidget.h
49

For the most part, you got it. Would it be possible to get rid of shadowRadius() completely by adding an #include instead of calling the function?

Note how my link has those in a namespace and not inside the class, which should help in your case.

src/Gui/KSMainWindow.cpp
199

Sounds good. In general C++ and KDE's code in particular prefers //-style comments over /* */, though (except for the copyright header).

anemeth updated this revision to Diff 26800.Feb 8 2018, 10:56 PM

/* */ --> //

anemeth marked an inline comment as done.Feb 8 2018, 10:57 PM
anemeth added inline comments.
src/Gui/KSImageWidget.h
49

Nothing uses namespace in Specatle.
Isn't it easier and simpler to just add a single function? What's wrong with this approach? It works perfectly.

rkflx added inline comments.Feb 8 2018, 11:13 PM
src/Gui/KSImageWidget.h
49

Spectacle also uses ints instead of enums and other ugly things. For new code I'd advocate to do better. It's not about whether it's working, but about code readability and long-term maintainability of the code base. To me your approach seems pretty uncommon.

You don't have to put everything into a namespace, the constant would be enough for now.

anemeth updated this revision to Diff 26805.Feb 9 2018, 12:59 AM

Shadow radius moved to a namespace

src/Gui/KSImageWidget.h
49

Like this?

rkflx accepted this revision.Feb 9 2018, 5:50 PM
rkflx added inline comments.
src/Gui/KSImageWidget.h
49

Perfect ;)

This way you have only a single place concerned with the constant, don't clutter the class declaration with a function definition and you avoid an extra public function in the API and binary. Everybody knows instantly: "That's a tunable constant."

This revision is now accepted and ready to land.Feb 9 2018, 5:50 PM
rkflx retitled this revision from Window size depends on the screenshot aspect ratio to Let window size depend on the screenshot aspect ratio.Feb 9 2018, 5:50 PM
This revision was automatically updated to reflect the committed changes.