2 #include "BorderedBarWidget.h"
4 BorderedBarWidget::BorderedBarWidget( 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);
14 BorderedBarWidget::~BorderedBarWidget() {
20 QColor BorderedBarWidget::backgroundColor()
22 return iPalette.color( QPalette::Window );;
25 QColor BorderedBarWidget::faceColor()
27 return iPalette.color( QPalette::WindowText );;
30 int BorderedBarWidget::borderWidth()
35 QString BorderedBarWidget::text( TextPosition aPos )
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();
46 void BorderedBarWidget::setBackgroundColor( QColor aColor )
48 iPalette.setColor( QPalette::Window, aColor );
49 iCenterLabel->setPalette( iPalette );
50 iLeftLabel->setPalette( iPalette );
51 iRightLabel->setPalette( iPalette );
54 void BorderedBarWidget::setFaceColor( QColor aColor )
56 iPalette.setColor( QPalette::WindowText, aColor );
57 iCenterLabel->setPalette( iPalette );
58 iLeftLabel->setPalette( iPalette );
59 iRightLabel->setPalette( iPalette );
62 void BorderedBarWidget::setBorderWidth( int aWidth )
64 iBorderWidth = aWidth;
65 iRightLabel->setMargin( 2*iBorderWidth );
66 iLeftLabel->setMargin( 2*iBorderWidth );
69 void BorderedBarWidget::setText( QString aText, TextPosition aPos )
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 );
79 void BorderedBarWidget::setPixmap( QPixmap aPixmap, TextPosition aPos )
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 );
89 void BorderedBarWidget::paintEvent(QPaintEvent *)
92 iCenterLabel->setGeometry( rect() );
93 iLeftLabel->setGeometry( rect() );
94 iRightLabel->setGeometry( rect() );
97 void BorderedBarWidget::drawCorner( QPainter &aPainter, QPoint &aCenter )
99 QRadialGradient radialGrad(QPointF(aCenter), iBorderWidth);
100 radialGrad.setColorAt(0, iPalette.color( QPalette::WindowText));
101 radialGrad.setColorAt(1, iPalette.color( QPalette::Window));
102 aPainter.setBrush(radialGrad);
103 aPainter.drawEllipse(QPoint(aCenter), iBorderWidth, iBorderWidth);
106 void BorderedBarWidget::drawSide( QPainter &aPainter, QPoint aStartPoint, QPoint aEndPoint )
108 QPoint d = aEndPoint - aStartPoint;
109 QPoint gradEnd = aStartPoint;
110 if ( abs( d.x() ) < abs( d.y() ) )
111 gradEnd.setX( aEndPoint.x()+1 );
113 gradEnd.setY( aEndPoint.y()+1 );
115 QLinearGradient linearGradTop(aStartPoint, gradEnd);
116 linearGradTop.setColorAt(0, iPalette.color( QPalette::Window));
117 linearGradTop.setColorAt(1, iPalette.color( QPalette::WindowText));
118 aPainter.setBrush(linearGradTop);
119 aPainter.drawRect( QRect(aStartPoint,aEndPoint) );
122 void BorderedBarWidget::drawBorder()
124 QPainter painter(this);
125 painter.setPen(Qt::NoPen);
126 painter.setRenderHint(QPainter::Antialiasing, true);
129 QPoint center(iBorderWidth,iBorderWidth);
130 drawCorner( painter, center );
133 center.setX( this->rect().right()-iBorderWidth );
134 center.setY( iBorderWidth );
135 drawCorner( painter, center );
137 /*bottom left corner*/
138 center.setX( iBorderWidth );
139 center.setY( this->rect().bottom()-iBorderWidth );
140 drawCorner( painter, center );
142 /*bottom right corner*/
143 center.setX( this->rect().right()-iBorderWidth );
144 center.setY( this->rect().bottom()-iBorderWidth );
145 drawCorner( painter, center );
148 drawSide( painter, QPoint(iBorderWidth,0), QPoint(this->rect().right()-(iBorderWidth+1),(iBorderWidth-1)) );
151 drawSide( painter, QPoint(this->rect().right(),this->rect().bottom()-iBorderWidth), QPoint(this->rect().right()-(iBorderWidth+1),iBorderWidth-1) );
154 drawSide( painter, QPoint(this->rect().right()-iBorderWidth, this->rect().bottom()), QPoint((iBorderWidth-1),this->rect().bottom()-(iBorderWidth+1)) );
157 drawSide( painter, QPoint(0,iBorderWidth), QPoint((iBorderWidth-1), this->rect().bottom()-(iBorderWidth+1)) );
160 QBrush brush( iPalette.color( QPalette::Window ) );
161 painter.setBrush(brush);
162 QRect inside(iBorderWidth,iBorderWidth,this->rect().right()-2*iBorderWidth,this->rect().bottom()-2*iBorderWidth);
163 painter.drawRoundRect(inside,iBorderWidth,iBorderWidth);