File indexing completed on 2025-01-26 05:09:31

0001 /*
0002  * This file is part of the KDE wacomtablet project. For copyright
0003  * information and license terms see the AUTHORS and COPYING files
0004  * in the top-level directory of this distribution.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "pressurecurvedialog.h"
0021 #include "ui_pressurecurvedialog.h"
0022 
0023 #include "dbustabletinterface.h"
0024 #include "logging.h"
0025 #include "pressurecurvewidget.h"
0026 
0027 // Qt includes
0028 #include <QDBusInterface>
0029 #include <QDBusReply>
0030 
0031 using namespace Wacom;
0032 
0033 PressureCurveDialog::PressureCurveDialog(const QString &initialValue, const QString &tabletId, const DeviceType &deviceType, QWidget *parent)
0034     : QDialog(parent)
0035     , m_ui(new Ui::PressureCurveDialog)
0036     , _initialValue(initialValue)
0037     , _tabletId(tabletId)
0038     , _deviceType(deviceType.key())
0039 {
0040     m_ui->setupUi(this);
0041 
0042     connect(m_ui->pc_Widget, SIGNAL(controlPointsChanged(QString)), SLOT(updateControlPoints(QString)));
0043 
0044     setControllPoints(initialValue);
0045 }
0046 
0047 PressureCurveDialog::~PressureCurveDialog()
0048 {
0049     delete m_ui;
0050 }
0051 
0052 void PressureCurveDialog::setControllPoints(const QString &points)
0053 {
0054     QStringList splitPoints = points.split(QLatin1Char(' '));
0055 
0056     if (splitPoints.count() != 4) {
0057         qCDebug(KCM) << "Invalid number of control points, using defaults";
0058         splitPoints.insert(0, QLatin1String("0"));
0059         splitPoints.insert(1, QLatin1String("0"));
0060         splitPoints.insert(2, QLatin1String("100"));
0061         splitPoints.insert(3, QLatin1String("100"));
0062     }
0063 
0064     qreal p1 = splitPoints.at(0).toDouble();
0065     qreal p2 = splitPoints.at(1).toDouble();
0066     qreal p3 = splitPoints.at(2).toDouble();
0067     qreal p4 = splitPoints.at(3).toDouble();
0068     m_ui->pc_Widget->setControlPoints(p1, p2, p3, p4);
0069     m_ui->pc_Values->setText(QString::fromLatin1("%1 %2 %3 %4").arg(p1).arg(p2).arg(p3).arg(p4));
0070 }
0071 
0072 QString PressureCurveDialog::getControllPoints()
0073 {
0074     return m_ui->pc_Values->text();
0075 }
0076 
0077 void PressureCurveDialog::updateControlPoints(const QString &points)
0078 {
0079     m_ui->pc_Values->setText(points);
0080     DBusTabletInterface::instance().setProperty(_tabletId, _deviceType, Property::PressureCurve.key(), points);
0081 }
0082 
0083 void PressureCurveDialog::accept()
0084 {
0085     done(QDialog::Accepted);
0086 }
0087 void PressureCurveDialog::reject()
0088 {
0089     // Reset pressure curve to initial values
0090     DBusTabletInterface::instance().setProperty(_tabletId, _deviceType, Property::PressureCurve.key(), _initialValue);
0091 
0092     done(QDialog::Rejected);
0093 }
0094 
0095 #include "moc_pressurecurvedialog.cpp"