From 0e70e173de2583ce70fafe177b820bcb2d4b8130 Mon Sep 17 00:00:00 2001 From: Mjolnir Date: Mon, 7 Sep 2015 14:52:01 +0200 Subject: [PATCH] Peephole --- LivingDemos/Peephole.cpp | 24 +++++++++++++++++------- LivingDemos/Peephole.h | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/LivingDemos/Peephole.cpp b/LivingDemos/Peephole.cpp index 6977d3d..24dba7a 100644 --- a/LivingDemos/Peephole.cpp +++ b/LivingDemos/Peephole.cpp @@ -3,8 +3,7 @@ #include #include #include - -const int Peephole::length = 660; +#include 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(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(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()));*/ } } diff --git a/LivingDemos/Peephole.h b/LivingDemos/Peephole.h index 6e99adf..7446d3b 100644 --- a/LivingDemos/Peephole.h +++ b/LivingDemos/Peephole.h @@ -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; }; -- 2.30.2