PeepHole
authorMjolnir <thomas.pietrzak@inria.fr>
Fri, 4 Sep 2015 14:21:47 +0000 (16:21 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Fri, 4 Sep 2015 14:21:47 +0000 (16:21 +0200)
LivingDemos/LargeView.cpp [new file with mode: 0644]
LivingDemos/LargeView.h [new file with mode: 0644]
LivingDemos/LivingDemos.pro
LivingDemos/MenuPrincipal.cpp
LivingDemos/MenuPrincipal.h
LivingDemos/Peephole.cpp [new file with mode: 0644]
LivingDemos/Peephole.h [new file with mode: 0644]
LivingDemos/Tidy.cpp
LivingDemos/fullscreen.ui
LivingDemos/menuprincipal.ui
images/panorama.jpg [new file with mode: 0644]

diff --git a/LivingDemos/LargeView.cpp b/LivingDemos/LargeView.cpp
new file mode 100644 (file)
index 0000000..aeb0bc9
--- /dev/null
@@ -0,0 +1,34 @@
+#include "LargeView.h"
+
+#include <QDebug>
+#include <QDragEnterEvent>
+#include <QDragMoveEvent>
+
+LargeView::LargeView(QWidget *parent) :
+    QGraphicsView(parent)
+{
+    setInteractive(true);
+}
+
+void LargeView::resizeEvent(QResizeEvent *event)
+{
+    fit();
+}
+
+void LargeView::fit()
+{
+    //QRectF content = scene().sceneRect();
+    //qreal ratio = width() / height();
+    fitInView(sceneRect(), Qt::KeepAspectRatioByExpanding);
+}
+
+void LargeView::dragEnterEvent(QDragEnterEvent *event)
+{
+    event->accept();
+    qDebug() << "start drag";
+}
+
+void LargeView::dragMoveEvent(QDragMoveEvent *event)
+{
+    qDebug() << "move " << event->pos().x();
+}
diff --git a/LivingDemos/LargeView.h b/LivingDemos/LargeView.h
new file mode 100644 (file)
index 0000000..e7a15e2
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef LARGEVIEW_H
+#define LARGEVIEW_H
+
+#include <QGraphicsView>
+
+class LargeView : public QGraphicsView
+{
+        Q_OBJECT
+    public:
+        explicit LargeView(QWidget *parent = 0);
+
+    private:
+        void resizeEvent(QResizeEvent * event);
+        void fit();
+
+        void dragEnterEvent(QDragEnterEvent * event);
+        void dragMoveEvent(QDragMoveEvent * event);
+
+    signals:
+
+    public slots:
+
+};
+
+#endif // LARGEVIEW_H
index 73d9e2f99528133177960779d07aca6a1c373dc2..d63a1292131890cfde6b21e195a8e9b4eb7c76d5 100644 (file)
@@ -27,13 +27,17 @@ SOURCES += main.cpp\
         Options.cpp \
     Tidy.cpp \
     Force.cpp \
-    GestureOutput.cpp
+    GestureOutput.cpp \
+    Peephole.cpp \
+    LargeView.cpp
 
 HEADERS  += MenuPrincipal.h \
     Options.h \
     Tidy.h \
     Force.h \
-    GestureOutput.h
+    GestureOutput.h \
+    Peephole.h \
+    LargeView.h
 
 FORMS    += menuprincipal.ui \
     options.ui \
index a2edcd3e3594f7ace7c1e237df84b81e815ccaef..4b77dd23bbbcb70cb9dfc38c6024dda5ce2977e4 100644 (file)
@@ -6,6 +6,7 @@
 #include <Tidy.h>
 #include <Force.h>
 #include <GestureOutput.h>
+#include <Peephole.h>
 
 MenuPrincipal::MenuPrincipal(QWidget *parent) :
     QMainWindow(parent),
@@ -23,6 +24,8 @@ MenuPrincipal::MenuPrincipal(QWidget *parent) :
     connect(ui->tidy, SIGNAL(clicked()), this, SLOT(openTidy()));
     connect(ui->force, SIGNAL(clicked()), this, SLOT(openForce()));
     connect(ui->gestureoutput, SIGNAL(clicked()), this, SLOT(openGestureOutput()));
+    connect(ui->peephole, SIGNAL(clicked()), this, SLOT(openPeephole()));
+
 
     connectKeyboard();
     connectScreen();
@@ -179,3 +182,9 @@ void MenuPrincipal::openGestureOutput()
     GestureOutput * g= new GestureOutput(this);
     g->show();
 }
+
+void MenuPrincipal::openPeephole()
+{
+    Peephole * p= new Peephole(this);
+    p->show();
+}
index ba2bbcab1a26b1285cff285a59fee28f8a8a029e..2a006994ad6966b8fa31282349162f9bb1d4a50c 100644 (file)
@@ -49,6 +49,7 @@ class MenuPrincipal : public QMainWindow
         void openTidy();
         void openForce();
         void openGestureOutput();
+        void openPeephole();
 
     private:
         Ui::MenuPrincipal *ui;
diff --git a/LivingDemos/Peephole.cpp b/LivingDemos/Peephole.cpp
new file mode 100644 (file)
index 0000000..6977d3d
--- /dev/null
@@ -0,0 +1,51 @@
+#include "Peephole.h"
+
+#include <QDebug>
+#include <MenuPrincipal.h>
+#include <QScrollBar>
+
+const int Peephole::length = 660;
+
+Peephole::Peephole(QWidget *parent) :
+    QMainWindow(parent),
+    screenpos(330),
+    viewpos(0),
+    ui(new Ui::Fullscreen)
+{
+    ui->setupUi(this);
+    setWindowState(Qt::WindowMaximized);
+    setAttribute(Qt::WA_DeleteOnClose);
+
+    ui->image->setScene(&_background);
+    _background.addPixmap(QPixmap("../../images/panorama.jpg"));
+    ui->image->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    ui->image->setDragMode(QGraphicsView::ScrollHandDrag);
+    ui->image->setResizeAnchor(QGraphicsView::AnchorViewCenter);
+
+    connect(ui->start, SIGNAL(clicked()), this, SLOT(moveDevices()));
+    connect(ui->image->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scroll(int)));
+
+    MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(parent);
+    if (!menu->getScreen())
+        qDebug() << "Warning: screen not connected";
+}
+
+Peephole::~Peephole()
+{
+    delete ui;
+}
+
+void Peephole::scroll(int pos)
+{
+    qDebug() << "Pos: " << pos;
+    MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+    if (menu->getScreen())
+    {
+        int delta = pos - viewpos;
+        viewpos = pos;
+        if (delta < 0)
+            menu->getScreen()->translation(LivingScreen::LEFT, -delta * length / (_background.width() - ui->image->width()));
+        else
+            menu->getScreen()->translation(LivingScreen::RIGHT, delta * length / (_background.width() - ui->image->width()));
+    }
+}
diff --git a/LivingDemos/Peephole.h b/LivingDemos/Peephole.h
new file mode 100644 (file)
index 0000000..6e99adf
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef PEEPHOLE_H
+#define PEEPHOLE_H
+
+#include <QMainWindow>
+#include <QGraphicsScene>
+
+#include <ui_fullscreen.h>
+
+namespace Ui {
+    class Fullscreen;
+}
+
+class Peephole : public QMainWindow
+{
+        Q_OBJECT
+
+    public:
+        explicit Peephole(QWidget *parent = 0);
+        ~Peephole();
+
+    public slots:
+        void scroll(int pos);
+
+    private:
+        int screenpos, viewpos;
+        static const int length;
+        Ui::Fullscreen *ui;
+        QGraphicsScene _background;
+};
+
+#endif // PEEPHOLE_H
index 2685990f5fad532d80db371157a7e02db88b4040..3ce922056d7addb847d3bc42128563114b24e41d 100644 (file)
@@ -16,8 +16,6 @@ Tidy::Tidy(QWidget *parent) :
     _background.addPixmap(QPixmap("../../images/desktop.jpg"));
     ui->image->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     ui->image->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    //ui->image->ensureVisible(_background.itemsBoundingRect());
-                             //sceneRect());
 
     connect(ui->start, SIGNAL(clicked()), this, SLOT(moveDevices()));
 
index ca23847390f7c2cf2258670e181dfcd93792cc7d..1b36056083bf762907e2f41c02353af302781696 100644 (file)
@@ -34,7 +34,7 @@
      <number>0</number>
     </property>
     <item>
-     <widget class="QGraphicsView" name="image"/>
+     <widget class="LargeView" name="image"/>
     </item>
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout">
    </layout>
   </widget>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>LargeView</class>
+   <extends>QGraphicsView</extends>
+   <header location="global">LargeView.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>
index ca9aaa0bc0b65aa5347d94fcb74c731f2da8296b..bb1689f8c3528f1bb7154e1c2fe837dadb6abbdf 100644 (file)
@@ -88,7 +88,7 @@
        </widget>
       </item>
       <item row="2" column="1">
-       <widget class="QPushButton" name="pushButton_4">
+       <widget class="QPushButton" name="peephole">
         <property name="minimumSize">
          <size>
           <width>0</width>
          </font>
         </property>
         <property name="text">
-         <string>Demo 4</string>
+         <string>Peephole</string>
         </property>
        </widget>
       </item>
   <tabstop>tidy</tabstop>
   <tabstop>force</tabstop>
   <tabstop>gestureoutput</tabstop>
-  <tabstop>pushButton_4</tabstop>
+  <tabstop>peephole</tabstop>
   <tabstop>options</tabstop>
  </tabstops>
  <resources/>
diff --git a/images/panorama.jpg b/images/panorama.jpg
new file mode 100644 (file)
index 0000000..7cd6d4f
Binary files /dev/null and b/images/panorama.jpg differ