contactengine/detailsgv.cpp
author John Kern <johnk@symbian.org>
Wed, 18 Aug 2010 16:39:30 -0700
changeset 34 93c5a58496b6
child 35 0cb8cc1ee8f5
permissions -rwxr-xr-x
add graphics view which presents contacts details
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    56
     // looks like there is a bug with respect to displaying jpeg's in a scene on Symbian^1.
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    57
     // I've asked about it on the mailing list QtS60-feedback@trolltech.com.
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    58
     //QGraphicsPixmapItem *profile = new QGraphicsPixmapItem( QPixmap(":/images/MadProf_thumb.jpg"));
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    59
     // strange returns width of screen not button ?
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    60
     // int w = this->callMe->width();
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    61
     // profile->setX(100);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    62
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    63
     // 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
    64
     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
    65
     profile->scale(0.5,0.5);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    66
     profile->setX(32);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    67
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    68
     QGraphicsAnchorLayout *aLayout = new QGraphicsAnchorLayout;
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    69
     aLayout->addAnchor(leftLayout,Qt::AnchorLeft,aLayout,Qt::AnchorLeft);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    70
     aLayout->addAnchor(leftLayout,Qt::AnchorTop,aLayout,Qt::AnchorTop);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    71
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    72
    // address
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    73
     QGraphicsTextItem *address = new QGraphicsTextItem();
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
     address->setDefaultTextColor(QColor(Qt::darkRed));
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    75
     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
    76
     address->setPos(25, 225);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    77
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    78
     QGraphicsWidget *widget = new QGraphicsWidget;
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    79
     widget->setLayout(aLayout);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    80
     scene->addItem(profile);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    81
     scene->addItem(address);
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    82
     scene->addItem(widget);
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
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    86
void DetailsGV::customizeView()
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    87
{
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    88
    view->setBackgroundBrush(QColor("bisque"));
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    89
    view->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
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
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    92
void DetailsGV::createConnections()
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    93
{
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    94
    // 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
    95
    connect(this->exitApp, SIGNAL(clicked()),this,SIGNAL(closeMe()));
93c5a58496b6 add graphics view which presents contacts details
John Kern <johnk@symbian.org>
parents:
diff changeset
    96
}