author | John Kern <johnk@symbian.org> |
Thu, 19 Aug 2010 13:16:27 -0700 | |
changeset 35 | 0cb8cc1ee8f5 |
parent 34 | 93c5a58496b6 |
permissions | -rwxr-xr-x |
34
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
1 |
#include "detailsgv.h" |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
2 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
3 |
#include <QColor> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
4 |
#include <QGraphicsTextItem> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
5 |
#include <QGraphicsWidget> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
6 |
#include <QGraphicsLinearLayout> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
7 |
#include <QGraphicsAnchorLayout> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
8 |
#include <QGraphicsPixmapItem> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
9 |
#include <QGraphicsSvgItem> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
10 |
#include <QPixmap> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
11 |
#include <QTransform> |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
12 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
13 |
DetailsGV::DetailsGV(QObject *parent,QGraphicsView *gv) : |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
14 |
QObject(parent), view(gv) |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
15 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
16 |
scene = new QGraphicsScene(this); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
17 |
gv->setScene(scene); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
18 |
this->createWidgets(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
19 |
this->createProxyWidgets(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
20 |
this->createLayout(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
21 |
this->createConnections(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
22 |
this->customizeView(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
23 |
} |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
24 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
25 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
26 |
void DetailsGV::createWidgets() |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
27 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
28 |
QString styleSheet("background-color:red"); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
29 |
callMe = new QPushButton(tr("call us")); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
30 |
callMe->setStyleSheet(styleSheet); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
31 |
textMe = new QPushButton(tr("text us")); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
32 |
textMe->setStyleSheet(styleSheet); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
33 |
back = new QPushButton (tr("back")); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
34 |
back->setStyleSheet(styleSheet); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
35 |
exitApp = new QPushButton(tr("exit")); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
36 |
exitApp->setStyleSheet(styleSheet); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
37 |
} |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
38 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
39 |
void DetailsGV::createProxyWidgets() |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
40 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
41 |
proxyForName["callMe"] = scene->addWidget(callMe); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
42 |
proxyForName["textMe"] = scene->addWidget(textMe); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
43 |
proxyForName["back"] = scene->addWidget(back); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
44 |
proxyForName["exitApp"] = scene->addWidget(exitApp); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
45 |
} |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
46 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
47 |
void DetailsGV::createLayout() |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
48 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
49 |
// row of buttons |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
50 |
QGraphicsLinearLayout *leftLayout = new QGraphicsLinearLayout(Qt::Vertical); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
51 |
leftLayout->addItem(proxyForName["callMe"]); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
52 |
leftLayout->addItem(proxyForName["textMe"]); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
53 |
leftLayout->addItem(proxyForName["back"]); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
54 |
leftLayout->addItem(proxyForName["exitApp"]); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
55 |
|
35 | 56 |
|
57 |
// you can use jpeg too. However, it consumes more memory. If you want to use jpeg, edit |
|
58 |
// the pro file and bump up the max heap size. |
|
34
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
59 |
//QGraphicsPixmapItem *profile = new QGraphicsPixmapItem( QPixmap(":/images/MadProf_thumb.jpg")); |
35 | 60 |
|
34
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
61 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
62 |
// svg from open clipart (http://www.openclipart.org/detail/959) |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
63 |
QGraphicsSvgItem *profile = new QGraphicsSvgItem(":/images/johnny_automatic_marching_band_1.svg"); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
64 |
profile->scale(0.5,0.5); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
65 |
profile->setX(32); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
66 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
67 |
QGraphicsAnchorLayout *aLayout = new QGraphicsAnchorLayout; |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
68 |
aLayout->addAnchor(leftLayout,Qt::AnchorLeft,aLayout,Qt::AnchorLeft); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
69 |
aLayout->addAnchor(leftLayout,Qt::AnchorTop,aLayout,Qt::AnchorTop); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
70 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
71 |
// address |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
72 |
QGraphicsTextItem *address = new QGraphicsTextItem(); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
73 |
address->setDefaultTextColor(QColor(Qt::darkRed)); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
74 |
address->setHtml("<b>Symbian Foundation West</b><br/>Foster City<br/>California"); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
75 |
address->setPos(25, 225); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
76 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
77 |
QGraphicsWidget *widget = new QGraphicsWidget; |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
78 |
widget->setLayout(aLayout); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
79 |
scene->addItem(profile); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
80 |
scene->addItem(address); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
81 |
scene->addItem(widget); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
82 |
} |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
83 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
84 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
85 |
void DetailsGV::customizeView() |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
86 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
87 |
view->setBackgroundBrush(QColor("bisque")); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
88 |
view->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
89 |
} |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
90 |
|
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
91 |
void DetailsGV::createConnections() |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
92 |
{ |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
93 |
// if someone clicks on the exit button, propogate it to the QMainWindow. |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
94 |
connect(this->exitApp, SIGNAL(clicked()),this,SIGNAL(closeMe())); |
93c5a58496b6
add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
95 |
} |