/**
* cadMousePro
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QLabel>
#include <QPushButton>
#include "MouseMainWindow.h"
MouseMainWindow::MouseMainWindow() {
proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this);
setWindowTitle("cadMousePro");
initStatusPanel();
initConfigurationPanel();
initAboutPanel();
setCentralWidget(tabs);
refresh();
}
void MouseMainWindow::initStatusPanel() {
QWidget* panel = new QWidget(this);
QFormLayout* layout = new QFormLayout(panel);
int f = 0;
statusProxy->setEnabled(false);
statusUPower->setEnabled(false);
statusDevice->setEnabled(false);
layout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
layout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
layout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
QPushButton* refreshButton = new QPushButton("Refresh", panel);
layout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh);
tabs->addTab(panel, "Status");
}
void MouseMainWindow::initConfigurationPanel() {
QWidget* panel = new QWidget(this);
QFormLayout* layout = new QFormLayout(panel);
int f = 0;
configureLiftOffDetection->setChecked(true);
layout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
layout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
configureFrequency250->setChecked(true);
layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
QPushButton* configureButton = new QPushButton("Configure", panel);
configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration");
layout->setWidget(f++, QFormLayout::FieldRole, configureButton);
connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure);
message->setReadOnly(true);
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("Result:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, message);
tabs->addTab(panel, "Configuration");
}
void MouseMainWindow::initAboutPanel() {
QWidget* panel = new QWidget(this);
QFormLayout* layout = new QFormLayout(panel);
int f = 0;
layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Program name:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("cadMousePro", panel));
layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Description:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("configuration tool for 3DConnexion CadMouse Pro Wireless", panel));
layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Author:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("Ing. František Kučera, Frantovo.cz, GlobalCode.info", panel));
layout->setWidget(f, QFormLayout::LabelRole, new QLabel("License:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("GNU GPLv3+", panel));
layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Contact and support:", panel));
layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("https://mouse.globalcode.info/", panel));
tabs->addTab(panel, "About");
}
void MouseMainWindow::refresh() {
statusProxy->setChecked(proxy->isValid());
statusDevice->setChecked(proxy->devicePresent());
}
void MouseMainWindow::configure() {
message->setText("…");
int frequency; // TODO: get value from the group
if (configureFrequency125->isChecked()) frequency = 125;
else if (configureFrequency250->isChecked()) frequency = 250;
else if (configureFrequency500->isChecked()) frequency = 500;
else if (configureFrequency1000->isChecked()) frequency = 1000;
else frequency = 250;
auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency);
response.waitForFinished();
if (response.isError()) message->setText("Error: " + response.error().message());
else message->setText("mouse configured");
}