contactengine/detailsgv.cpp
changeset 34 93c5a58496b6
child 35 0cb8cc1ee8f5
equal deleted inserted replaced
33:f6cf541961ad 34:93c5a58496b6
       
     1 #include "detailsgv.h"
       
     2 
       
     3 #include <QColor>
       
     4 #include <QGraphicsTextItem>
       
     5 #include <QGraphicsWidget>
       
     6 #include <QGraphicsLinearLayout>
       
     7 #include <QGraphicsAnchorLayout>
       
     8 #include <QGraphicsPixmapItem>
       
     9 #include <QGraphicsSvgItem>
       
    10 #include <QPixmap>
       
    11 #include <QTransform>
       
    12 
       
    13 DetailsGV::DetailsGV(QObject *parent,QGraphicsView *gv) :
       
    14     QObject(parent), view(gv)
       
    15 {
       
    16     scene = new QGraphicsScene(this);
       
    17     gv->setScene(scene);
       
    18     this->createWidgets();
       
    19     this->createProxyWidgets();
       
    20     this->createLayout();
       
    21     this->createConnections();
       
    22     this->customizeView();
       
    23 }
       
    24 
       
    25 
       
    26 void DetailsGV::createWidgets()
       
    27 {
       
    28     QString styleSheet("background-color:red");
       
    29     callMe = new QPushButton(tr("call us"));
       
    30     callMe->setStyleSheet(styleSheet);
       
    31     textMe = new QPushButton(tr("text us"));
       
    32     textMe->setStyleSheet(styleSheet);
       
    33     back = new QPushButton (tr("back"));
       
    34     back->setStyleSheet(styleSheet);
       
    35     exitApp = new QPushButton(tr("exit"));
       
    36     exitApp->setStyleSheet(styleSheet);
       
    37 }
       
    38 
       
    39 void DetailsGV::createProxyWidgets()
       
    40 {
       
    41     proxyForName["callMe"] = scene->addWidget(callMe);
       
    42     proxyForName["textMe"] = scene->addWidget(textMe);
       
    43     proxyForName["back"] = scene->addWidget(back);
       
    44     proxyForName["exitApp"] = scene->addWidget(exitApp);
       
    45 }
       
    46 
       
    47 void DetailsGV::createLayout()
       
    48 {
       
    49     // row of buttons
       
    50     QGraphicsLinearLayout *leftLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    51     leftLayout->addItem(proxyForName["callMe"]);
       
    52     leftLayout->addItem(proxyForName["textMe"]);
       
    53     leftLayout->addItem(proxyForName["back"]);
       
    54     leftLayout->addItem(proxyForName["exitApp"]);
       
    55 
       
    56      // looks like there is a bug with respect to displaying jpeg's in a scene on Symbian^1.
       
    57      // I've asked about it on the mailing list QtS60-feedback@trolltech.com.
       
    58      //QGraphicsPixmapItem *profile = new QGraphicsPixmapItem( QPixmap(":/images/MadProf_thumb.jpg"));
       
    59      // strange returns width of screen not button ?
       
    60      // int w = this->callMe->width();
       
    61      // profile->setX(100);
       
    62 
       
    63      // svg from open clipart (http://www.openclipart.org/detail/959)
       
    64      QGraphicsSvgItem *profile = new QGraphicsSvgItem(":/images/johnny_automatic_marching_band_1.svg");
       
    65      profile->scale(0.5,0.5);
       
    66      profile->setX(32);
       
    67 
       
    68      QGraphicsAnchorLayout *aLayout = new QGraphicsAnchorLayout;
       
    69      aLayout->addAnchor(leftLayout,Qt::AnchorLeft,aLayout,Qt::AnchorLeft);
       
    70      aLayout->addAnchor(leftLayout,Qt::AnchorTop,aLayout,Qt::AnchorTop);
       
    71 
       
    72     // address
       
    73      QGraphicsTextItem *address = new QGraphicsTextItem();
       
    74      address->setDefaultTextColor(QColor(Qt::darkRed));
       
    75      address->setHtml("<b>Symbian Foundation West</b><br/>Foster City<br/>California");
       
    76      address->setPos(25, 225);
       
    77 
       
    78      QGraphicsWidget *widget = new QGraphicsWidget;
       
    79      widget->setLayout(aLayout);
       
    80      scene->addItem(profile);
       
    81      scene->addItem(address);
       
    82      scene->addItem(widget);
       
    83 }
       
    84 
       
    85 
       
    86 void DetailsGV::customizeView()
       
    87 {
       
    88     view->setBackgroundBrush(QColor("bisque"));
       
    89     view->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
       
    90 }
       
    91 
       
    92 void DetailsGV::createConnections()
       
    93 {
       
    94     // if someone clicks on the exit button, propogate it to the QMainWindow.
       
    95     connect(this->exitApp, SIGNAL(clicked()),this,SIGNAL(closeMe()));
       
    96 }