Skip to content

Commit

Permalink
Add an option for touch scrolling
Browse files Browse the repository at this point in the history
The touch scrolling support was introduced in commit c2b83bd, but
it's not convenient for devices with a small touch screen, so I added
an option for enabling/disabling this feature.
  • Loading branch information
wh201906 committed Apr 13, 2024
1 parent cae854b commit fda6389
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/ctrltab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CtrlTab::CtrlTab(QWidget *parent) :
commentRegExp->optimize();

ui->ctrl_dataEdit->hide();
QScroller::grabGesture(ui->ctrl_itemArea);
}

CtrlTab::~CtrlTab()
Expand Down Expand Up @@ -238,3 +237,15 @@ void CtrlTab::dropEvent(QDropEvent *event)
file.close();
}
}

void CtrlTab::setTouchScroll(bool enabled)
{
if(enabled)
{
QScroller::grabGesture(ui->ctrl_itemArea);
}
else
{
QScroller::ungrabGesture(ui->ctrl_itemArea);
}
}
1 change: 1 addition & 0 deletions src/ctrltab.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CtrlTab : public QWidget

public slots:
void setDataCodec(QTextCodec *codec);
void setTouchScroll(bool enabled);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
Expand Down
37 changes: 28 additions & 9 deletions src/devicetab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,6 @@ void DeviceTab::initUI()

ui->Net_localPortEdit->setValidator(m_netPortValidator);
ui->Net_remotePortEdit->setValidator(m_netPortValidator);

QScroller::grabGesture(ui->BLEC_argsScrollArea);
QScroller::grabGesture(ui->Net_argsScrollArea);
QScroller::grabGesture(ui->SP_portList);
QScroller::grabGesture(ui->BTServer_deviceList);
QScroller::grabGesture(ui->BTClient_deviceList);
QScroller::grabGesture(ui->BLEC_deviceList);
QScroller::grabGesture(ui->BLEC_UUIDList);
QScroller::grabGesture(ui->Net_addrPortList);
}

void DeviceTab::getAvailableTypes(bool useFirstValid)
Expand Down Expand Up @@ -1736,3 +1727,31 @@ void DeviceTab::on_BTClient_serviceUUIDBox_clicked()
ui->BTClient_tipLabel->setVisible(!userSpecifiedUUID);
}

void DeviceTab::setTouchScroll(bool enabled)
{
if(enabled)
{

QScroller::grabGesture(ui->BLEC_argsScrollArea);
QScroller::grabGesture(ui->Net_argsScrollArea);
QScroller::grabGesture(ui->SP_portList);
QScroller::grabGesture(ui->BTServer_deviceList);
QScroller::grabGesture(ui->BTClient_deviceList);
QScroller::grabGesture(ui->BLEC_deviceList);
QScroller::grabGesture(ui->BLEC_UUIDList);
QScroller::grabGesture(ui->Net_addrPortList);
}
else
{

QScroller::ungrabGesture(ui->BLEC_argsScrollArea);
QScroller::ungrabGesture(ui->Net_argsScrollArea);
QScroller::ungrabGesture(ui->SP_portList);
QScroller::ungrabGesture(ui->BTServer_deviceList);
QScroller::ungrabGesture(ui->BTClient_deviceList);
QScroller::ungrabGesture(ui->BLEC_deviceList);
QScroller::ungrabGesture(ui->BLEC_UUIDList);
QScroller::ungrabGesture(ui->Net_addrPortList);

}
}
1 change: 1 addition & 0 deletions src/devicetab.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public slots:
void Net_onDeleteButtonClicked();
void syncUDPPreference();
void syncTCPClientPreference();
void setTouchScroll(bool enabled);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(settingsTab, &SettingsTab::themeChanged, this, &MainWindow::onThemeChanged);
connect(settingsTab, &SettingsTab::opacityChanged, this, &MainWindow::onOpacityChanged); // not a slot function, but works fine.
connect(settingsTab, &SettingsTab::fullScreenStateChanged, this, &MainWindow::setFullScreen);
connect(settingsTab, &SettingsTab::TouchScrollStateChanged, deviceTab, &DeviceTab::setTouchScroll);
connect(settingsTab, &SettingsTab::TouchScrollStateChanged, ctrlTab, &CtrlTab::setTouchScroll);
connect(settingsTab, &SettingsTab::TouchScrollStateChanged, settingsTab, &SettingsTab::setTouchScroll);
connect(settingsTab, &SettingsTab::updateAvailableDeviceTypes, deviceTab, &DeviceTab::getAvailableTypes);
connect(settingsTab, &SettingsTab::themeChanged, plotTab, &PlotTab::onThemeChanged);
connect(settingsTab, &SettingsTab::recordDataChanged, dataTab, &DataTab::onRecordDataChanged);
Expand Down
24 changes: 22 additions & 2 deletions src/settingstab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ SettingsTab::SettingsTab(QWidget *parent) :

// APP_VERSION is defined in the .pro file
ui->versionLabel->setText(APP_VERSION);

QScroller::grabGesture(ui->scrollArea);
}

SettingsTab::~SettingsTab()
Expand Down Expand Up @@ -97,6 +95,7 @@ void SettingsTab::initSettings()
connect(ui->Android_fullScreenBox, &QCheckBox::clicked, this, &SettingsTab::savePreference);
connect(ui->Android_forceLandscapeBox, &QCheckBox::clicked, this, &SettingsTab::savePreference);
connect(ui->Android_dockBox, &QCheckBox::clicked, this, &SettingsTab::savePreference);
connect(ui->General_touchScrollBox, &QCheckBox::clicked, this, &SettingsTab::savePreference);
// Android_HWSerialBox will handle the preference itself.
connect(ui->Opacity_Box, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsTab::savePreference);
connect(ui->Data_recordDataBox, &QCheckBox::clicked, this, &SettingsTab::savePreference);
Expand Down Expand Up @@ -167,6 +166,12 @@ void SettingsTab::on_Android_fullScreenBox_clicked()
emit fullScreenStateChanged(ui->Android_fullScreenBox->isChecked());
}


void SettingsTab::on_General_touchScrollBox_clicked()
{
emit TouchScrollStateChanged(ui->General_touchScrollBox->isChecked());
}

void SettingsTab::savePreference()
{
if(m_settings->group() != "")
Expand All @@ -179,6 +184,7 @@ void SettingsTab::savePreference()
#else
m_settings->setValue("Opacity", ui->Opacity_Box->value());
#endif
m_settings->setValue("TouchScroll", ui->General_touchScrollBox->isChecked());
m_settings->endGroup();
// Android_HWSerialBox will handle the preference itself.
m_settings->beginGroup("SerialTest_Data");
Expand All @@ -199,6 +205,7 @@ void SettingsTab::loadPreference()
ui->Android_fullScreenBox->setChecked(m_settings->value("Android_FullScreen", false).toBool());
ui->Android_forceLandscapeBox->setChecked(m_settings->value("Android_ForceLandscape", true).toBool());
ui->Android_dockBox->setChecked(m_settings->value("Android_Dock", false).toBool());
ui->General_touchScrollBox->setChecked(m_settings->value("TouchScroll", true).toBool());
ui->Opacity_Box->setValue(m_settings->value("Opacity", 100).toInt());
ui->General_simultaneousClearBox->setChecked(m_settings->value("ClearBothRxDataAndGraph", false).toBool());
int themeId = ui->Theme_nameBox->findData(m_settings->value("Theme_Name", "(none)").toString());
Expand Down Expand Up @@ -248,6 +255,7 @@ void SettingsTab::loadPreference()
#else
on_Opacity_Box_valueChanged(ui->Opacity_Box->value());
#endif
on_General_touchScrollBox_clicked();
on_Theme_setButton_clicked();
on_Data_recordDataBox_clicked();
on_Data_mergeTimestampBox_clicked();
Expand Down Expand Up @@ -394,3 +402,15 @@ void SettingsTab::on_General_simultaneousClearBox_clicked()
emit clearBehaviorChanged(clearBoth);
}


void SettingsTab::setTouchScroll(bool enabled)
{
if(enabled)
{
QScroller::grabGesture(ui->scrollArea);
}
else
{
QScroller::ungrabGesture(ui->scrollArea);
}
}
5 changes: 5 additions & 0 deletions src/settingstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class SettingsTab : public QWidget
~SettingsTab();

void initSettings();
public slots:
void setTouchScroll(bool enabled);
private slots:
void on_Opacity_Box_valueChanged(int arg1);

Expand Down Expand Up @@ -62,6 +64,8 @@ private slots:

void on_General_simultaneousClearBox_clicked();

void on_General_touchScrollBox_clicked();

private:
Ui::SettingsTab *ui;
MySettings* m_settings;
Expand All @@ -71,6 +75,7 @@ private slots:
void opacityChanged(qreal value);
void fontChanged(QFont font);
void fullScreenStateChanged(bool isFullScreen);
void TouchScrollStateChanged(bool enabled);
// keep the default parameter the same as DeviceTab::getAvailableTypes()
void updateAvailableDeviceTypes(bool useFirstValid = false);
void recordDataChanged(bool enabled);
Expand Down
7 changes: 7 additions & 0 deletions src/ui/settingstab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ If no config file is detected, This app will create one in the current working d
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="General_touchScrollBox">
<property name="text">
<string>Respond to Touch Scroll Events</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit fda6389

Please sign in to comment.