Personal infotab contents merged, reviewed by wallika
[situare] / src / ui / infotab.cpp
1 #include "infotab.h"
2
3 InfoTab::InfoTab(QWidget *parent)
4     : QWidget(parent, Qt::FramelessWindowHint)
5 {
6     layout = new QGridLayout(this);
7     userPicture = new QLabel;
8     userNameLabel = new QLabel;
9     messageLabel = new QLabel;
10     addressLabel = new QLabel;
11     timeLabel = new QLabel;
12     QLabel *clockLabel = new QLabel;
13     QLabel *envelopeLabel = new QLabel;
14     QLabel *compassLabel = new QLabel;
15     QToolButton *sendLocationButton = new QToolButton;
16     QToolButton *updateStatusMessageButton = new QToolButton;
17
18     sendLocationButton->setIcon(QIcon(QPixmap(":/resources/reload_icon.png")));
19     updateStatusMessageButton->setIcon(QIcon(QPixmap(":/resources/sendPosition_icon.png")));
20
21     clockLabel->setPixmap(QPixmap(":/resources/clock_small.png"));
22     envelopeLabel->setPixmap(QPixmap(":/resources/list_small.png"));
23     compassLabel->setPixmap(QPixmap(":/resources/compas_small.png"));
24     layout->addWidget(userPicture,0,0,4,1);
25     layout->addWidget(userNameLabel,0,2,1,2);
26     layout->addWidget(clockLabel,1,1,1,1);
27     layout->addWidget(envelopeLabel,2,1,1,1);
28     layout->addWidget(compassLabel,3,1,1,1);
29     layout->addWidget(timeLabel,1,2,1,1);
30     layout->addWidget(messageLabel,2,2,1,1);
31     layout->addWidget(addressLabel,3,2,1,1);
32     layout->addWidget(sendLocationButton,0,3,2,1);
33     layout->addWidget(updateStatusMessageButton,1,3,2,1);
34
35 }
36
37 InfoTab::~InfoTab()
38 {
39     if (userPicture)
40         delete userPicture;
41     if (userNameLabel)
42         delete userNameLabel;
43     if (messageLabel)
44         delete messageLabel;
45     if (addressLabel)
46         delete addressLabel;
47     if (timeLabel)
48         delete timeLabel;
49     if (layout)
50         delete layout;
51     userPicture=NULL;
52     userNameLabel=NULL;
53     messageLabel=NULL;
54     addressLabel=NULL;
55     timeLabel=NULL;
56     layout=NULL;
57 }
58
59 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
60 {
61     //Look and feel settings
62     QPalette qpalette;
63     QColor myColor(Qt::black);
64     myColor.setAlpha(50);
65     qpalette.setColor(QPalette::Background,myColor);
66     setPalette(qpalette);
67     int roundness(6);
68
69     QRect widgetRect = this->rect();
70     QPainter painter(this);
71     painter.save();
72
73     painter.setRenderHint(QPainter::Antialiasing);
74     QPainterPath roundedRect;
75     roundedRect.addRoundedRect(1,1,widgetRect.width() - 2, widgetRect.height()-2,roundness,roundness);
76
77     painter.setClipPath(roundedRect);
78     QRegion maskRegion = painter.clipRegion();
79
80     setMask(maskRegion);
81
82     painter.fillPath(roundedRect,QBrush(myColor));
83     painter.restore();
84 }
85
86 void InfoTab::setAvatar(const QPixmap &avat)
87 {
88     avatar = avat;
89     userPicture->setPixmap(avat);
90 }
91
92 void InfoTab::setUserName(const QString &usernam)
93 {
94     if(userName == usernam)
95       return;
96     userName = usernam;
97     userNameLabel->setText(userName);
98 }
99
100 void InfoTab::setMessageText(const QString &text)
101 {
102     if(messageText == text)
103       return;
104     messageText = text;
105     messageLabel->setText(messageText);
106 }
107
108 void InfoTab::setAddress(const QString &addr)
109 {
110     if(address == addr)
111       return;
112     address = addr;
113     addressLabel->setText(address);
114 }
115
116 void InfoTab::setTime(const QString &tim)
117 {
118     if(time == tim)
119       return;
120     time = tim;
121     timeLabel->setText(time);
122 }