Personal infotab contents merged, reviewed by wallika
[situare] / src / ui / listviewscreen.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Kaj Wallin - kaj.wallin@ixonos.com
6       Jukka Saastamoinen jukka.saastamoinen@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <QGraphicsScene>
24 #include <QGraphicsView>
25 #include <QGraphicsWidget>
26 #include <QtGui/QVBoxLayout>
27 #include <QGraphicsProxyWidget>
28 #include <QStateMachine>
29 #include "listviewscreen.h"
30 #include "pixmap.h"
31 #include "infotab.h"
32 #include <QDebug>
33
34 ListViewScreen::ListViewScreen(QWidget *parent)
35    : QWidget(parent)
36 {
37     Pixmap *arrowbutton = new Pixmap(QPixmap(":/resources/arrow_right.png"));
38
39     InfoTab *personalInfo = new InfoTab;
40     personalInfo->setAvatar(QPixmap(":/resources/facebook_user_64.png"));
41     personalInfo->setUserName("Fred Facebook");
42     personalInfo->setMessageText("Hello Maemo Situare !");
43     personalInfo->setTime("1 hour ago");
44     personalInfo->setAddress("Kiviharjunlenkki 1E, 91910 Oulu");
45
46     QGraphicsProxyWidget *widgetProxy = new QGraphicsProxyWidget();
47     widgetProxy->setWidget(personalInfo);
48
49     QGraphicsScene *scene= new QGraphicsScene();
50     QGraphicsWidget *graphWidget = new QGraphicsWidget();
51     graphLayout = new QGraphicsLinearLayout(graphWidget);
52     graphLayout->setOrientation(Qt::Horizontal);
53     graphLayout->addItem(widgetProxy);
54     scene->setBackgroundBrush(Qt::white);    
55     scene->addItem(graphWidget);
56     scene->addItem(arrowbutton);
57     qDebug() << "Scene width: " << scene->width();
58     qDebug() << "Scene heigth: " << scene->height();
59
60     QGraphicsView *view = new QGraphicsView(scene);
61     view->setAlignment(Qt::AlignLeft|Qt::AlignTop);
62     view->setSceneRect(0,0,7000,3000);
63     view->centerOn(QPointF(0,0));
64     view->setFrameStyle(0);
65     view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
66     view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67     view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
68
69     QStateMachine *machine = new QStateMachine;
70     machine->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
71
72     QState *state1 = new QState(machine);
73     QState *state2 = new QState(machine);
74     machine->setInitialState(state1);
75
76     // State 1
77     state1->assignProperty(graphWidget,"pos",QPointF(-(personalInfo->width()+20),0));
78     state1->assignProperty(arrowbutton,"pos",QPointF(0,(arrowbutton->boundingRect().height()/2)+10));
79
80     // State 2
81     state2->assignProperty(graphWidget,"pos",QPointF(-20,0));
82     state2->assignProperty(arrowbutton,"pos",QPointF((personalInfo->width()-5),(arrowbutton->boundingRect().height()/2)+10));
83
84     QAbstractTransition *trans1 = state1->addTransition(arrowbutton,SIGNAL(clicked()),state2);
85     trans1->addAnimation(new QPropertyAnimation(graphWidget,"pos"));
86     trans1->addAnimation(new QPropertyAnimation(arrowbutton,"pos"));
87
88     QAbstractTransition *trans2 = state2->addTransition(arrowbutton,SIGNAL(clicked()),state1);
89     trans2->addAnimation(new QPropertyAnimation(graphWidget,"pos"));
90     trans2->addAnimation(new QPropertyAnimation(arrowbutton,"pos"));
91
92     machine->start();
93
94     vbox = new QVBoxLayout(this);
95     vbox->addWidget(view);
96 }
97
98 ListViewScreen::~ListViewScreen()
99 {
100     if (vbox)
101         delete vbox;
102     if (graphLayout)
103         delete graphLayout;
104     vbox=NULL;
105     graphLayout=NULL;
106 }