Dummy personal info tab animation added to listview scree.
authorJukka Saastamoinen <juksa@juksa-laptop.(none)>
Sat, 10 Apr 2010 12:17:46 +0000 (15:17 +0300)
committerJukka Saastamoinen <juksa@juksa-laptop.(none)>
Sat, 10 Apr 2010 12:17:46 +0000 (15:17 +0300)
src/images.qrc [new file with mode: 0644]
src/resources/dummy_personal_infotab_background.png [new file with mode: 0644]
src/src.pro
src/ui/listviewscreen.cpp
src/ui/personalinfotab.cpp
src/ui/personalinfotab.h

diff --git a/src/images.qrc b/src/images.qrc
new file mode 100644 (file)
index 0000000..ecb64ec
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>resources/dummy_personal_infotab_background.png</file>
+    </qresource>
+</RCC>
diff --git a/src/resources/dummy_personal_infotab_background.png b/src/resources/dummy_personal_infotab_background.png
new file mode 100644 (file)
index 0000000..9031870
Binary files /dev/null and b/src/resources/dummy_personal_infotab_background.png differ
index 8fd52e0..1e6c6b7 100644 (file)
@@ -47,3 +47,4 @@ unix {
     target.path = $$BINDIR
     INSTALLS += target
 }
+RESOURCES += images.qrc
index 5915840..0da7b19 100644 (file)
@@ -22,9 +22,7 @@
 
 #include <QGraphicsScene>
 #include <QGraphicsWidget>
-#include <QGraphicsLinearLayout>
 #include <QGraphicsView>
-#include <QGraphicsProxyWidget>
 #include <QtGui/QVBoxLayout>
 #include <QStateMachine>
 #include "listviewscreen.h"
 ListViewScreen::ListViewScreen(QWidget *parent)
    : QWidget(parent)
 {
+    PersonalInfoTab *infoTab = new PersonalInfoTab(QPixmap(":/resources/dummy_personal_infotab_background.png")); //200x300 pix
+    QGraphicsScene *scene= new QGraphicsScene(0,0,800,400);
+    scene->setBackgroundBrush(Qt::white);
+    scene->addItem(infoTab);
 
-    PersonalInfoTab *myTab = new PersonalInfoTab();
-    QGraphicsScene *scene= new QGraphicsScene();
-    QGraphicsWidget *widget = new QGraphicsWidget();
-    QGraphicsLinearLayout *linearLayout = new QGraphicsLinearLayout(widget);
-    linearLayout->setOrientation(Qt::Vertical);
-    linearLayout->addItem(myTab);
-    widget->setLayout(linearLayout);
-    scene->addItem(widget);
+    QGraphicsView *view = new QGraphicsView(scene);
+    view->setFrameStyle(0);
+    view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
-    //States and animations
+    QStateMachine *machine = new QStateMachine;
+    machine->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
 
-    QStateMachine machine;
-    QState *state1 = new QState(&machine);
-    QState *state2 = new QState(&machine);
-    machine.setInitialState(state1);
+    QState *state1 = new QState(machine);
+    QState *state2 = new QState(machine);
+    machine->setInitialState(state1);
 
-    state1->assignProperty(widget, "pos", QPointF(-140, 0));
-    state2->assignProperty(widget, "pos", QPointF(0, 0));
+    state1->assignProperty(infoTab,"pos", QPointF(-180,50));
 
-    QAbstractTransition *t1 = state1->addTransition(myTab, SIGNAL(clicked()), state2);
-    t1->addAnimation(new QPropertyAnimation(widget, "pos"));
+    state2->assignProperty(infoTab,"pos", QPoint(0,50));
 
-    QAbstractTransition *t2 = state2->addTransition(myTab, SIGNAL(clicked()), state1);
-    t2->addAnimation(new QPropertyAnimation(widget, "pos"));
+    QAbstractTransition *trans1 = state1->addTransition(infoTab,SIGNAL(clicked()),state2);
+    trans1->addAnimation(new QPropertyAnimation(infoTab,"pos"));
 
-    machine.start();
+    QAbstractTransition *trans2 = state2->addTransition(infoTab,SIGNAL(clicked()),state1);
+    trans2->addAnimation(new QPropertyAnimation(infoTab,"pos"));
 
+    machine->start();
 
-    QGraphicsView *view = new QGraphicsView(scene);
     QVBoxLayout *vbox = new QVBoxLayout(this);
     vbox->addWidget(view);
-
 }
index 4cc2b05..e6c9cb4 100644 (file)
 */
 
 #include "personalinfotab.h"
-#include <QtGui/QPushButton>
-#include <QtGui/QVBoxLayout>
-#include <QGraphicsProxyWidget>
-#include <QGraphicsLinearLayout>
+#include <QDebug>
 
-
-PersonalInfoTab::PersonalInfoTab(QGraphicsItem *parent)
-    : QGraphicsWidget(parent)
+PersonalInfoTab::PersonalInfoTab(const QPixmap &picture)
+    : QGraphicsObject(), p(picture)
 {
-    QWidget *infoTab = new QWidget();
-    QPushButton *reloadButton = new QPushButton("Testing");
-    QVBoxLayout *vbox = new QVBoxLayout(infoTab);
-    vbox->addWidget(reloadButton);
-
-    // Need to use QGraphicsProxyWidget to enable embedding QWidgets like QPushButton etc.
-    QGraphicsProxyWidget *infoTabProxy = new QGraphicsProxyWidget();
-    infoTabProxy->setWidget(infoTab);
-    QGraphicsLinearLayout *linearVbox = new QGraphicsLinearLayout(this);
-    linearVbox->addItem(infoTabProxy);
-
 }
 
 void PersonalInfoTab::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     emit clicked();
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+void PersonalInfoTab::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+    painter->drawPixmap(QPointF(), p);
+}
+
+QRectF PersonalInfoTab::boundingRect() const
+{
+    return QRectF( QPointF(0, 0), p.size());
 }
index 412716b..d224241 100644 (file)
 #ifndef PERSONALINFOTAB_H
 #define PERSONALINFOTAB_H
 
-#include <QGraphicsWidget>
+#include <QtCore>
+#include <QtGui>
 
 
-class PersonalInfoTab : public QGraphicsWidget
+class PersonalInfoTab : public QGraphicsObject
 {
     Q_OBJECT
 public:
@@ -34,11 +35,14 @@ public:
     *
     * @param parent Parent
     */
-    PersonalInfoTab(QGraphicsItem *parent = 0);
+    PersonalInfoTab(const QPixmap &);
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
-
-Q_SIGNALS:
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
+    QRectF boundingRect() const;
+signals:
     void clicked();
+private:
+    QPixmap p;
 };
 
 #endif // PERSONALINFOTAB_H