cadMousePro-gui/src/MouseMainWindow.cpp
branchv_0
changeset 16 2705911938b4
child 17 d37c6dd9aa20
equal deleted inserted replaced
15:00783e323e66 16:2705911938b4
       
     1 /**
       
     2  * cadMousePro
       
     3  * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, either version 3 of the License, or
       
     8  * (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17  */
       
    18 #include <QLabel>
       
    19 #include <QPushButton>
       
    20 
       
    21 #include "MouseMainWindow.h"
       
    22 
       
    23 MouseMainWindow::MouseMainWindow() {
       
    24 	proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this);
       
    25 
       
    26 	resize(640, 480);
       
    27 	setWindowTitle("cadMousePro");
       
    28 	centralwidget = new QWidget(this);
       
    29 	formLayout = new QFormLayout(centralwidget);
       
    30 
       
    31 	int f = 0;
       
    32 
       
    33 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("How does the mouse feel:", centralwidget));
       
    34 
       
    35 	statusProxy->setEnabled(false);
       
    36 	statusUPower->setEnabled(false);
       
    37 	statusDevice->setEnabled(false);
       
    38 
       
    39 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
       
    40 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
       
    41 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
       
    42 
       
    43 
       
    44 
       
    45 	QPushButton* refreshButton = new QPushButton("Refresh", this);
       
    46 	formLayout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
       
    47 	connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh);
       
    48 
       
    49 
       
    50 
       
    51 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Talk to your mouse:", centralwidget));
       
    52 
       
    53 	configureLiftOffDetection->setChecked(true);
       
    54 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
       
    55 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
       
    56 	configureFrequency250->setChecked(true);
       
    57 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
       
    58 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
       
    59 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
       
    60 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
       
    61 
       
    62 	QPushButton* configureButton = new QPushButton("Configure", this);
       
    63 	configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration");
       
    64 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureButton);
       
    65 	connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure);
       
    66 
       
    67 
       
    68 	message->setReadOnly(true);
       
    69 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Mouse responds:", this));
       
    70 	formLayout->setWidget(f++, QFormLayout::FieldRole, message);
       
    71 
       
    72 	setCentralWidget(centralwidget);
       
    73 	refresh();
       
    74 }
       
    75 
       
    76 void MouseMainWindow::refresh() {
       
    77 	statusProxy->setChecked(proxy->isValid());
       
    78 	statusDevice->setChecked(proxy->devicePresent());
       
    79 
       
    80 }
       
    81 
       
    82 void MouseMainWindow::configure() {
       
    83 	int frequency; // TODO: get value from the group
       
    84 	if (configureFrequency125->isChecked()) frequency = 125;
       
    85 	else if (configureFrequency250->isChecked()) frequency = 250;
       
    86 	else if (configureFrequency500->isChecked()) frequency = 500;
       
    87 	else if (configureFrequency1000->isChecked()) frequency = 1000;
       
    88 	else frequency = 250;
       
    89 	
       
    90 	auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency);
       
    91 
       
    92 	response.waitForFinished();
       
    93 	if (response.isError()) message->setText("Error: " + response.error().message());
       
    94 	else message->setText("mouse configured");
       
    95 
       
    96 }