SOURCES += main.cpp\
- MenuPrincipal.cpp
+ MenuPrincipal.cpp \
+ Options.cpp
-HEADERS += MenuPrincipal.h
+HEADERS += MenuPrincipal.h \
+ Options.h
-FORMS += menuprincipal.ui
+FORMS += menuprincipal.ui \
+ options.ui
#include "MenuPrincipal.h"
#include "ui_menuprincipal.h"
+#include <QDebug>
+
MenuPrincipal::MenuPrincipal(QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::MenuPrincipal)
+ ui(new Ui::MenuPrincipal),
+ options(this)
{
ui->setupUi(this);
+
+ connect(ui->options, SIGNAL(clicked()), this, SLOT(openOptions()));
+
+ connectKeyboard();
+ connectScreen();
+ connectMouse();
}
MenuPrincipal::~MenuPrincipal()
{
+ disconnectMouse();
+ disconnectKeyboard();
+ disconnectScreen();
delete ui;
}
+
+void MenuPrincipal::connectMouse()
+{
+ qDebug("Connect mouse");
+ try
+ {
+ //The mouse may require a little time because of calibration (blocking process)
+ _mouse = new XYPlotter();
+ _mouse->calibrate();
+ options.enableMouse();
+ }
+ catch (ErrorMessage e)
+ {
+ options.disableMouse();
+ _mouse = NULL;
+ qDebug() << QString(e.what());
+ }
+}
+
+void MenuPrincipal::connectKeyboard()
+{
+ qDebug() << "Connect keyboard";
+ try
+ {
+ _keyboard = new LivingKeyboard();
+ _keyboard->calibrate();
+ options.enableKeyboard();
+ }
+ catch (ErrorMessage e)
+ {
+ options.disableKeyboard();
+ _keyboard = NULL;
+ qDebug() << QString(e.what());
+ }
+}
+
+void MenuPrincipal::connectScreen()
+{
+ qDebug("Connect screen");
+ try
+ {
+ //The screen may require a little time because of calibration (blocking process)
+ _screen = new LivingScreen();
+ _screen->calibrate();
+ options.enableScreen();
+ }
+ catch (ErrorMessage e)
+ {
+ options.disableScreen();
+ _screen = NULL;
+ qDebug() << QString(e.what());
+ }
+}
+
+void MenuPrincipal::calibrateMouse()
+{
+ if (_mouse)
+ _mouse->calibrate();
+}
+
+void MenuPrincipal::calibrateKeyboard()
+{
+ if (_keyboard)
+ _keyboard->calibrate();
+}
+
+void MenuPrincipal::calibrateScreen()
+{
+ if (_screen)
+ _screen->calibrate();
+}
+
+void MenuPrincipal::resetMouse()
+{
+ disconnectMouse();
+ connectMouse();
+ calibrateMouse();
+}
+
+void MenuPrincipal::resetKeyboard()
+{
+ disconnectKeyboard();
+ connectKeyboard();
+ calibrateKeyboard();
+}
+
+void MenuPrincipal::resetScreen()
+{
+ disconnectScreen();
+ connectScreen();
+ calibrateScreen();
+}
+
+void MenuPrincipal::disconnectMouse()
+{
+ if (_mouse)
+ {
+ _mouse->moveTo(0, 0, false);
+ delete _mouse;
+ _mouse = NULL;
+ }
+}
+
+void MenuPrincipal::disconnectKeyboard()
+{
+ if (_keyboard)
+ {
+ delete _keyboard;
+ _keyboard = NULL;
+ }
+}
+
+void MenuPrincipal::disconnectScreen()
+{
+ if (_screen)
+ {
+ delete _screen;
+ _screen = NULL;
+ }
+}
+
+void MenuPrincipal::openOptions()
+{
+ options.show();
+}
#include <QMainWindow>
+#include <Options.h>
+
+#include <XYPlotter.h>
+#include <LivingKeyboard.h>
+#include <LivingScreen.h>
+
namespace Ui {
class MenuPrincipal;
}
explicit MenuPrincipal(QWidget *parent = 0);
~MenuPrincipal();
+ public slots:
+ void connectMouse();
+ void connectKeyboard();
+ void connectScreen();
+
+ void calibrateMouse();
+ void calibrateKeyboard();
+ void calibrateScreen();
+
+ void resetMouse();
+ void resetKeyboard();
+ void resetScreen();
+
+ void disconnectMouse();
+ void disconnectKeyboard();
+ void disconnectScreen();
+
+ private slots:
+ void openOptions();
+
private:
Ui::MenuPrincipal *ui;
+ Options options;
+
+ XYPlotter *_mouse;
+ LivingKeyboard *_keyboard;
+ LivingScreen *_screen;
};
#endif // MENUPRINCIPAL_H
--- /dev/null
+#include "Options.h"
+#include "ui_options.h"
+
+#include <MenuPrincipal.h>
+
+Options::Options(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::Options)
+{
+ ui->setupUi(this);
+
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(parent);
+
+ connect(ui->calibmouse, SIGNAL(clicked()), menu, SLOT(calibrateMouse()));
+ connect(ui->calibkeyboard, SIGNAL(clicked()), menu, SLOT(calibrateKeyboard()));
+ connect(ui->calibscreen, SIGNAL(clicked()), menu, SLOT(calibrateScreen()));
+
+ connect(ui->resetmouse, SIGNAL(clicked()), menu, SLOT(resetMouse()));
+ connect(ui->resetkeyboard, SIGNAL(clicked()), menu, SLOT(resetKeyboard()));
+ connect(ui->resetscreen, SIGNAL(clicked()), menu, SLOT(resetScreen()));
+}
+
+Options::~Options()
+{
+ delete ui;
+}
+
+void Options::enableMouse()
+{
+ ui->calibmouse->setEnabled(true);
+}
+
+void Options::enableKeyboard()
+{
+ ui->calibkeyboard->setEnabled(true);
+}
+
+void Options::enableScreen()
+{
+ ui->calibscreen->setEnabled(true);
+}
+
+void Options::disableMouse()
+{
+ ui->calibmouse->setEnabled(false);
+}
+
+void Options::disableKeyboard()
+{
+ ui->calibkeyboard->setEnabled(false);
+}
+
+void Options::disableScreen()
+{
+ ui->calibscreen->setEnabled(false);
+}
--- /dev/null
+#ifndef OPTIONS_H
+#define OPTIONS_H
+
+#include <QDialog>
+#include <XYPlotter.h>
+#include <LivingKeyboard.h>
+#include <LivingScreen.h>
+
+namespace Ui {
+ class Options;
+}
+
+class Options : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ explicit Options(QWidget *parent = 0);
+ ~Options();
+
+ void enableMouse();
+ void enableKeyboard();
+ void enableScreen();
+
+ void disableMouse();
+ void disableKeyboard();
+ void disableScreen();
+
+ private:
+ Ui::Options *ui;
+};
+
+#endif // OPTIONS_H
<x>0</x>
<y>0</y>
<width>894</width>
- <height>618</height>
+ <height>546</height>
</rect>
</property>
<property name="windowTitle">
</property>
</widget>
</item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
<item>
<layout class="QGridLayout" name="gridLayout">
- <item row="1" column="1">
- <widget class="QPushButton" name="pushButton_4">
+ <item row="2" column="0">
+ <widget class="QPushButton" name="pushButton_2">
<property name="minimumSize">
<size>
<width>0</width>
</font>
</property>
<property name="text">
- <string>PushButton</string>
+ <string>Demo 3</string>
</property>
</widget>
</item>
- <item row="0" column="1">
+ <item row="1" column="1">
<widget class="QPushButton" name="pushButton_3">
<property name="minimumSize">
<size>
</font>
</property>
<property name="text">
- <string>PushButton</string>
+ <string>Demo 2</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QPushButton" name="pushButton_2">
+ <item row="2" column="1">
+ <widget class="QPushButton" name="pushButton_4">
<property name="minimumSize">
<size>
<width>0</width>
</font>
</property>
<property name="text">
- <string>PushButton</string>
+ <string>Demo 4</string>
</property>
</widget>
</item>
- <item row="0" column="0">
+ <item row="1" column="0">
<widget class="QPushButton" name="pushButton">
<property name="minimumSize">
<size>
</font>
</property>
<property name="text">
- <string>PushButton</string>
+ <string>Demo 1</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>1</number>
+ </property>
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Minimum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="options">
+ <property name="text">
+ <string>Options</string>
</property>
</widget>
</item>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Options</class>
+ <widget class="QDialog" name="Options">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>500</width>
+ <height>324</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="calibmouse">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Calibrate Mouse</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="calibscreen">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Calibrate Screen</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="calibkeyboard">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Calibrate Keyboard</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetmouse">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Reset Mouse</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetscreen">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Reset Screen</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetkeyboard">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Reset Keyboard</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>Options</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>Options</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
}
if (keyboard)
delete keyboard;
+ if (screen)
+ delete screen;
delete ui;
}