X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2FUserInterface%2FComponents%2FBorderedBarWidget.cpp;fp=src%2FUserInterface%2FComponents%2FBorderedBarWidget.cpp;h=67356e4db110e3161ad59c6f1cc18c0bd63fe0cd;hb=663a2fc8ce3a0b8b987655fe709a831a3db9b315;hp=0000000000000000000000000000000000000000;hpb=59b4a9d85f3cd02e90c8efcecc66f9150f8a61f8;p=qtmeetings diff --git a/src/UserInterface/Components/BorderedBarWidget.cpp b/src/UserInterface/Components/BorderedBarWidget.cpp new file mode 100644 index 0000000..67356e4 --- /dev/null +++ b/src/UserInterface/Components/BorderedBarWidget.cpp @@ -0,0 +1,165 @@ +#include +#include "BorderedBarWidget.h" + +BorderedBarWidget::BorderedBarWidget( QWidget *aParent ) : + QWidget( aParent ){ + iCenterLabel = new QLabel(this); + iCenterLabel->setAlignment( Qt::AlignCenter ); + iLeftLabel = new QLabel(this); + iLeftLabel->setAlignment( Qt::AlignLeading | Qt::AlignVCenter); + iRightLabel = new QLabel(this); + iRightLabel->setAlignment( Qt::AlignTrailing | Qt::AlignVCenter); +} + +BorderedBarWidget::~BorderedBarWidget() { + delete iCenterLabel; + delete iLeftLabel; + delete iRightLabel; +} + +QColor BorderedBarWidget::backgroundColor() +{ + return iPalette.color( QPalette::Window );; +} + +QColor BorderedBarWidget::faceColor() +{ + return iPalette.color( QPalette::WindowText );; +} + +int BorderedBarWidget::borderWidth() +{ + return iBorderWidth; +} + +QString BorderedBarWidget::text( TextPosition aPos ) +{ + if ( aPos == CenterAlign ) + return iCenterLabel->text(); + else if ( aPos == LeftAlign ) + return iLeftLabel->text(); + else if ( aPos == RightAlign ) + return iRightLabel->text(); + return ""; +} + +void BorderedBarWidget::setBackgroundColor( QColor aColor ) +{ + iPalette.setColor( QPalette::Window, aColor ); + iCenterLabel->setPalette( iPalette ); + iLeftLabel->setPalette( iPalette ); + iRightLabel->setPalette( iPalette ); +} + +void BorderedBarWidget::setFaceColor( QColor aColor ) +{ + iPalette.setColor( QPalette::WindowText, aColor ); + iCenterLabel->setPalette( iPalette ); + iLeftLabel->setPalette( iPalette ); + iRightLabel->setPalette( iPalette ); +} + +void BorderedBarWidget::setBorderWidth( int aWidth ) +{ + iBorderWidth = aWidth; + iRightLabel->setMargin( 2*iBorderWidth ); + iLeftLabel->setMargin( 2*iBorderWidth ); +} + +void BorderedBarWidget::setText( QString aText, TextPosition aPos ) +{ + if ( aPos == CenterAlign ) + iCenterLabel->setText( aText ); + else if ( aPos == LeftAlign ) + iLeftLabel->setText( aText ); + else if ( aPos == RightAlign ) + iRightLabel->setText( aText ); +} + +void BorderedBarWidget::setPixmap( QPixmap aPixmap, TextPosition aPos ) +{ + if ( aPos == CenterAlign ) + iCenterLabel->setPixmap( aPixmap ); + else if ( aPos == LeftAlign ) + iLeftLabel->setPixmap( aPixmap ); + else if ( aPos == RightAlign ) + iRightLabel->setPixmap( aPixmap ); +} + +void BorderedBarWidget::paintEvent(QPaintEvent *) +{ + drawBorder(); + iCenterLabel->setGeometry( rect() ); + iLeftLabel->setGeometry( rect() ); + iRightLabel->setGeometry( rect() ); +} + +void BorderedBarWidget::drawCorner( QPainter &aPainter, QPoint &aCenter ) +{ + QRadialGradient radialGrad(QPointF(aCenter), iBorderWidth); + radialGrad.setColorAt(0, iPalette.color( QPalette::WindowText)); + radialGrad.setColorAt(1, iPalette.color( QPalette::Window)); + aPainter.setBrush(radialGrad); + aPainter.drawEllipse(QPoint(aCenter), iBorderWidth, iBorderWidth); +} + +void BorderedBarWidget::drawSide( QPainter &aPainter, QPoint aStartPoint, QPoint aEndPoint ) +{ + QPoint d = aEndPoint - aStartPoint; + QPoint gradEnd = aStartPoint; + if ( abs( d.x() ) < abs( d.y() ) ) + gradEnd.setX( aEndPoint.x()+1 ); + else + gradEnd.setY( aEndPoint.y()+1 ); + + QLinearGradient linearGradTop(aStartPoint, gradEnd); + linearGradTop.setColorAt(0, iPalette.color( QPalette::Window)); + linearGradTop.setColorAt(1, iPalette.color( QPalette::WindowText)); + aPainter.setBrush(linearGradTop); + aPainter.drawRect( QRect(aStartPoint,aEndPoint) ); +} + +void BorderedBarWidget::drawBorder() +{ + QPainter painter(this); + painter.setPen(Qt::NoPen); + painter.setRenderHint(QPainter::Antialiasing, true); + + /*top left corner*/ + QPoint center(iBorderWidth,iBorderWidth); + drawCorner( painter, center ); + + /*top right corner*/ + center.setX( this->rect().right()-iBorderWidth ); + center.setY( iBorderWidth ); + drawCorner( painter, center ); + + /*bottom left corner*/ + center.setX( iBorderWidth ); + center.setY( this->rect().bottom()-iBorderWidth ); + drawCorner( painter, center ); + + /*bottom right corner*/ + center.setX( this->rect().right()-iBorderWidth ); + center.setY( this->rect().bottom()-iBorderWidth ); + drawCorner( painter, center ); + + /*top*/ + drawSide( painter, QPoint(iBorderWidth,0), QPoint(this->rect().right()-(iBorderWidth+1),(iBorderWidth-1)) ); + + /*right*/ + drawSide( painter, QPoint(this->rect().right(),this->rect().bottom()-iBorderWidth), QPoint(this->rect().right()-(iBorderWidth+1),iBorderWidth-1) ); + + /*bottom*/ + drawSide( painter, QPoint(this->rect().right()-iBorderWidth, this->rect().bottom()), QPoint((iBorderWidth-1),this->rect().bottom()-(iBorderWidth+1)) ); + + /*left*/ + drawSide( painter, QPoint(0,iBorderWidth), QPoint((iBorderWidth-1), this->rect().bottom()-(iBorderWidth+1)) ); + + /*inside*/ + QBrush brush( iPalette.color( QPalette::Window ) ); + painter.setBrush(brush); + QRect inside(iBorderWidth,iBorderWidth,this->rect().right()-2*iBorderWidth,this->rect().bottom()-2*iBorderWidth); + painter.drawRoundRect(inside,iBorderWidth,iBorderWidth); + +}