Skip to content

Commit 617c210

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 ee5b176 commit 617c210

11 files changed

+156
-7
lines changed

ui/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ add_library(${module_name}
141141
virtualconsole/vcmatrixproperties.cpp virtualconsole/vcmatrixproperties.h virtualconsole/vcmatrixproperties.ui
142142
virtualconsole/vcproperties.cpp virtualconsole/vcproperties.h virtualconsole/vcproperties.ui
143143
virtualconsole/vcpropertieseditor.cpp virtualconsole/vcpropertieseditor.h
144+
virtualconsole/vcscrollarea.cpp virtualconsole/vcscrollarea.h
144145
virtualconsole/vcslider.cpp virtualconsole/vcslider.h
145146
virtualconsole/vcsliderproperties.cpp virtualconsole/vcsliderproperties.h virtualconsole/vcsliderproperties.ui
146147
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
@@ -33,6 +33,7 @@
3333

3434
VCProperties::VCProperties()
3535
: m_size(QSize(1920, 1080))
36+
, m_keyboardScroll(true)
3637
, m_gmChannelMode(GrandMaster::Intensity)
3738
, m_gmValueMode(GrandMaster::Reduce)
3839
, m_gmSliderMode(GrandMaster::Normal)
@@ -43,6 +44,7 @@ VCProperties::VCProperties()
4344

4445
VCProperties::VCProperties(const VCProperties& properties)
4546
: m_size(properties.m_size)
47+
, m_keyboardScroll(properties.m_keyboardScroll)
4648
, m_gmChannelMode(properties.m_gmChannelMode)
4749
, m_gmValueMode(properties.m_gmValueMode)
4850
, m_gmSliderMode(properties.m_gmSliderMode)
@@ -60,6 +62,7 @@ VCProperties &VCProperties::operator=(const VCProperties &props)
6062
if (this != &props)
6163
{
6264
m_size = props.m_size;
65+
m_keyboardScroll = props.m_keyboardScroll;
6366
m_gmChannelMode = props.m_gmChannelMode;
6467
m_gmValueMode = props.m_gmValueMode;
6568
m_gmSliderMode = props.m_gmSliderMode;
@@ -84,6 +87,20 @@ QSize VCProperties::size() const
8487
return m_size;
8588
}
8689

90+
/*****************************************************************************
91+
* Keyboard scrolling
92+
*****************************************************************************/
93+
94+
void VCProperties::setKeyboardScroll(const bool enable)
95+
{
96+
m_keyboardScroll = enable;
97+
}
98+
99+
bool VCProperties::keyboardScroll() const
100+
{
101+
return m_keyboardScroll;
102+
}
103+
87104
/*****************************************************************************
88105
* Grand Master
89106
*****************************************************************************/
@@ -166,6 +183,15 @@ bool VCProperties::loadXML(QXmlStreamReader &root)
166183
/* Set size if both are valid */
167184
if (sz.isValid() == true)
168185
setSize(sz);
186+
\
187+
bool keyboardScroll = true;
188+
189+
/* Keyboard scrolling */
190+
str = root.attributes().value(KXMLQLCVCPropertiesKeyboardScroll).toString();
191+
if (str.isEmpty() == false)
192+
keyboardScroll = QVariant(str).toBool();
193+
setKeyboardScroll(keyboardScroll);
194+
169195
root.skipCurrentElement();
170196
}
171197
else if (root.name() == KXMLQLCVCPropertiesGrandMaster)
@@ -224,6 +250,7 @@ bool VCProperties::saveXML(QXmlStreamWriter *doc) const
224250
doc->writeStartElement(KXMLQLCVCPropertiesSize);
225251
doc->writeAttribute(KXMLQLCVCPropertiesSizeWidth, QString::number(size().width()));
226252
doc->writeAttribute(KXMLQLCVCPropertiesSizeHeight, QString::number(size().height()));
253+
doc->writeAttribute(KXMLQLCVCPropertiesKeyboardScroll, QVariant(keyboardScroll()).toString());
227254
doc->writeEndElement();
228255

229256
/***********************

ui/src/virtualconsole/vcproperties.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ class Doc;
3737

3838
#define KXMLQLCVirtualConsole QString("VirtualConsole")
3939

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

4546
#define KXMLQLCVCPropertiesGrandMaster QString("GrandMaster")
4647
#define KXMLQLCVCPropertiesGrandMasterVisible QString("Visible")
@@ -78,6 +79,19 @@ class VCProperties
7879
private:
7980
QSize m_size;
8081

82+
/*********************************************************************
83+
* Keyboard scrolling
84+
*********************************************************************/
85+
public:
86+
/** Set Virtual Console keyboard scrolling */
87+
void setKeyboardScroll(const bool enable);
88+
89+
/** Get Virtual Console keyboard scrolling */
90+
bool keyboardScroll() const;
91+
92+
private:
93+
bool m_keyboardScroll;
94+
8195
/*************************************************************************
8296
* Grand Master
8397
*************************************************************************/

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::Vertical</enum>
@@ -820,6 +849,7 @@
820849
<tabstops>
821850
<tabstop>m_sizeXSpin</tabstop>
822851
<tabstop>m_sizeYSpin</tabstop>
852+
<tabstop>m_enableKeyboardScroll</tabstop>
823853
<tabstop>m_buttonWspin</tabstop>
824854
<tabstop>m_buttonHspin</tabstop>
825855
<tabstop>m_sliderWspin</tabstop>
@@ -994,6 +1024,22 @@
9941024
</hint>
9951025
</hints>
9961026
</connection>
1027+
<connection>
1028+
<sender>m_enableKeyboardScroll</sender>
1029+
<signal>toggled(bool)</signal>
1030+
<receiver>VCPropertiesEditor</receiver>
1031+
<slot>slotKeyboardScrollToggled(bool)</slot>
1032+
<hints>
1033+
<hint type="sourcelabel">
1034+
<x>190</x>
1035+
<y>198</y>
1036+
</hint>
1037+
<hint type="destinationlabel">
1038+
<x>190</x>
1039+
<y>245</y>
1040+
</hint>
1041+
</hints>
1042+
</connection>
9971043
</connections>
9981044
<slots>
9991045
<slot>slotGridXChanged(int)</slot>

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;
@@ -319,6 +320,11 @@ void VCPropertiesEditor::slotSizeYChanged(int value)
319320
m_properties.setSize(sz);
320321
}
321322

323+
void VCPropertiesEditor::slotKeyboardScrollToggled(bool checked)
324+
{
325+
m_properties.setKeyboardScroll(checked);
326+
}
327+
322328
void VCPropertiesEditor::slotSpeedDialConfirmed()
323329
{
324330
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ VirtualConsole::VirtualConsole(QWidget* parent, Doc* doc)
133133
, m_contents(NULL)
134134

135135
, m_liveEdit(false)
136+
, m_keyboardScroll(true)
136137
{
137138
Q_ASSERT(s_instance == NULL);
138139
s_instance = this;
@@ -1583,7 +1584,7 @@ void VirtualConsole::initContents()
15831584
{
15841585
Q_ASSERT(layout() != NULL);
15851586

1586-
m_scrollArea = new QScrollArea(this);
1587+
m_scrollArea = new VCScrollArea(this);
15871588
m_contentsLayout->addWidget(m_scrollArea);
15881589
m_scrollArea->setAlignment(Qt::AlignCenter);
15891590
m_scrollArea->setWidgetResizable(false);
@@ -1707,6 +1708,9 @@ void VirtualConsole::enableEdit()
17071708
m_stackingRaiseAction->setShortcut(QKeySequence("SHIFT+UP"));
17081709
m_stackingLowerAction->setShortcut(QKeySequence("SHIFT+DOWN"));
17091710

1711+
// disable key passthru
1712+
m_scrollArea->setKeyPassthruEnabled(false);
1713+
17101714
// Show toolbar
17111715
m_toolbar->show();
17121716
}
@@ -1759,6 +1763,10 @@ void VirtualConsole::disableEdit()
17591763
m_stackingRaiseAction->setShortcut(QKeySequence());
17601764
m_stackingLowerAction->setShortcut(QKeySequence());
17611765

1766+
1767+
// manage key passthru
1768+
m_scrollArea->setKeyPassthruEnabled(!m_keyboardScroll);
1769+
17621770
// Hide toolbar; there's nothing usable there in operate mode
17631771
m_toolbar->hide();
17641772

@@ -1821,6 +1829,7 @@ bool VirtualConsole::loadXML(QXmlStreamReader &root)
18211829
QSize size(m_properties.size());
18221830
contents()->resize(size);
18231831
contents()->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1832+
m_keyboardScroll = m_properties.keyboardScroll();
18241833
}
18251834
else if (root.name() == KXMLQLCVCFrame)
18261835
{

0 commit comments

Comments
 (0)