Skip to content

Commit 1f1409b

Browse files
committed
ui: introduce keyboard scroll flag in Virtual Console
Introduce in Virtual Console Settings a flag to enable/disable standard keyboard management on scroll area. The flag, when enabled (default), guarantees current behaviour: arrow keys and PgUp/PgDown keys are used to scroll the console and cannot be used as key combinations for controls. When disabled, the scroll area does not consume key events anymore, leaving all the keys available as key combinations on the controls.
1 parent 5413a7e commit 1f1409b

11 files changed

+156
-8
lines changed

ui/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ add_library(${module_name}
127127
virtualconsole/vcmatrixproperties.cpp virtualconsole/vcmatrixproperties.h virtualconsole/vcmatrixproperties.ui
128128
virtualconsole/vcproperties.cpp virtualconsole/vcproperties.h virtualconsole/vcproperties.ui
129129
virtualconsole/vcpropertieseditor.cpp virtualconsole/vcpropertieseditor.h
130+
virtualconsole/vcscrollarea.cpp virtualconsole/vcscrollarea.h
130131
virtualconsole/vcslider.cpp virtualconsole/vcslider.h
131132
virtualconsole/vcsliderproperties.cpp virtualconsole/vcsliderproperties.h virtualconsole/vcsliderproperties.ui
132133
virtualconsole/vcsoloframe.cpp virtualconsole/vcsoloframe.h

ui/src/src.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ HEADERS += virtualconsole/addvcbuttonmatrix.h \
155155
virtualconsole/vcmatrixproperties.h \
156156
virtualconsole/vcproperties.h \
157157
virtualconsole/vcpropertieseditor.h \
158+
virtualconsole/vcscrollarea.h \
158159
virtualconsole/vcslider.h \
159160
virtualconsole/vcsliderproperties.h \
160161
virtualconsole/vcsoloframe.h \
@@ -337,6 +338,7 @@ SOURCES += virtualconsole/addvcbuttonmatrix.cpp \
337338
virtualconsole/vcmatrixproperties.cpp \
338339
virtualconsole/vcproperties.cpp \
339340
virtualconsole/vcpropertieseditor.cpp \
341+
virtualconsole/vcscrollarea.cpp \
340342
virtualconsole/vcslider.cpp \
341343
virtualconsole/vcsliderproperties.cpp \
342344
virtualconsole/vcsoloframe.cpp \

ui/src/virtualconsole/vcproperties.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
VCProperties::VCProperties()
3535
: m_size(QSize(1920, 1080))
3636
, m_gmVisible(true)
37+
, m_keyboardScroll(true)
3738
, m_gmChannelMode(GrandMaster::Intensity)
3839
, m_gmValueMode(GrandMaster::Reduce)
3940
, m_gmSliderMode(GrandMaster::Normal)
@@ -45,6 +46,7 @@ VCProperties::VCProperties()
4546
VCProperties::VCProperties(const VCProperties& properties)
4647
: m_size(properties.m_size)
4748
, m_gmVisible(properties.m_gmVisible)
49+
, m_keyboardScroll(properties.m_keyboardScroll)
4850
, m_gmChannelMode(properties.m_gmChannelMode)
4951
, m_gmValueMode(properties.m_gmValueMode)
5052
, m_gmSliderMode(properties.m_gmSliderMode)
@@ -63,6 +65,7 @@ VCProperties &VCProperties::operator=(const VCProperties &props)
6365
{
6466
m_size = props.m_size;
6567
m_gmVisible = props.m_gmVisible;
68+
m_keyboardScroll = props.m_keyboardScroll;
6669
m_gmChannelMode = props.m_gmChannelMode;
6770
m_gmValueMode = props.m_gmValueMode;
6871
m_gmSliderMode = props.m_gmSliderMode;
@@ -87,6 +90,20 @@ QSize VCProperties::size() const
8790
return m_size;
8891
}
8992

93+
/*****************************************************************************
94+
* Keyboard scrolling
95+
*****************************************************************************/
96+
97+
void VCProperties::setKeyboardScroll(const bool enable)
98+
{
99+
m_keyboardScroll = enable;
100+
}
101+
102+
bool VCProperties::keyboardScroll() const
103+
{
104+
return m_keyboardScroll;
105+
}
106+
90107
/*****************************************************************************
91108
* Grand Master
92109
*****************************************************************************/
@@ -179,6 +196,15 @@ bool VCProperties::loadXML(QXmlStreamReader &root)
179196
/* Set size if both are valid */
180197
if (sz.isValid() == true)
181198
setSize(sz);
199+
\
200+
bool keyboardScroll = true;
201+
202+
/* Keyboard scrolling */
203+
str = root.attributes().value(KXMLQLCVCPropertiesKeyboardScroll).toString();
204+
if (str.isEmpty() == false)
205+
keyboardScroll = QVariant(str).toBool();
206+
setKeyboardScroll(keyboardScroll);
207+
182208
root.skipCurrentElement();
183209
}
184210
else if (root.name() == KXMLQLCVCPropertiesGrandMaster)
@@ -242,6 +268,7 @@ bool VCProperties::saveXML(QXmlStreamWriter *doc) const
242268
doc->writeStartElement(KXMLQLCVCPropertiesSize);
243269
doc->writeAttribute(KXMLQLCVCPropertiesSizeWidth, QString::number(size().width()));
244270
doc->writeAttribute(KXMLQLCVCPropertiesSizeHeight, QString::number(size().height()));
271+
doc->writeAttribute(KXMLQLCVCPropertiesKeyboardScroll, QVariant(keyboardScroll()).toString());
245272
doc->writeEndElement();
246273

247274
/***********************

ui/src/virtualconsole/vcproperties.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ class Doc;
3535
* @{
3636
*/
3737

38-
#define KXMLQLCVirtualConsole QStringLiteral("VirtualConsole")
38+
#define KXMLQLCVirtualConsole QStringLiteral("VirtualConsole")
3939

40-
#define KXMLQLCVCProperties QStringLiteral("Properties")
41-
#define KXMLQLCVCPropertiesSize QStringLiteral("Size")
42-
#define KXMLQLCVCPropertiesSizeWidth QStringLiteral("Width")
43-
#define KXMLQLCVCPropertiesSizeHeight QStringLiteral("Height")
40+
#define KXMLQLCVCProperties QStringLiteral("Properties")
41+
#define KXMLQLCVCPropertiesSize QStringLiteral("Size")
42+
#define KXMLQLCVCPropertiesSizeWidth QStringLiteral("Width")
43+
#define KXMLQLCVCPropertiesSizeHeight QStringLiteral("Height")
44+
#define KXMLQLCVCPropertiesKeyboardScroll QStringLiteral("KeyboardScroll")
4445

4546
#define KXMLQLCVCPropertiesGrandMaster QStringLiteral("GrandMaster")
4647
#define KXMLQLCVCPropertiesGrandMasterVisible QStringLiteral("Visible")
@@ -98,8 +99,19 @@ class VCProperties
9899
quint32 grandMasterInputUniverse() const;
99100
quint32 grandMasterInputChannel() const;
100101

102+
/*********************************************************************
103+
* Keyboard scrolling
104+
*********************************************************************/
105+
106+
/** Set Virtual Console keyboard scrolling */
107+
void setKeyboardScroll(const bool enable);
108+
109+
/** Get Virtual Console keyboard scrolling */
110+
bool keyboardScroll() const;
111+
101112
private:
102113
bool m_gmVisible;
114+
bool m_keyboardScroll;
103115
GrandMaster::ChannelMode m_gmChannelMode;
104116
GrandMaster::ValueMode m_gmValueMode;
105117
GrandMaster::SliderMode m_gmSliderMode;

ui/src/virtualconsole/vcproperties.ui

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@
105105
</widget>
106106
</item>
107107
<item row="1" column="0">
108+
<widget class="QGroupBox" name="m_scrollGroup">
109+
<property name="title">
110+
<string>Scrolling</string>
111+
</property>
112+
<layout class="QGridLayout" name="gridLayout_1">
113+
<item row="0" column="0">
114+
<widget class="QCheckBox" name="m_enableKeyboardScroll">
115+
<property name="text">
116+
<string>Use arrow and PgUp/PgDown keys to scroll</string>
117+
</property>
118+
<property name="checked">
119+
<bool>true</bool>
120+
</property>
121+
</widget>
122+
</item>
123+
<item row="1" column="0">
124+
<widget class="QLabel" name="m_keyboardScrollWarning">
125+
<property name="text">
126+
<string>Note: enabling keyboard scroll prevents using arrow and PgUp/PgDown keys in Key combinations for console controls.</string>
127+
</property>
128+
<property name="wordWrap">
129+
<bool>true</bool>
130+
</property>
131+
</widget>
132+
</item>
133+
</layout>
134+
</widget>
135+
</item>
136+
<item row="2" column="0">
108137
<spacer name="verticalSpacer_2">
109138
<property name="orientation">
110139
<enum>Qt::Orientation::Vertical</enum>
@@ -830,6 +859,7 @@
830859
<tabstops>
831860
<tabstop>m_sizeXSpin</tabstop>
832861
<tabstop>m_sizeYSpin</tabstop>
862+
<tabstop>m_enableKeyboardScroll</tabstop>
833863
<tabstop>m_buttonWspin</tabstop>
834864
<tabstop>m_buttonHspin</tabstop>
835865
<tabstop>m_sliderWspin</tabstop>
@@ -1004,6 +1034,22 @@
10041034
</hint>
10051035
</hints>
10061036
</connection>
1037+
<connection>
1038+
<sender>m_enableKeyboardScroll</sender>
1039+
<signal>toggled(bool)</signal>
1040+
<receiver>VCPropertiesEditor</receiver>
1041+
<slot>slotKeyboardScrollToggled(bool)</slot>
1042+
<hints>
1043+
<hint type="sourcelabel">
1044+
<x>190</x>
1045+
<y>198</y>
1046+
</hint>
1047+
<hint type="destinationlabel">
1048+
<x>190</x>
1049+
<y>245</y>
1050+
</hint>
1051+
</hints>
1052+
</connection>
10071053
<connection>
10081054
<sender>m_gmVisible</sender>
10091055
<signal>toggled(bool)</signal>

ui/src/virtualconsole/vcpropertieseditor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ VCPropertiesEditor::VCPropertiesEditor(QWidget* parent, const VCProperties& prop
5656
/* General page */
5757
m_sizeXSpin->setValue(properties.size().width());
5858
m_sizeYSpin->setValue(properties.size().height());
59+
m_enableKeyboardScroll->setChecked(properties.keyboardScroll());
5960

6061
/* Widgets page */
6162
QSettings settings;
@@ -321,6 +322,11 @@ void VCPropertiesEditor::slotSizeYChanged(int value)
321322
m_properties.setSize(sz);
322323
}
323324

325+
void VCPropertiesEditor::slotKeyboardScrollToggled(bool checked)
326+
{
327+
m_properties.setKeyboardScroll(checked);
328+
}
329+
324330
void VCPropertiesEditor::slotSpeedDialConfirmed()
325331
{
326332
if (m_speedValueEdit->text().contains(".") == false)

ui/src/virtualconsole/vcpropertieseditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class VCPropertiesEditor : public QDialog, public Ui_VCPropertiesEditor
8484
private slots:
8585
void slotSizeXChanged(int value);
8686
void slotSizeYChanged(int value);
87+
void slotKeyboardScrollToggled(bool checked);
8788

8889
/*************************************************************************
8990
* Widgets page
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "vcscrollarea.h"
2+
#include "qevent.h"
3+
4+
VCScrollArea::VCScrollArea(QWidget *parent) : QScrollArea(parent) {
5+
// nothing more right now
6+
}
7+
8+
void VCScrollArea::keyPressEvent(QKeyEvent *ev) {
9+
if (m_keyPassthru) {
10+
ev->ignore();
11+
} else {
12+
QScrollArea::keyPressEvent(ev);
13+
}
14+
}
15+
16+
void VCScrollArea::setKeyPassthruEnabled(bool enable) {
17+
m_keyPassthru = enable;
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef VCSCROLLAREA_H
2+
#define VCSCROLLAREA_H
3+
4+
#include <QObject>
5+
#include <QScrollArea>
6+
#include <QWidget>
7+
8+
class VCScrollArea : public QScrollArea
9+
{
10+
Q_OBJECT
11+
public:
12+
explicit VCScrollArea(QWidget *parent = nullptr);
13+
14+
void setKeyPassthruEnabled(bool enabled);
15+
16+
protected:
17+
void keyPressEvent(QKeyEvent *) override;
18+
19+
private:
20+
bool m_keyPassthru;
21+
};
22+
23+
#endif // VCSCROLLAREA_H

ui/src/virtualconsole/virtualconsole.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ VirtualConsole::VirtualConsole(QWidget* parent, Doc* doc)
135135
, m_contents(NULL)
136136

137137
, m_liveEdit(false)
138+
, m_keyboardScroll(true)
138139
{
139140
Q_ASSERT(s_instance == NULL);
140141
s_instance = this;
@@ -1014,6 +1015,7 @@ void VirtualConsole::slotToolsSettings()
10141015
m_dockArea->setGrandMasterVisible(m_properties.grandMasterVisible());
10151016
m_dockArea->setGrandMasterInvertedAppearance(m_properties.grandMasterSliderMode());
10161017
}
1018+
m_keyboardScroll = m_properties.keyboardScroll();
10171019

10181020
QSettings settings;
10191021
settings.setValue(SETTINGS_BUTTON_SIZE, vcpe.buttonSize());
@@ -1605,7 +1607,7 @@ void VirtualConsole::initContents()
16051607
{
16061608
Q_ASSERT(layout() != NULL);
16071609

1608-
m_scrollArea = new QScrollArea(this);
1610+
m_scrollArea = new VCScrollArea(this);
16091611
m_contentsLayout->addWidget(m_scrollArea);
16101612
m_scrollArea->setAlignment(Qt::AlignCenter);
16111613
m_scrollArea->setWidgetResizable(false);
@@ -1730,6 +1732,9 @@ void VirtualConsole::enableEdit()
17301732
m_stackingRaiseAction->setShortcut(QKeySequence("SHIFT+UP"));
17311733
m_stackingLowerAction->setShortcut(QKeySequence("SHIFT+DOWN"));
17321734

1735+
// disable key passthru
1736+
m_scrollArea->setKeyPassthruEnabled(false);
1737+
17331738
// Show toolbar
17341739
m_toolbar->show();
17351740
}
@@ -1783,6 +1788,10 @@ void VirtualConsole::disableEdit()
17831788
m_stackingRaiseAction->setShortcut(QKeySequence());
17841789
m_stackingLowerAction->setShortcut(QKeySequence());
17851790

1791+
1792+
// manage key passthru
1793+
m_scrollArea->setKeyPassthruEnabled(!m_keyboardScroll);
1794+
17861795
// Hide toolbar; there's nothing usable there in operate mode
17871796
m_toolbar->hide();
17881797

@@ -1845,6 +1854,7 @@ bool VirtualConsole::loadXML(QXmlStreamReader &root)
18451854
QSize size(m_properties.size());
18461855
contents()->resize(size);
18471856
contents()->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1857+
m_keyboardScroll = m_properties.keyboardScroll();
18481858
}
18491859
else if (root.name() == KXMLQLCVCFrame)
18501860
{

0 commit comments

Comments
 (0)