on xenial help sign in
allow up/down keys to manipulate focus in the fenced focus chain
43912eaLukáš Tinkl
plugins/Utils/tabfocusfence.cpp+22
@@ -25,6 +25,28 @@ TabFocusFenceItem::TabFocusFenceItem(QQuickItem *parent) : QQuickItem(parent)
25 setFlag(ItemIsFocusScope);
25 setFlag(ItemIsFocusScope);
26}
26}
27
27
28+void TabFocusFenceItem::focusNext()
29+{
30+ QQuickItem * current = scopedFocusItem();
31+ if (current) {
32+ QQuickItem * next = scopedFocusItem()->nextItemInFocusChain(true);
33+ if (next) {
34+ next->setFocus(true, Qt::TabFocusReason);
35+ }
36+ }
37+}
38+
39+void TabFocusFenceItem::focusPrev()
40+{
41+ QQuickItem * current = scopedFocusItem();
42+ if (current) {
43+ QQuickItem * prev = scopedFocusItem()->nextItemInFocusChain(false);
44+ if (prev) {
45+ prev->setFocus(true, Qt::BacktabFocusReason);
46+ }
47+ }
48+}
49+
28void TabFocusFenceItem::keyPressEvent(QKeyEvent *event)
50void TabFocusFenceItem::keyPressEvent(QKeyEvent *event)
29{
51{
30 // Needed so we eat Tab keys when there's only one item inside the fence
52 // Needed so we eat Tab keys when there's only one item inside the fence
plugins/Utils/tabfocusfence.h+3
@@ -28,6 +28,9 @@ Q_OBJECT
28public:
28public:
29 TabFocusFenceItem(QQuickItem *parent = nullptr);
29 TabFocusFenceItem(QQuickItem *parent = nullptr);
30
30
31+ Q_INVOKABLE void focusNext();
32+ Q_INVOKABLE void focusPrev();
33+
31 void keyPressEvent(QKeyEvent *event) override;
34 void keyPressEvent(QKeyEvent *event) override;
32 void keyReleaseEvent(QKeyEvent *event) override;
35 void keyReleaseEvent(QKeyEvent *event) override;
33};
36};
qml/Components/ShellDialog.qml+6
@@ -61,5 +61,11 @@ Dialog {
61 width: parent.width
61 width: parent.width
62 spacing: units.gu(2)
62 spacing: units.gu(2)
63 }
63 }
64+ Keys.onDownPressed: {
65+ focusNext();
66+ }
67+ Keys.onUpPressed: {
68+ focusPrev();
69+ }
64 }
70 }
65}
71}