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