Merge branch 'wallika-own'
[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 <QDebug>
31
32 ListViewScreen::ListViewScreen(QWidget *parent)
33     : QWidget(parent)
34 {
35
36     m_arrowbutton = new Pixmap(QPixmap(":/resources/arrow_right.png"));
37
38     m_personalInfo = new InfoTab;
39     m_personalInfo->setAvatar(QPixmap(":/resources/facebook_user_64.png"));
40     m_personalInfo->setUserName("Fred Facebook");
41     m_personalInfo->setMessageText("Hello Maemo Situare !");
42     m_personalInfo->setTime("1 hour ago");
43     m_personalInfo->setAddress("Kiviharjunlenkki 1E, 91910 Oulu");
44
45     m_locationDialog = new UpdateLocationDialog(this);
46     m_widgetProxy = new QGraphicsProxyWidget();
47     m_widgetProxy->setWidget(m_personalInfo);
48
49     QGraphicsScene *scene= new QGraphicsScene(this);
50     scene->setBackgroundBrush(Qt::white);    
51     scene->addItem(m_widgetProxy);
52     scene->addItem(m_arrowbutton);
53     qDebug() << "Scene width: " << scene->width();
54     qDebug() << "Scene heigth: " << scene->height();
55
56     QGraphicsView *view = new QGraphicsView(scene);
57     view->setAlignment(Qt::AlignLeft|Qt::AlignTop);
58     view->setSceneRect(0,0,7000,3000);
59     view->centerOn(QPointF(0,0));
60     view->setFrameStyle(0);
61     view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
62     view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
63     view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64
65     QStateMachine *machine = new QStateMachine(this);
66     machine->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
67
68     QState *state1 = new QState(machine);
69     QState *state2 = new QState(machine);
70     machine->setInitialState(state1);
71
72     // State 1
73     state1->assignProperty(m_widgetProxy,"pos",QPointF(-(m_personalInfo->width()),0));
74     state1->assignProperty(m_arrowbutton,"pos",QPointF(0,(m_personalInfo->height()/4)));
75
76     // State 2
77     state2->assignProperty(m_widgetProxy,"pos",QPointF(0,0));
78     state2->assignProperty(m_arrowbutton,"pos",QPointF((m_personalInfo->width()),(m_personalInfo->height()/4)));
79
80     m_trans1 = state1->addTransition(m_arrowbutton,SIGNAL(clicked()),state2);
81     m_anim1 = new QPropertyAnimation(m_widgetProxy,"pos");
82     m_anim2 = new QPropertyAnimation(m_arrowbutton,"pos");
83     m_trans1->addAnimation(m_anim1);
84     m_trans1->addAnimation(m_anim2);
85
86     m_trans2 = state2->addTransition(m_arrowbutton,SIGNAL(clicked()),state1);
87     m_anim3= new QPropertyAnimation(m_widgetProxy,"pos");
88     m_anim4= new QPropertyAnimation(m_arrowbutton,"pos");
89     m_trans2->addAnimation(m_anim3);
90     m_trans2->addAnimation(m_anim4);
91
92     machine->start();
93
94     m_vbox = new QVBoxLayout(this);
95     m_vbox->addWidget(view);
96     m_vbox->setMargin(0);
97
98     connect(m_personalInfo,SIGNAL(launchMessageUpdate()),this,SLOT(updateMessage()));
99 }
100
101 ListViewScreen::~ListViewScreen()
102 {
103     if (m_personalInfo)
104         delete m_personalInfo;
105     if (m_arrowbutton)
106         delete m_arrowbutton;
107     if (m_trans1)
108         delete m_trans1;
109     if (m_trans2)
110         delete m_trans2;
111     if (m_anim1)
112         delete m_anim1;
113     if (m_anim2)
114         delete m_anim2;
115     if (m_anim3)
116         delete m_anim3;
117     if (m_anim4)
118         delete m_anim4;
119     if (m_vbox)
120         delete m_vbox;
121 }
122
123 void ListViewScreen::updateMessage()
124 {
125    qDebug() << __PRETTY_FUNCTION__;
126    m_locationDialog->exec();
127 }