[spectacle/Applications/18.08] /: Add arrow keys to move and resize selection rectangle
Scott Harvey
null at kde.org
Thu Jul 19 11:38:08 BST 2018
Git commit 48eacd1ba1495a9167dd9f9cd8097e86ae6ff6dd by Scott Harvey.
Committed on 19/07/2018 at 10:38.
Pushed by sharvey into branch 'Applications/18.08'.
Add arrow keys to move and resize selection rectangle
Summary:
Add arrow keys to move and resize selection rectangle.
{key Arrows} alone moves in large increment
{key Shift} + {key Arrows} moves in small (single pixel) increments
{key ALT} + {key Arrows} resize rectangle in large increment
{key ALT} + {key Shift} + {key Arrows} resize rectangle in small increment
BUG: 394947
Test Plan:
- Apply patch
- Launch Spectacle; begin Rectangular Selection
- Select a rectangle with the mouse
- Use {key Arrows} to move rectangle (large increment)
- Use {key Shift} + {key Arrows} to move in small increment
- Use {key ALT} + {key Arrows} to resize rectangle (large increment
- Use {key ALT} + {key Shift} + {key Arrows} to resize rectangle in small increment
- Complete capture with mouse or {key Enter} key
- Ensure right selection is captured after moving and resizing rectangle
Reviewers: rkflx, ngraham, #spectacle, yurchor
Reviewed By: rkflx, ngraham, #spectacle, yurchor
Subscribers: ltoscano, kde-doc-english, abalaji, #spectacle
Tags: #documentation
Differential Revision: https://phabricator.kde.org/D13450
M +5 -2 doc/index.docbook
M +202 -3 src/QuickEditor/EditorRoot.qml
https://commits.kde.org/spectacle/48eacd1ba1495a9167dd9f9cd8097e86ae6ff6dd
diff --git a/doc/index.docbook b/doc/index.docbook
index 4fcfb40..0331d5f 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -29,8 +29,8 @@
<legalnotice>&FDLNotice;</legalnotice>
- <date>2018-03-06</date>
- <releaseinfo>Applications 18.04</releaseinfo>
+ <date>2018-07-17</date>
+ <releaseinfo>Applications 18.08</releaseinfo>
<abstract>
<para>&spectacle; is a simple application for capturing desktop screenshots. It can capture images of the entire desktop, a single monitor, the currently active window, the window currently under the mouse, or a rectangular region of the screen. The images can then be printed, sent to other applications for manipulation, or quickly be saved as-is.</para>
@@ -150,6 +150,9 @@
<para>The <guilabel>Rectangular Region</guilabel> option allows you to select a rectangular region of your desktop with your mouse. This region may be spread across different outputs.</para>
<para>This mode does not immediately take a screenshot but allows you to draw a rectangle on your screen, which can be moved and resized as needed. Once the desired selection rectangle has been drawn, double-clicking anywhere on the screen, or pressing the &Enter; button on the keyboard will capture the screenshot.</para>
+
+ <para>You can use the arrow keys to move and adjust the rectangle. Pressing the arrow keys will move the rectangle. Holding the <keycap>Shift</keycap> key while pressing the arrow keys will move the rectangle slowly, for fine-tuning your selection. Holding the <keycap>Alt</keycap> key while pressing the arrow keys will adjust the size of the rectangle.</para>
+
</listitem>
</itemizedlist>
diff --git a/src/QuickEditor/EditorRoot.qml b/src/QuickEditor/EditorRoot.qml
index 583bc37..10560ab 100644
--- a/src/QuickEditor/EditorRoot.qml
+++ b/src/QuickEditor/EditorRoot.qml
@@ -38,6 +38,8 @@ Item {
property int magZoom: 5;
property int magPixels: 16;
property int magOffset: 32;
+ property double largeChange: 15;
+ property double smallChange: 1 / Screen.devicePixelRatio;
SystemPalette {
id: systemPalette;
@@ -78,11 +80,202 @@ Item {
}
Keys.onPressed: {
+
+ var change;
+
+ // shift key alone = magnifier toggle
if (event.modifiers & Qt.ShiftModifier) {
toggleMagnifier = true;
- cropDisplayCanvas.requestPaint();
}
- }
+
+ // nested switches for arrow keys based on modifier keys
+ switch(event.modifiers) {
+
+ case Qt.NoModifier:
+ switch (event.key) {
+
+ case Qt.Key_Left:
+ change = checkBounds(-largeChange, 0.0, "left");
+ selection.x += change;
+ break;
+ case Qt.Key_Right:
+ change = checkBounds(largeChange, 0.0, "right");
+ selection.x += change;
+ break;
+ case Qt.Key_Up:
+ change = checkBounds(0.0, -largeChange, "up");
+ selection.y += change;
+ break;
+ case Qt.Key_Down:
+ change = checkBounds(0.0, largeChange, "down");
+ selection.y += change;
+ break;
+ }
+
+ break; // end no modifier (just arrows)
+
+ case Qt.ShiftModifier:
+ switch (event.key) {
+
+ case Qt.Key_Left:
+ change = checkBounds(-smallChange, 0.0, "left");
+ selection.x += change;
+ break;
+
+ case Qt.Key_Right:
+ change = checkBounds(smallChange, 0.0, "right");
+ selection.x += change;
+ break;
+
+ case Qt.Key_Up:
+ change = checkBounds(0.0, -smallChange, "up");
+ selection.y += change;
+ break;
+
+ case Qt.Key_Down:
+ change = checkBounds(0.0, smallChange, "down");
+ selection.y += change;
+ break;
+ }
+
+ break; // end Shift + arrows (large move)
+
+ case Qt.AltModifier:
+ switch (event.key) {
+
+ case Qt.Key_Left:
+ change = checkBounds(-largeChange, 0.0, "left");
+ if (selection.width + change <= 0.0) {
+ selection.width = 0.0;
+ } else {
+ selection.width += change;
+ }
+ break;
+
+ case Qt.Key_Right:
+ change = checkBounds(largeChange, 0.0, "right");
+ selection.width += change;
+ break;
+
+ case Qt.Key_Up:
+ change = checkBounds(0.0, -largeChange, "up");
+ if (selection.height + change <= 0.0) {
+ selection.height = 0.0;
+ } else {
+ selection.height += change;
+ }
+ break;
+
+ case Qt.Key_Down:
+ change = checkBounds(0.0, largeChange, "down");
+ selection.height = selection.height + change;
+ break;
+ }
+
+ break; // end ALT + arrows (resize rectangle)
+
+ case (Qt.ShiftModifier + Qt.AltModifier):
+ switch (event.key) {
+
+ case Qt.Key_Left:
+ change = checkBounds(-smallChange, 0.0, "left");
+ if (selection.width + change <= 0.0) {
+ selection.width = 0.0;
+ } else {
+ selection.width += change;
+ }
+ break;
+
+ case Qt.Key_Right:
+ change = checkBounds(smallChange, 0.0, "right");
+ selection.width += change;
+ break;
+
+ case Qt.Key_Up:
+ change = checkBounds(0.0, -smallChange, "up");
+ if (selection.height + change <= 0.0) {
+ selection.height = 0.0;
+ } else {
+ selection.height += change
+ }
+ break;
+
+ case Qt.Key_Down:
+ change = checkBounds(0.0, smallChange, "down");
+ selection.height += change;
+ break;
+ }
+
+ break; // end Shift + ALT + arrows (large resize rectangle)
+
+ }
+
+ // all switches done; repaint on any keypress
+ cropDisplayCanvas.requestPaint();
+
+ function checkBounds(changeX, changeY, direction) {
+
+ var leftEdge = selection.x;
+ var rightEdge = selection.x + selection.width;
+ var topEdge = selection.y;
+ var bottomEdge = selection.y + selection.height;
+
+ const screenMaxX = cropDisplayCanvas.width;
+ const screenMaxY = cropDisplayCanvas.height;
+
+ var newX;
+ var newY;
+
+ var overlap;
+
+ newX = selection.x + changeX;
+ newY = selection.y + changeY;
+
+ switch (direction) {
+
+ case "left":
+ if (leftEdge + changeX > 0.0) {
+ return changeX;
+ }
+
+ if (leftEdge + changeX < 0.0) {
+ return -leftEdge;
+ }
+ break;
+
+ case "right":
+ newX = newX + selection.width;
+ if (newX < screenMaxX) {
+ return changeX;
+ }
+ if (newX > screenMaxX) {
+ overlap = newX - screenMaxX;
+ return changeX - overlap;
+ }
+ break;
+
+ case "up":
+ if (topEdge + changeY > 0.0) {
+ return changeY;
+ } else {
+ return -topEdge;
+ }
+
+ case "down":
+ newY = newY + selection.height;
+ if (newY < screenMaxY) {
+ return changeY;
+ }
+ if (newY > screenMaxY) {
+ overlap = newY - screenMaxY;
+ return changeY - overlap;
+ }
+ break;
+
+ }
+ }
+ } // end Keys.onPressed
+
Keys.onReleased: {
if (toggleMagnifier && !(event.modifiers & Qt.ShiftModifier)) {
@@ -304,6 +497,13 @@ Item {
}
Label { text: i18n("Hold to toggle magnifier"); }
+ Label {
+ text: i18n("Arrow keys:");
+ Layout.alignment: Qt.AlignRight | Qt.AlignTop;
+ }
+ Label { text: i18n("Move selection rectangle \n" +
+ "Hold Alt to resize, Shift to fine-tune"); }
+
Label {
text: i18n("Right-click:");
Layout.alignment: Qt.AlignRight;
@@ -368,7 +568,6 @@ Item {
color: crossColour;
}
}
-
}
MouseArea {
More information about the kde-doc-english
mailing list