From 469ab771b270ab47572d1b2ad4bc38f38e0a8a78 Mon Sep 17 00:00:00 2001 From: Igor Trindade Oliveira Date: Fri, 31 Jul 2009 14:42:54 -0400 Subject: [PATCH] initial commit --- appui.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ appui.h | 51 ++++++++++++++++++++++++++++++++++++++ kineticscroll.cpp | 53 +++++++++++++++++++++++++++++++++++++++ kineticscroll.h | 26 +++++++++++++++++++ kineticscroll_p.h | 16 ++++++++++++ main.cpp | 28 +++++++++++++++++++++ standalone.pro | 3 +++ 7 files changed, 251 insertions(+) create mode 100644 appui.cpp create mode 100644 appui.h create mode 100644 kineticscroll.cpp create mode 100644 kineticscroll.h create mode 100644 kineticscroll_p.h create mode 100644 main.cpp create mode 100644 standalone.pro diff --git a/appui.cpp b/appui.cpp new file mode 100644 index 0000000..cb4cc9f --- /dev/null +++ b/appui.cpp @@ -0,0 +1,74 @@ +#include "appui.h" + + +AppUI::AppUI(QGraphicsItem *parent): QGraphicsWidget( parent ), + previousDim( 0 ), + mGraphicsWidget( 0 ), + mLayout( 0 ), mFlipLayout( 0 ), + toBackButton( 0 ) +{ + resize( 300, 400 ); + setFlag(QGraphicsItem::ItemIsMovable, true); + setAcceptTouchEvents(true); + setAcceptedMouseButtons( Qt::LeftButton ); +} + +void AppUI:: buildWorld() { + + mLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); + mGraphicsWidget = new QGraphicsWidget(this); + mGraphicsWidget->resize(300, 400); + mGraphicsWidget->setAcceptedMouseButtons( Qt::LeftButton ); + mGraphicsWidget->setAcceptTouchEvents(true); + + mFlipLayout = new QGraphicsLinearLayout(Qt::Vertical, mGraphicsWidget); + + QWidget *front = new QWidget(); + toBackButton = new QPushButton("To Back"); + //QObject::connect(toBackButton, SIGNAL(clicked()), this, SLOT(makeVisible())); + toBackButton->setStyleSheet("background: pink"); + { + QVBoxLayout *vbox = new QVBoxLayout(front); + vbox->addWidget(toBackButton); + } + + QGraphicsProxyWidget *stackProxy1 = new QGraphicsProxyWidget(); + stackProxy1->setWidget( front ); + + mFlipLayout->addItem(stackProxy1); + mLayout->addItem( mGraphicsWidget ); + + previousDim = new QRectF( geometry() ); + +} + +void AppUI::mousePressEvent ( QGraphicsSceneMouseEvent * event ) +{ + KineticScrolling::mousePressEvent( event ); + QGraphicsItem::mousePressEvent( event ); +} + +void AppUI::mouseMoveEvent( QGraphicsSceneMouseEvent *event) +{ + KineticScrolling::mouseMoveEvent( event ); + QGraphicsItem::mouseMoveEvent( event ); +} + +void AppUI::mouseReleaseEvent( QGraphicsSceneMouseEvent *event) +{ + KineticScrolling::mouseReleaseEvent( event ); + QGraphicsItem::mouseReleaseEvent( event ); + qDebug()<<"atual:"<setEasingCurve(QEasingCurve::OutQuad); + anim1->setDuration(2*duration); + anim1->setStartValue(startValue); + anim1->setEndValue(endValue); + anim1->start(); + qDebug()<<"duration:"< */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */ +/* 02110-1301, USA. */ +/*********************************************************************/ + +#ifndef APPUI_H +#define APPUI_H +#include "kineticscroll.h" + +#include + +class AppUI: public QGraphicsWidget, public KineticScrolling { + Q_OBJECT + +public: + AppUI(QGraphicsItem *parent = 0); + + virtual ~AppUI() { delete previousDim; } + + void buildWorld(); + void animation(); + + QRectF *previousDim; + QGraphicsWidget *mGraphicsWidget; + QGraphicsLinearLayout *mLayout; + QGraphicsLinearLayout *mFlipLayout; + QPushButton *toBackButton; +protected: + void mousePressEvent ( QGraphicsSceneMouseEvent * event ); + void mouseMoveEvent( QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent( QGraphicsSceneMouseEvent *event); + + void animation(int duration, qreal startValue, qreal endValue); +}; + +#endif diff --git a/kineticscroll.cpp b/kineticscroll.cpp new file mode 100644 index 0000000..a845016 --- /dev/null +++ b/kineticscroll.cpp @@ -0,0 +1,53 @@ +#include "kineticscroll.h" + +#include +#include +#include + +unsigned int KineticScrollingPrivate::currentTimeInSecs() +{ + QTime t = QTime::currentTime(); + return (t.hour() * 3600000 + t.minute() * 60000 + t.second() * 1000 + t.msec()); +} + +KineticScrolling::KineticScrolling() +{ + d = new KineticScrollingPrivate; +} + +qreal KineticScrolling::movement() +{ + return d->movement; +} + +qreal KineticScrolling::duration() +{ + return d->timeDelta; +} + +void KineticScrolling::mousePressEvent( QGraphicsSceneMouseEvent *event ) +{ + d->timeStamp = d->currentTimeInSecs(); + d->scrollVelocity = 0; + d->movement = 0; + + qDebug()<< "MousePressEvent"; +} + +void KineticScrolling::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) +{ + d->movement = event->lastPos().y() - event->pos().y(); + + d->timeDelta = d->currentTimeInSecs() - d->timeStamp; + qDebug()<<"MouseMoveEvent"; + qDebug()<<"movement:"<movement; + qDebug()<<"timerStamp:"<timeStamp; + qDebug()<<"currentTime:"<currentTimeInSecs(); +} + +void KineticScrolling::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) +{ + qDebug()<<"MouseReleaseEvent"; + qDebug()<<"movement:"<movement; + qDebug()<<"timerStamp:"<timeStamp; +} diff --git a/kineticscroll.h b/kineticscroll.h new file mode 100644 index 0000000..b977242 --- /dev/null +++ b/kineticscroll.h @@ -0,0 +1,26 @@ +#ifndef KINETICSCROLLING_H +#define KINETICSCROLLING_H + +#include +#include +#include + +#include "kineticscroll_p.h" + +class KineticScrolling +{ + public: + KineticScrolling(); + protected: + void mouseMoveEvent( QGraphicsSceneMouseEvent *event); + void mousePressEvent( QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent( QGraphicsSceneMouseEvent *event); + + qreal duration(); + qreal movement(); + + private: + KineticScrollingPrivate *d; +}; + +#endif diff --git a/kineticscroll_p.h b/kineticscroll_p.h new file mode 100644 index 0000000..7e74e09 --- /dev/null +++ b/kineticscroll_p.h @@ -0,0 +1,16 @@ +#ifndef KINETICSCROLLINGPRIVATE_H +#define KINETICSCROLLINGPRIVATE_H + +class KineticScrollingPrivate +{ + public: + + unsigned int currentTimeInSecs(); + + unsigned int timeStamp; + unsigned int timeDelta; + qreal scrollVelocity; + qreal movement; +}; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..4833f39 --- /dev/null +++ b/main.cpp @@ -0,0 +1,28 @@ +#include +#include "appui.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QGraphicsScene scene; + scene.setSceneRect(0, 0, 600, 600); + + AppUI ui[300]; + + for( int i = 0; i < 10; i++) { + if( i > 0 ){ + ui[i].setGeometry(ui[i].geometry().x(), ui[i - 1].geometry().y() + ui[i - 1].geometry().height(), ui[i].geometry().width(), ui[i].geometry().height()); + ui[i].setParentItem( &ui[ i -1]); + } + scene.addItem( &ui[i] ); + ui[i].buildWorld(); + } + + QGraphicsView view(&scene); + view.setRenderHint(QPainter::Antialiasing); + /* view drag */ + view.setDragMode(QGraphicsView::ScrollHandDrag); + view.show(); + + return app.exec(); +} diff --git a/standalone.pro b/standalone.pro new file mode 100644 index 0000000..66ec86a --- /dev/null +++ b/standalone.pro @@ -0,0 +1,3 @@ +QMAKE_CXXFLAGS += -g -Wall +SOURCES += main.cpp appui.cpp kineticscroll.cpp +HEADERS += appui.h kineticscroll_p.h kineticscroll.h -- 2.11.4.GIT