summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-08-29 10:32:22 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-20 09:58:03 +0000
commit719d2198bcda25768cafb2c7f4194317eff6b306 (patch)
treef445249b0fee07e63b0b1f861a1aa27785e87a92
parent04555d2dc8d5fb23240e99b14bbc804d049b4f29 (diff)
(mostly) use Shortcut rather than Keys
Thus it's not required for the root Presentation to retain key focus. That way each slide can also use the keyboard as long as those uses don't interefere with the global shortcuts. The shortcuts can also be disabled in case they interfere (e.g. using arrow navigation globally prevents using it for navigating within a slide). The remaining exception is for directly entering slide numbers. IMO this is impractical anyway; but if you need to do that, then you also need to give the Presentation keyboard focus, as before. The shortcut which used Esc to quit is removed, and replaced with the more-standard Control-Q. Enter and Backspace are also no longer used for slide navigation: there seem to be enough keys for that. Change-Id: I0a54ae62305aa28b0ffef15b5ec010058c36fb8e Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--src/Presentation.qml40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/Presentation.qml b/src/Presentation.qml
index a99e272..00903bf 100644
--- a/src/Presentation.qml
+++ b/src/Presentation.qml
@@ -40,7 +40,7 @@
****************************************************************************/
-import QtQuick 2.0
+import QtQuick 2.5
import QtQuick.Window 2.0
Item {
@@ -52,6 +52,8 @@ Item {
property bool showNotes: false;
property bool allowDelay: true;
property alias mouseNavigation: mouseArea.enabled
+ property bool arrowNavigation: true
+ property bool keyShortcutsEnabled: true
property color titleColor: textColor;
property color textColor: "black"
@@ -100,20 +102,16 @@ Item {
if (root.slides[currentSlide]._advance())
return;
}
- if (currentSlide + 1 < root.slides.length) {
+ if (currentSlide + 1 < root.slides.length)
++currentSlide;
- root.focus = true;
- }
}
function goToPreviousSlide() {
root._userNum = 0
if (root._faded)
return
- if (currentSlide - 1 >= 0) {
+ if (currentSlide - 1 >= 0)
--currentSlide;
- root.focus = true;
- }
}
function goToUserSlide() {
@@ -128,28 +126,32 @@ Item {
}
}
- focus: true
-
- Keys.onSpacePressed: goToNextSlide()
- Keys.onRightPressed: goToNextSlide()
- Keys.onDownPressed: goToNextSlide()
- Keys.onLeftPressed: goToPreviousSlide()
- Keys.onUpPressed: goToPreviousSlide()
- Keys.onEscapePressed: Qt.quit()
+ // directly type in the slide number: depends on root having focus
Keys.onPressed: {
if (event.key >= Qt.Key_0 && event.key <= Qt.Key_9)
_userNum = 10 * _userNum + (event.key - Qt.Key_0)
else {
if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter)
goToUserSlide();
- else if (event.key == Qt.Key_Backspace)
- goToPreviousSlide();
- else if (event.key == Qt.Key_C)
- root._faded = !root._faded;
_userNum = 0;
}
}
+ // navigate with arrow keys
+ Shortcut { sequence: StandardKey.MoveToNextLine; enabled: root.arrowNavigation; onActivated: goToNextSlide() }
+ Shortcut { sequence: StandardKey.MoveToPreviousLine; enabled: root.arrowNavigation; onActivated: goToPreviousSlide() }
+ Shortcut { sequence: StandardKey.MoveToNextChar; enabled: root.arrowNavigation; onActivated: goToNextSlide() }
+ Shortcut { sequence: StandardKey.MoveToPreviousChar; enabled: root.arrowNavigation; onActivated: goToPreviousSlide() }
+
+ // presentation-specific single-key shortcuts (which interfere with normal typing)
+ Shortcut { sequence: " "; enabled: root.keyShortcutsEnabled; onActivated: goToNextSlide() }
+ Shortcut { sequence: "c"; enabled: root.keyShortcutsEnabled; onActivated: root._faded = !root._faded }
+
+ // standard shortcuts
+ Shortcut { sequence: StandardKey.MoveToNextPage; onActivated: goToNextSlide() }
+ Shortcut { sequence: StandardKey.MoveToPreviousPage; onActivated: goToPreviousSlide() }
+ Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() }
+
Rectangle {
z: 1000
color: "black"