Peephole
authorMjolnir <thomas.pietrzak@inria.fr>
Mon, 7 Sep 2015 12:52:01 +0000 (14:52 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Mon, 7 Sep 2015 12:52:01 +0000 (14:52 +0200)
LivingDemos/Peephole.cpp
LivingDemos/Peephole.h

index 6977d3d208b77475227ea7ba51afec8ae003136c..24dba7a76a6b7a7e9650558ed0cd433d9da0aaf4 100644 (file)
@@ -3,8 +3,7 @@
 #include <QDebug>
 #include <MenuPrincipal.h>
 #include <QScrollBar>
-
-const int Peephole::length = 660;
+#include <QThread>
 
 Peephole::Peephole(QWidget *parent) :
     QMainWindow(parent),
@@ -17,17 +16,20 @@ Peephole::Peephole(QWidget *parent) :
     setAttribute(Qt::WA_DeleteOnClose);
 
     ui->image->setScene(&_background);
-    _background.addPixmap(QPixmap("../../images/panorama.jpg"));
+    QPixmap back("../../images/panorama.jpg");
+    _background.addPixmap(back);
+    bgwidth = back.width();
     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";
+    else
+        rackwidth = menu->getScreen()->getWidth();
 }
 
 Peephole::~Peephole()
@@ -41,11 +43,19 @@ void Peephole::scroll(int pos)
     MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
     if (menu->getScreen())
     {
-        int delta = pos - viewpos;
+        unsigned int min = ui->image->horizontalScrollBar()->minimum();
+        unsigned int range = ui->image->horizontalScrollBar()->maximum() - min;
+        if (range == 0)
+            return;
+        unsigned int dest = rackwidth * pos / range - min;
+        qDebug() << "Move to" << dest;
+        menu->getScreen()->moveto(dest);//(bgwidth - ui->image->width()));
+        QThread::msleep(20);
+/*        int delta = pos - viewpos;
         viewpos = pos;
         if (delta < 0)
-            menu->getScreen()->translation(LivingScreen::LEFT, -delta * length / (_background.width() - ui->image->width()));
+            menu->getScreen()->translation(LivingScreen::LEFT, -delta * rackwidth / (bgwidth - ui->image->width()));
         else
-            menu->getScreen()->translation(LivingScreen::RIGHT, delta * length / (_background.width() - ui->image->width()));
+            menu->getScreen()->translation(LivingScreen::RIGHT, delta * rackwidth / (bgwidth - ui->image->width()));*/
     }
 }
index 6e99adff4e2b93095484e2e3877ff7d8d86a1a97..7446d3bcad53699424c7911f7cb6c0f563d4cb25 100644 (file)
@@ -23,7 +23,7 @@ class Peephole : public QMainWindow
 
     private:
         int screenpos, viewpos;
-        static const int length;
+        unsigned int rackwidth, bgwidth;
         Ui::Fullscreen *ui;
         QGraphicsScene _background;
 };