Menu démo fonctionnel
authorMjolnir <thomas.pietrzak@inria.fr>
Thu, 3 Sep 2015 11:37:54 +0000 (13:37 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Thu, 3 Sep 2015 11:37:54 +0000 (13:37 +0200)
LivingDemos/LivingDemos.pro
LivingDemos/MenuPrincipal.cpp
LivingDemos/MenuPrincipal.h
LivingDemos/Options.cpp [new file with mode: 0644]
LivingDemos/Options.h [new file with mode: 0644]
LivingDemos/menuprincipal.ui
LivingDemos/options.ui [new file with mode: 0644]
Test/mainwindow.cpp

index 4c79fdc01fc945409dbdb7b0b426b15bd1efd23c..10663e68fa2ac34bac2afd4b575617911b06d2c7 100644 (file)
@@ -23,8 +23,11 @@ LIBS += -L$$PWD/../builds/livingdesktop-Release -lLivingDesktop
 
 
 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
index 226b8889be0b111c7b48533b80f41c7c4934651c..4cf4b5ec4c1dc412a1f9e5169c0c6b50de9bb453 100644 (file)
 #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();
+}
index 9394fa3fce97b52bdb893536a75484ddd58ca0cf..b4dd4cadd93c2f196d88b48940df49fe7e7c10d0 100644 (file)
@@ -3,6 +3,12 @@
 
 #include <QMainWindow>
 
+#include <Options.h>
+
+#include <XYPlotter.h>
+#include <LivingKeyboard.h>
+#include <LivingScreen.h>
+
 namespace Ui {
     class MenuPrincipal;
 }
@@ -15,8 +21,33 @@ class MenuPrincipal : public QMainWindow
         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
diff --git a/LivingDemos/Options.cpp b/LivingDemos/Options.cpp
new file mode 100644 (file)
index 0000000..65aa47f
--- /dev/null
@@ -0,0 +1,56 @@
+#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);
+}
diff --git a/LivingDemos/Options.h b/LivingDemos/Options.h
new file mode 100644 (file)
index 0000000..0187154
--- /dev/null
@@ -0,0 +1,33 @@
+#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
index aec54c46dbbad03dcafa694a5e850e5b848063ea..bd7d7b40bea8100b9d5a88aaa1714ec69768059e 100644 (file)
@@ -7,7 +7,7 @@
     <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>
diff --git a/LivingDemos/options.ui b/LivingDemos/options.ui
new file mode 100644 (file)
index 0000000..442e1e2
--- /dev/null
@@ -0,0 +1,124 @@
+<?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>
index eda2defd0ac18c2fd193256dcc05c624637fac52..aff38fc427f25c04ff04107915dc1349e355c417 100644 (file)
@@ -64,6 +64,8 @@ MainWindow::~MainWindow()
     }
     if (keyboard)
         delete keyboard;
+    if (screen)
+        delete screen;
     delete ui;
 }