feat(settings): add touchscreen page

main
reionwong 1 month ago
parent d972020d3f
commit b14e02844a

@ -52,6 +52,7 @@ set(SRCS
src/datetime/timezonemap.cpp
src/datetime/timedated_interface.cpp
src/touchpad.cpp
src/touchscreen.cpp
src/shortcuts/shortcutsmodel.cpp
src/vpn/vpn.cpp
src/vpn/nm-l2tp-service.h

@ -24,6 +24,7 @@
#include "mock/networkmockmodel.h"
#include "settingsuiadaptor.h"
#include "touchpad.h"
#include "touchscreen.h"
#include "shortcuts/shortcutsmodel.h"
#include "thumbnailprovider.h"
@ -93,6 +94,7 @@ Application::Application(int &argc, char **argv)
qmlRegisterType<Time>(uri, 1, 0, "Time");
qmlRegisterType<TimeZoneMap>(uri, 1, 0, "TimeZoneMap");
qmlRegisterType<Touchpad>(uri, 1, 0, "Touchpad");
qmlRegisterType<Touchscreen>(uri, 1, 0, "Touchscreen");
qmlRegisterType<ShortcutsModel>(uri, 1, 0, "ShortcutsModel");
qmlRegisterType<NetworkProxy>(uri, 1, 0, "NetworkProxy");
qmlRegisterType<Notifications>(uri, 1, 0, "Notifications");

@ -0,0 +1,4 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M2 2H14A1 1 0 0 1 15 3V13A1 1 0 0 1 14 14H2A1 1 0 0 1 1 13V3A1 1 0 0 1 2 2ZM2.5 3A0.5 0.5 0 0 0 2 3.5V12.5A0.5 0.5 0 0 0 2.5 13H13.5A0.5 0.5 0 0 0 14 12.5V3.5A0.5 0.5 0 0 0 13.5 3Z" fill="#fff" fill-rule="evenodd"/>
<path d="M8 5.5A2.5 2.5 0 1 1 8 10.5A2.5 2.5 0 1 1 8 5.5Z" fill="#fff"/>
</svg>

After

Width:  |  Height:  |  Size: 405 B

@ -331,6 +331,16 @@ Item {
keywords: qsTr("trackpad, tap to click, natural scrolling, secondary click, pointer speed")
}
ListElement {
title: qsTr("Touchscreen")
name: "touchscreen"
page: "qrc:/qml/Touchscreen/Main.qml"
iconSource: "touchscreen.svg"
iconColor: "#999999"
category: qsTr("Devices")
keywords: qsTr("touch, touch screen, touch panel")
}
ListElement {
title: qsTr("Users")
name: "accounts"
@ -882,4 +892,13 @@ Item {
removeItem("touchpad")
}
}
Touchscreen {
id: _touchscreen
Component.onCompleted: {
if (!_touchscreen.available)
removeItem("touchscreen")
}
}
}

@ -0,0 +1,48 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import FishUI 1.0 as FishUI
import Cutefish.Settings 1.0
import "../"
ItemPage {
headerTitle: qsTr("Touchscreen")
Touchscreen {
id: touchscreen
}
Scrollable {
anchors.fill: parent
contentHeight: layout.implicitHeight
ColumnLayout {
id: layout
anchors.fill: parent
spacing: Metrics.sectionSpacing
ListCard {
visible: touchscreen.available
Repeater {
model: touchscreen.devices
ListRow {
required property string modelData
interactive: false
text: modelData
FishUI.Switch {
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
checked: touchscreen.disabledDevices.indexOf(modelData) < 0
rightPadding: 0
rightInset: 0
onToggled: touchscreen.setDeviceEnabled(modelData, checked)
}
}
}
}
}
}
}

@ -99,12 +99,14 @@
<file>images/sidebar/dark/datetime.svg</file>
<file>qml/Update/Main.qml</file>
<file>qml/Touchpad/Main.qml</file>
<file>qml/Touchscreen/Main.qml</file>
<file>qml/Shortcuts/Main.qml</file>
<file>qml/Shortcuts/ShortcutRow.qml</file>
<file>qml/Shortcuts/ShortcutKeys.qml</file>
<file>qml/Shortcuts/ShortcutEditDialog.qml</file>
<file>images/sidebar/dark/keyboard.svg</file>
<file>images/sidebar/dark/touchpad.svg</file>
<file>images/sidebar/dark/touchscreen.svg</file>
<file>images/logo.png</file>
<file>qml/Bluetooth/DeviceItem.qml</file>
<file>qml/Bluetooth/DeviceSection.qml</file>

@ -0,0 +1,77 @@
#include "touchscreen.h"
#include <QDBusPendingCall>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QDBusServiceWatcher>
#include <QDebug>
namespace {
constexpr auto service = "com.cutefish.Touchscreen1";
constexpr auto path = "/com/cutefish/Touchscreen1";
} // namespace
Touchscreen::Touchscreen(QObject *parent)
: QObject(parent)
{
auto *watcher = new QDBusServiceWatcher(QLatin1String(service), QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForOwnerChange, this);
connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, this,
&Touchscreen::refreshInterface);
refreshInterface();
}
void Touchscreen::refreshInterface()
{
delete m_interface;
m_interface = new QDBusInterface(QLatin1String(service), QLatin1String(path),
QLatin1String(service), QDBusConnection::sessionBus(), this);
if (m_interface->isValid()) {
connect(m_interface, SIGNAL(devicesChanged()), this, SIGNAL(devicesChanged()));
connect(m_interface, SIGNAL(disabledDevicesChanged()), this,
SIGNAL(disabledDevicesChanged()));
}
notifyChanged();
}
void Touchscreen::notifyChanged()
{
emit devicesChanged();
emit disabledDevicesChanged();
}
QStringList Touchscreen::list(const char *name) const
{
return m_interface->isValid() ? m_interface->property(name).toStringList() : QStringList();
}
bool Touchscreen::available() const
{
return !devices().isEmpty();
}
QStringList Touchscreen::devices() const
{
return list("devices");
}
QStringList Touchscreen::disabledDevices() const
{
return list("disabledDevices");
}
void Touchscreen::setDeviceEnabled(const QString &name, bool enabled)
{
if (!m_interface->isValid())
return;
auto *watcher = new QDBusPendingCallWatcher(
m_interface->asyncCall(QStringLiteral("setDeviceEnabled"), name, enabled), this);
connect(watcher, &QDBusPendingCallWatcher::finished, this,
[this](QDBusPendingCallWatcher *reply) {
const QDBusPendingReply<> result = *reply;
if (result.isError()) {
qWarning() << "Cannot update touchscreen setting" << result.error().message();
notifyChanged();
}
reply->deleteLater();
});
}

@ -0,0 +1,35 @@
#ifndef TOUCHSCREEN_H
#define TOUCHSCREEN_H
#include <QDBusInterface>
#include <QObject>
#include <QStringList>
class Touchscreen : public QObject
{
Q_OBJECT
Q_PROPERTY(bool available READ available NOTIFY devicesChanged)
Q_PROPERTY(QStringList devices READ devices NOTIFY devicesChanged)
Q_PROPERTY(QStringList disabledDevices READ disabledDevices NOTIFY disabledDevicesChanged)
public:
explicit Touchscreen(QObject *parent = nullptr);
bool available() const;
QStringList devices() const;
QStringList disabledDevices() const;
Q_INVOKABLE void setDeviceEnabled(const QString &name, bool enabled);
signals:
void devicesChanged();
void disabledDevicesChanged();
private:
void refreshInterface();
void notifyChanged();
QStringList list(const char *name) const;
QDBusInterface *m_interface = nullptr;
};
#endif // TOUCHSCREEN_H
Loading…
Cancel
Save