added refresh on statusbar click
[qtmeetings] / src / UserInterface / Components / BorderedBarWidget.cpp
1 #include <QPainter>
2 #include "BorderedBarWidget.h"
3
4 BorderedBarWidget::BorderedBarWidget( QWidget *aParent ) :
5         QWidget( aParent ){
6         iCenterLabel = new QLabel(this);
7         iCenterLabel->setAlignment( Qt::AlignCenter );
8         iLeftLabel = new QLabel(this);
9         iLeftLabel->setAlignment( Qt::AlignLeading | Qt::AlignVCenter);
10         iRightLabel = new QLabel(this);
11         iRightLabel->setAlignment( Qt::AlignTrailing | Qt::AlignVCenter);
12 }
13
14 BorderedBarWidget::~BorderedBarWidget() {
15         delete iCenterLabel;
16         delete iLeftLabel;
17         delete iRightLabel;
18 }
19
20 QColor BorderedBarWidget::backgroundColor()
21 {
22         return iPalette.color( QPalette::Window );;
23 }
24
25 QColor BorderedBarWidget::faceColor()
26 {
27         return iPalette.color( QPalette::WindowText );;
28 }
29
30 int BorderedBarWidget::borderWidth()
31 {
32         return iBorderWidth;
33 }
34
35 QString BorderedBarWidget::text( TextPosition aPos )
36 {
37         if ( aPos == CenterAlign )
38                 return iCenterLabel->text();
39         else if ( aPos == LeftAlign )
40                 return iLeftLabel->text();
41         else if ( aPos == RightAlign )
42                 return iRightLabel->text();
43         return "";
44 }
45
46 void BorderedBarWidget::setBackgroundColor( QColor aColor )
47 {
48         iPalette.setColor( QPalette::Window, aColor );
49         iCenterLabel->setPalette( iPalette );
50         iLeftLabel->setPalette( iPalette );
51         iRightLabel->setPalette( iPalette );
52 }
53
54 void BorderedBarWidget::setFaceColor( QColor aColor )
55 {
56         iPalette.setColor( QPalette::WindowText, aColor );
57         iCenterLabel->setPalette( iPalette );
58         iLeftLabel->setPalette( iPalette );
59         iRightLabel->setPalette( iPalette );
60 }
61
62 void BorderedBarWidget::setBorderWidth( int aWidth )
63 {
64         iBorderWidth = aWidth;
65         iRightLabel->setMargin( 2*iBorderWidth );
66         iLeftLabel->setMargin( 2*iBorderWidth );
67 }
68
69 void BorderedBarWidget::setText( QString aText, TextPosition aPos )
70 {
71         if ( aPos == CenterAlign )
72                 iCenterLabel->setText( aText );
73         else if ( aPos == LeftAlign )
74                 iLeftLabel->setText( aText );
75         else if ( aPos == RightAlign )
76                 iRightLabel->setText( aText );
77 }
78
79 void BorderedBarWidget::setPixmap( QPixmap aPixmap, TextPosition aPos )
80 {
81         if ( aPos == CenterAlign )
82                 iCenterLabel->setPixmap( aPixmap );
83         else if ( aPos == LeftAlign )
84                 iLeftLabel->setPixmap( aPixmap );
85         else if ( aPos == RightAlign )
86                 iRightLabel->setPixmap( aPixmap );
87 }
88
89 void BorderedBarWidget::paintEvent(QPaintEvent *)
90 {
91         drawBorder();
92         iCenterLabel->setGeometry( rect() );
93         iLeftLabel->setGeometry( rect() );
94         iRightLabel->setGeometry( rect() );
95 }
96
97 void BorderedBarWidget::mousePressEvent( QMouseEvent * )
98 {
99         emit ( clicked() );
100 }
101
102
103 void BorderedBarWidget::drawCorner( QPainter &aPainter, QPoint &aCenter )
104 {
105         QRadialGradient radialGrad(QPointF(aCenter), iBorderWidth);
106         radialGrad.setColorAt(0, iPalette.color( QPalette::WindowText));
107         radialGrad.setColorAt(1, iPalette.color( QPalette::Window));
108     aPainter.setBrush(radialGrad);
109         aPainter.drawEllipse(QPoint(aCenter), iBorderWidth, iBorderWidth);
110 }
111
112 void BorderedBarWidget::drawSide( QPainter &aPainter, QPoint aStartPoint, QPoint aEndPoint )
113 {
114         QPoint d = aEndPoint - aStartPoint;
115         QPoint gradEnd = aStartPoint;
116         if ( abs( d.x() ) < abs( d.y() ) )
117                 gradEnd.setX( aEndPoint.x()+1 );
118         else
119                 gradEnd.setY( aEndPoint.y()+1 );
120
121         QLinearGradient linearGradTop(aStartPoint, gradEnd);
122         linearGradTop.setColorAt(0, iPalette.color( QPalette::Window));
123         linearGradTop.setColorAt(1, iPalette.color( QPalette::WindowText));
124     aPainter.setBrush(linearGradTop);
125         aPainter.drawRect( QRect(aStartPoint,aEndPoint) );
126 }
127
128 void BorderedBarWidget::drawBorder()
129 {
130         QPainter painter(this);
131     painter.setPen(Qt::NoPen);
132         painter.setRenderHint(QPainter::Antialiasing, true);
133
134         /*top left corner*/
135         QPoint center(iBorderWidth,iBorderWidth);
136         drawCorner( painter, center );
137
138         /*top right corner*/
139         center.setX( this->rect().right()-iBorderWidth );
140         center.setY( iBorderWidth );
141         drawCorner( painter, center );
142
143         /*bottom left corner*/
144         center.setX( iBorderWidth );
145         center.setY( this->rect().bottom()-iBorderWidth );
146         drawCorner( painter, center );
147
148         /*bottom right corner*/
149         center.setX( this->rect().right()-iBorderWidth );
150         center.setY( this->rect().bottom()-iBorderWidth );
151         drawCorner( painter, center );
152
153         /*top*/
154         drawSide( painter, QPoint(iBorderWidth,0), QPoint(this->rect().right()-(iBorderWidth+1),(iBorderWidth-1)) );
155
156         /*right*/
157         drawSide( painter, QPoint(this->rect().right(),this->rect().bottom()-iBorderWidth), QPoint(this->rect().right()-(iBorderWidth+1),iBorderWidth-1) );
158
159         /*bottom*/
160         drawSide( painter, QPoint(this->rect().right()-iBorderWidth, this->rect().bottom()), QPoint((iBorderWidth-1),this->rect().bottom()-(iBorderWidth+1)) );
161
162         /*left*/
163         drawSide( painter, QPoint(0,iBorderWidth), QPoint((iBorderWidth-1), this->rect().bottom()-(iBorderWidth+1)) );
164
165         /*inside*/
166         QBrush brush( iPalette.color( QPalette::Window ) );
167         painter.setBrush(brush);
168         QRect inside(iBorderWidth,iBorderWidth,this->rect().right()-2*iBorderWidth,this->rect().bottom()-2*iBorderWidth);
169         painter.drawRoundRect(inside,iBorderWidth,iBorderWidth);
170
171 }