cadMousePro-gui/src/MouseMainWindow.cpp
branchv_0
changeset 17 d37c6dd9aa20
parent 16 2705911938b4
child 18 7323a89c15e9
equal deleted inserted replaced
16:2705911938b4 17:d37c6dd9aa20
    21 #include "MouseMainWindow.h"
    21 #include "MouseMainWindow.h"
    22 
    22 
    23 MouseMainWindow::MouseMainWindow() {
    23 MouseMainWindow::MouseMainWindow() {
    24 	proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this);
    24 	proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this);
    25 
    25 
    26 	resize(640, 480);
       
    27 	setWindowTitle("cadMousePro");
    26 	setWindowTitle("cadMousePro");
    28 	centralwidget = new QWidget(this);
    27 
    29 	formLayout = new QFormLayout(centralwidget);
    28 	initStatusPanel();
       
    29 	initConfigurationPanel();
       
    30 	initAboutPanel();
       
    31 
       
    32 	setCentralWidget(tabs);
       
    33 	refresh();
       
    34 }
       
    35 
       
    36 void MouseMainWindow::initStatusPanel() {
       
    37 	QWidget* panel = new QWidget(this);
       
    38 	QFormLayout* layout = new QFormLayout(panel);
    30 
    39 
    31 	int f = 0;
    40 	int f = 0;
    32 
       
    33 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("How does the mouse feel:", centralwidget));
       
    34 
    41 
    35 	statusProxy->setEnabled(false);
    42 	statusProxy->setEnabled(false);
    36 	statusUPower->setEnabled(false);
    43 	statusUPower->setEnabled(false);
    37 	statusDevice->setEnabled(false);
    44 	statusDevice->setEnabled(false);
    38 
    45 
    39 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
    46 	layout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
    40 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
    47 	layout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
    41 	formLayout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
    48 	layout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
    42 
    49 
    43 
    50 	QPushButton* refreshButton = new QPushButton("Refresh", panel);
    44 
    51 	layout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
    45 	QPushButton* refreshButton = new QPushButton("Refresh", this);
       
    46 	formLayout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
       
    47 	connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh);
    52 	connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh);
    48 
    53 
       
    54 	tabs->addTab(panel, "Status");
       
    55 }
    49 
    56 
       
    57 void MouseMainWindow::initConfigurationPanel() {
       
    58 	QWidget* panel = new QWidget(this);
       
    59 	QFormLayout* layout = new QFormLayout(panel);
    50 
    60 
    51 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Talk to your mouse:", centralwidget));
    61 	int f = 0;
    52 
    62 
    53 	configureLiftOffDetection->setChecked(true);
    63 	configureLiftOffDetection->setChecked(true);
    54 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
    64 	layout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
    55 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
    65 	layout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
    56 	configureFrequency250->setChecked(true);
    66 	configureFrequency250->setChecked(true);
    57 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
    67 	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
    58 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
    68 	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
    59 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
    69 	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
    60 	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
    70 	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
    61 
    71 
    62 	QPushButton* configureButton = new QPushButton("Configure", this);
    72 	QPushButton* configureButton = new QPushButton("Configure", panel);
    63 	configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration");
    73 	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);
    74 	layout->setWidget(f++, QFormLayout::FieldRole, configureButton);
    65 	connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure);
    75 	connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure);
    66 
    76 
       
    77 	message->setReadOnly(true);
       
    78 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("Result:", panel));
       
    79 	layout->setWidget(f++, QFormLayout::FieldRole, message);
    67 
    80 
    68 	message->setReadOnly(true);
    81 	tabs->addTab(panel, "Configuration");
    69 	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Mouse responds:", this));
    82 }
    70 	formLayout->setWidget(f++, QFormLayout::FieldRole, message);
       
    71 
    83 
    72 	setCentralWidget(centralwidget);
    84 void MouseMainWindow::initAboutPanel() {
    73 	refresh();
    85 	QWidget* panel = new QWidget(this);
       
    86 	QFormLayout* layout = new QFormLayout(panel);
       
    87 	
       
    88 	int f = 0;
       
    89 	
       
    90 	layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Program name:", panel));
       
    91 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("cadMousePro", panel));
       
    92 	
       
    93 	layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Description:", panel));
       
    94 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("configuration tool for 3DConnexion CadMouse Pro Wireless", panel));
       
    95 	
       
    96 	layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Author:", panel));
       
    97 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("Ing. František Kučera, Frantovo.cz, GlobalCode.info", panel));
       
    98 	
       
    99 	layout->setWidget(f, QFormLayout::LabelRole, new QLabel("License:", panel));
       
   100 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("GNU GPLv3+", panel));
       
   101 	
       
   102 	layout->setWidget(f, QFormLayout::LabelRole, new QLabel("Contact and support:", panel));
       
   103 	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("https://mouse.globalcode.info/", panel));
       
   104 	
       
   105 	tabs->addTab(panel, "About");
       
   106 	
    74 }
   107 }
    75 
   108 
    76 void MouseMainWindow::refresh() {
   109 void MouseMainWindow::refresh() {
    77 	statusProxy->setChecked(proxy->isValid());
   110 	statusProxy->setChecked(proxy->isValid());
    78 	statusDevice->setChecked(proxy->devicePresent());
   111 	statusDevice->setChecked(proxy->devicePresent());
    79 
   112 
    80 }
   113 }
    81 
   114 
    82 void MouseMainWindow::configure() {
   115 void MouseMainWindow::configure() {
       
   116 	message->setText("…");
       
   117 	
    83 	int frequency; // TODO: get value from the group
   118 	int frequency; // TODO: get value from the group
    84 	if (configureFrequency125->isChecked()) frequency = 125;
   119 	if (configureFrequency125->isChecked()) frequency = 125;
    85 	else if (configureFrequency250->isChecked()) frequency = 250;
   120 	else if (configureFrequency250->isChecked()) frequency = 250;
    86 	else if (configureFrequency500->isChecked()) frequency = 500;
   121 	else if (configureFrequency500->isChecked()) frequency = 500;
    87 	else if (configureFrequency1000->isChecked()) frequency = 1000;
   122 	else if (configureFrequency1000->isChecked()) frequency = 1000;
    88 	else frequency = 250;
   123 	else frequency = 250;
    89 	
   124 
    90 	auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency);
   125 	auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency);
    91 
   126 
    92 	response.waitForFinished();
   127 	response.waitForFinished();
    93 	if (response.isError()) message->setText("Error: " + response.error().message());
   128 	if (response.isError()) message->setText("Error: " + response.error().message());
    94 	else message->setText("mouse configured");
   129 	else message->setText("mouse configured");