mirror-kde-plasma-desktop/kcms/touchpad/kcm/xlib/touchpadconfigxlib.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

334 lines
9.9 KiB
C++
Raw Normal View History

2013-07-31 13:43:58 -08:00
/*
2021-05-20 21:53:47 -08:00
SPDX-FileCopyrightText: 2013 Alexander Mezin <mezin.alexander@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
2013-07-31 13:43:58 -08:00
#include "touchpadconfigxlib.h"
2013-07-14 08:03:02 -08:00
#include <QDBusInterface>
#include <QScrollArea>
#include <QTabWidget>
2013-07-14 08:03:02 -08:00
2013-08-01 15:55:48 -08:00
#include <KAboutData>
#include <KConfigGroup>
2013-07-14 08:03:02 -08:00
#include <KLocalizedString>
#include <KMessageWidget>
#include <KNotifyConfigWidget>
2013-12-24 12:22:27 -09:00
#include <KShortcutsDialog>
#include <QAction>
2013-07-14 08:03:02 -08:00
#include "../touchpadconfigcontainer.h"
#include "actions.h"
2013-12-21 08:35:06 -09:00
#include "customconfigdialogmanager.h"
#include "customslider.h"
2013-07-21 12:11:10 -08:00
#include "sliderpair.h"
2013-07-14 08:03:02 -08:00
#include "touchpadbackend.h"
#include "touchpadinterface.h"
2013-07-14 08:03:02 -08:00
#include "plasma_version.h"
void TouchpadConfigXlib::kcmInit()
{
TouchpadParameters::setSystemDefaults();
touchpadApplySavedConfig();
}
static void copyHelpFromBuddy(QObject *root)
{
QLabel *asLabel = qobject_cast<QLabel *>(root);
if (asLabel && asLabel->buddy()) {
if (asLabel->toolTip().isEmpty()) {
asLabel->setToolTip(asLabel->buddy()->toolTip());
}
if (asLabel->statusTip().isEmpty()) {
asLabel->setStatusTip(asLabel->buddy()->statusTip());
}
if (asLabel->whatsThis().isEmpty()) {
asLabel->setWhatsThis(asLabel->buddy()->whatsThis());
}
}
const auto childList = root->children();
for (QObject *child : childList) {
copyHelpFromBuddy(child);
}
}
template<typename T>
QWidget *addTab(QTabWidget *tabs, T &form)
{
QScrollArea *container = new QScrollArea(tabs);
container->setWidgetResizable(true);
container->setFrameStyle(QFrame::NoFrame);
container->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
2013-07-21 12:08:59 -08:00
QWidget *widget = new QWidget(container);
form.setupUi(widget);
copyHelpFromBuddy(widget);
widget->setContentsMargins(20, 20, 20, 20);
widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
container->setWidget(widget);
tabs->addTab(container, widget->windowTitle());
2013-12-24 12:22:27 -09:00
return widget;
}
TouchpadConfigXlib::TouchpadConfigXlib(TouchpadConfigContainer *parent, TouchpadBackend *backend)
: TouchpadConfigPlugin(parent, backend)
2013-12-22 11:05:29 -09:00
, m_configOutOfSync(false)
2013-07-14 08:03:02 -08:00
{
2013-09-15 09:42:03 -08:00
QGridLayout *layout = new QGridLayout(this);
2013-12-22 11:05:29 -09:00
QVBoxLayout *messageLayout = new QVBoxLayout();
layout->addLayout(messageLayout, 0, 0, 1, 2);
2013-12-26 18:37:17 -09:00
// Messages
m_errorMessage = new KMessageWidget(this);
m_errorMessage->setMessageType(KMessageWidget::Error);
m_errorMessage->setVisible(false);
m_errorMessage->setWordWrap(true);
2013-12-22 11:05:29 -09:00
messageLayout->addWidget(m_errorMessage);
m_configOutOfSyncMessage = new KMessageWidget(this);
m_configOutOfSyncMessage->setMessageType(KMessageWidget::Warning);
m_configOutOfSyncMessage->setText(
i18n("Active settings don't match saved settings.\n"
"You currently see saved settings."));
m_configOutOfSyncMessage->setVisible(false);
messageLayout->addWidget(m_configOutOfSyncMessage);
m_loadActiveConfiguration = new QAction(m_configOutOfSyncMessage);
2013-12-22 11:05:29 -09:00
m_loadActiveConfiguration->setText(i18n("Show active settings"));
connect(m_loadActiveConfiguration, SIGNAL(triggered()), SLOT(loadActiveConfig()));
m_configOutOfSyncMessage->addAction(m_loadActiveConfiguration);
2013-12-15 09:49:38 -09:00
layout->setColumnStretch(0, 3);
layout->setColumnStretch(1, 1);
2013-12-26 18:37:17 -09:00
// Main UI
m_tabs = new QTabWidget(this);
2013-12-26 18:37:17 -09:00
layout->addWidget(m_tabs, 1, 0, 1, 1);
2013-12-24 12:22:27 -09:00
addTab(m_tabs, m_tapping);
addTab(m_tabs, m_scrolling);
addTab(m_tabs, m_pointerMotion);
addTab(m_tabs, m_sensitivity);
static const CustomSlider::SqrtInterpolator interpolator;
m_pointerMotion.kcfg_MinSpeed->setInterpolator(&interpolator);
m_pointerMotion.kcfg_MaxSpeed->setInterpolator(&interpolator);
m_pointerMotion.kcfg_AccelFactor->setInterpolator(&interpolator);
2013-07-15 14:46:31 -08:00
new SliderPair(m_pointerMotion.kcfg_MinSpeed, m_pointerMotion.kcfg_MaxSpeed, this);
2013-07-29 20:33:22 -08:00
new SliderPair(m_sensitivity.kcfg_FingerLow, m_sensitivity.kcfg_FingerHigh, this);
2013-07-31 17:54:00 -08:00
new SliderPair(m_pointerMotion.kcfg_PressureMotionMinZ, m_pointerMotion.kcfg_PressureMotionMaxZ, this);
2013-07-21 12:11:10 -08:00
2013-12-21 08:35:06 -09:00
m_manager = new CustomConfigDialogManager(this, &m_config, m_backend->supportedParameters());
connect(m_manager, SIGNAL(widgetModified()), SLOT(checkChanges()), Qt::QueuedConnection);
2013-12-22 11:05:29 -09:00
2013-12-26 18:37:17 -09:00
// KDED settings
m_kdedTab = addTab(m_tabs, m_kded);
m_daemonConfigManager = m_parent->addConfig(&m_daemonSettings, m_kdedTab);
2013-12-26 18:37:17 -09:00
KMessageWidget *kdedMessage = new KMessageWidget(m_kdedTab);
kdedMessage->setMessageType(KMessageWidget::Information);
kdedMessage->setCloseButtonVisible(false);
kdedMessage->setText(i18n("These settings won't take effect in the testing area"));
qobject_cast<QVBoxLayout *>(m_kdedTab->layout())->insertWidget(0, kdedMessage);
connect(m_kded.configureNotificationsButton, SIGNAL(clicked()), SLOT(showConfigureNotificationsDialog()));
2013-12-26 18:37:17 -09:00
m_shortcutsDialog.reset(new KShortcutsDialog(KShortcutsEditor::GlobalAction, KShortcutsEditor::LetterShortcutsDisallowed));
m_shortcutsDialog->addCollection(new TouchpadGlobalActions(true, this), i18n("Enable/Disable Touchpad"));
connect(m_kded.configureShortcutsButton, &QPushButton::clicked, this, [this]() {
m_shortcutsDialog->configure(true);
});
2013-12-26 18:37:17 -09:00
m_mouseCombo = new KComboBox(true, m_kded.kcfg_MouseBlacklist);
m_kded.kcfg_MouseBlacklist->setCustomEditor(m_mouseCombo);
connect(m_backend, SIGNAL(mousesChanged()), SLOT(updateMouseList()));
m_backend->watchForEvents(false);
updateMouseList();
2023-06-27 12:06:29 -08:00
m_daemon = new OrgKdeTouchpadInterface("org.kde.kded6", "/modules/kded_touchpad", QDBusConnection::sessionBus(), this);
m_kdedTab->setEnabled(false);
QDBusPendingCallWatcher *watch;
watch = new QDBusPendingCallWatcher(m_daemon->workingTouchpadFound(), this);
// clang-format off
connect(watch, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(gotReplyFromDaemon(QDBusPendingCallWatcher*)));
// clang-format on
2013-12-26 18:37:17 -09:00
// Testing area
m_testArea = new TestArea(this);
layout->addWidget(m_testArea, 1, 1);
connect(m_testArea, SIGNAL(enter()), SLOT(beginTesting()));
connect(m_testArea, SIGNAL(leave()), SLOT(endTesting()));
connect(m_tabs, SIGNAL(currentChanged(int)), SLOT(updateTestAreaEnabled()));
updateTestAreaEnabled();
2013-07-14 08:03:02 -08:00
}
void TouchpadConfigXlib::gotReplyFromDaemon(QDBusPendingCallWatcher *watch)
{
QDBusPendingReply<bool> reply = *watch;
if (reply.isValid() && reply.value()) {
m_kdedTab->setEnabled(true);
}
watch->deleteLater();
}
void TouchpadConfigXlib::updateMouseList()
{
const QStringList mouses(m_backend->listMouses(m_daemonSettings.mouseBlacklist()));
for (int i = 0; i < m_mouseCombo->count();) {
if (!mouses.contains(m_mouseCombo->itemText(i))) {
m_mouseCombo->removeItem(i);
} else {
i++;
}
}
for (const QString &device : mouses) {
if (!m_mouseCombo->contains(device)) {
m_mouseCombo->addItem(device);
}
}
}
QVariantHash TouchpadConfigXlib::getActiveConfig()
2013-12-22 11:05:29 -09:00
{
if (m_prevConfig) {
return *m_prevConfig;
}
QVariantHash activeConfig;
if (!m_backend->getConfig(activeConfig)) {
m_errorMessage->setText(m_backend->errorString());
QMetaObject::invokeMethod(m_errorMessage, "animatedShow", Qt::QueuedConnection);
2013-12-22 11:05:29 -09:00
}
return activeConfig;
}
void TouchpadConfigXlib::loadActiveConfig()
2013-12-22 11:05:29 -09:00
{
m_manager->setWidgetProperties(getActiveConfig());
m_configOutOfSync = false;
m_configOutOfSyncMessage->animatedHide();
2013-12-22 11:05:29 -09:00
}
void TouchpadConfigXlib::load()
2013-12-21 08:35:06 -09:00
{
m_manager->updateWidgets();
m_parent->kcmLoad();
2013-12-22 11:05:29 -09:00
m_configOutOfSync = !m_manager->compareWidgetProperties(getActiveConfig());
2013-12-21 08:35:06 -09:00
}
void TouchpadConfigXlib::save()
2013-07-14 08:03:02 -08:00
{
2013-12-21 08:35:06 -09:00
m_manager->updateSettings();
m_configOutOfSync = false;
m_configOutOfSyncMessage->animatedHide();
2013-12-22 11:05:29 -09:00
bool daemonSettingsChanged = m_daemonConfigManager->hasChanged();
m_parent->kcmSave();
2013-07-14 08:03:02 -08:00
if (m_backend->applyConfig(m_config.values())) {
m_errorMessage->animatedHide();
} else {
m_errorMessage->setText(m_backend->errorString());
m_errorMessage->animatedShow();
}
if (daemonSettingsChanged) {
m_daemon->reloadSettings();
updateMouseList();
}
}
void TouchpadConfigXlib::defaults()
2013-12-21 08:35:06 -09:00
{
m_manager->updateWidgetsDefault();
m_parent->kcmDefaults();
2013-12-21 08:35:06 -09:00
}
void TouchpadConfigXlib::checkChanges()
2013-12-21 08:35:06 -09:00
{
if (!m_backend->touchpadCount()) {
return;
}
m_parent->unmanagedWidgetChangeState(m_manager->hasChangedFuzzy() || m_configOutOfSync);
if (m_configOutOfSync) {
m_configOutOfSyncMessage->animatedShow();
} else {
m_configOutOfSyncMessage->animatedHide();
}
2013-12-21 08:35:06 -09:00
}
void TouchpadConfigXlib::hideEvent(QHideEvent *e)
2013-09-15 09:42:03 -08:00
{
Q_UNUSED(e);
2013-09-15 09:42:03 -08:00
endTesting();
}
TouchpadConfigXlib::~TouchpadConfigXlib()
2013-09-16 20:57:03 -08:00
{
endTesting();
}
void TouchpadConfigXlib::onChanged()
2013-09-16 20:57:03 -08:00
{
if (m_testArea->underMouse()) {
beginTesting();
}
}
void TouchpadConfigXlib::beginTesting()
2013-09-15 09:42:03 -08:00
{
2013-09-16 20:57:03 -08:00
if (!m_prevConfig) {
m_prevConfig.reset(new QVariantHash());
2022-05-31 07:51:15 -08:00
m_backend->getConfig(*m_prevConfig.get());
2013-09-16 20:57:03 -08:00
}
2013-12-21 08:35:06 -09:00
m_backend->applyConfig(m_manager->currentWidgetProperties());
2013-09-15 09:42:03 -08:00
}
void TouchpadConfigXlib::endTesting()
2013-09-15 09:42:03 -08:00
{
if (!m_prevConfig) {
return;
}
2022-05-31 07:51:15 -08:00
m_backend->applyConfig(*m_prevConfig.get());
2013-09-15 09:42:03 -08:00
m_prevConfig.reset();
}
2013-12-24 12:22:27 -09:00
void TouchpadConfigXlib::updateTestAreaEnabled()
2013-12-24 12:22:27 -09:00
{
bool enable = true;
for (QWidget *i = m_kdedTab; i; i = i->parentWidget()) {
if (i == m_tabs->currentWidget()) {
enable = false;
break;
}
}
m_testArea->setEnabled(enable);
m_testArea->setMouseTracking(enable);
if (!enable) {
endTesting();
}
}
void TouchpadConfigXlib::showConfigureNotificationsDialog()
{
KNotifyConfigWidget *widget = KNotifyConfigWidget::configure(nullptr, QStringLiteral("kcm_touchpad"));
QDialog *dialog = qobject_cast<QDialog *>(widget->topLevelWidget());
connect(dialog, SIGNAL(finished()), dialog, SLOT(deleteLater()));
}