From f9c32608580f79c8c8907e19aa1d57715cb04e87 Mon Sep 17 00:00:00 2001 From: "theo.bertozzi" Date: Thu, 24 Jan 2008 20:02:32 +0000 Subject: [PATCH] Added Mouse Click to move slides git-svn-id: https://pictureflow.googlecode.com/svn/trunk@11 f1dae18b-7a3c-0410-92e9-d7898dd3a7d1 --- pictureflow-qt4/pictureflow.cpp | 36 +++++++++++++++++++++++++++++++++ pictureflow-qt4/pictureflow.h | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/pictureflow-qt4/pictureflow.cpp b/pictureflow-qt4/pictureflow.cpp index a64469e..9bca165 100644 --- a/pictureflow-qt4/pictureflow.cpp +++ b/pictureflow-qt4/pictureflow.cpp @@ -284,6 +284,7 @@ class PictureFlowPrivate QImage buffer; QBasicTimer animateTimer; + QVector slidesRect; private: PictureFlow* widget; @@ -606,18 +607,24 @@ void PictureFlowPrivate::render() if(step == 0) { + slidesRect.clear(); + slidesRect.resize(11); + // no animation, boring plain rendering for(int index = 0; index < nleft-1; index++) { int alpha = (index < nleft-2) ? 256 : 128; QRect rs = renderSlide(leftSlides[index], alpha, 0, c1-1); + slidesRect[index] = rs; if(!rs.isEmpty()) c1 = rs.left(); } + slidesRect[5] = r; for(int index = 0; index < nright-1; index++) { int alpha = (index < nright-2) ? 256 : 128; QRect rs = renderSlide(rightSlides[index], alpha, c2+1, buffer.width()); + slidesRect[6 + index] = rs; if(!rs.isEmpty()) c2 = rs.right(); } @@ -1058,6 +1065,14 @@ void PictureFlow::keyPressEvent(QKeyEvent* event) event->ignore(); } +void PictureFlow::mouseReleaseEvent (QMouseEvent *event) { + showSlideAt(event->x(), event->y()); +} + +void PictureFlow::mouseMoveEvent (QMouseEvent *event) { + showSlideAt(event->x(), event->y()); +} + void PictureFlow::paintEvent(QPaintEvent* event) { Q_UNUSED(event); @@ -1079,3 +1094,24 @@ void PictureFlow::timerEvent(QTimerEvent* event) else QWidget::timerEvent(event); } + +void PictureFlow::showSlideAt (int x, int y) { + if (d->slidesRect[5].contains(x, y)) + return; + + if (x < d->slidesRect[5].x()) { + for (int i=0; i < 5; ++i) { + if (d->slidesRect[i].contains(x, y)) { + showSlide(d->currentSlide() - (i + 1)); + return; + } + } + } else { + for (int i=6; i < 11; ++i) { + if (d->slidesRect[i].contains(x, y)) { + showSlide(d->currentSlide() + (i - 5)); + return; + } + } + } +} diff --git a/pictureflow-qt4/pictureflow.h b/pictureflow-qt4/pictureflow.h index 615e51a..93b60b1 100644 --- a/pictureflow-qt4/pictureflow.h +++ b/pictureflow-qt4/pictureflow.h @@ -150,11 +150,16 @@ public slots: protected: + void mouseReleaseEvent (QMouseEvent *event); + void mouseMoveEvent (QMouseEvent *event); void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent* event); void resizeEvent(QResizeEvent* event); void timerEvent(QTimerEvent* event); +private: + void showSlideAt (int x, int y); + private: PictureFlowPrivate* d; };