diff options
author | Bernd Lamecker <bernd.lamecker@basyskom.de> | 2010-02-24 10:47:00 +0100 |
---|---|---|
committer | Bernd Lamecker <bernd.lamecker@basyskom.de> | 2010-02-24 16:10:33 +0100 |
commit | e4f13878570d993ebed588d96efb13b68fa979d6 (patch) | |
tree | ec7cd55dc4c8b9bd305c349d5ce8063153deb5ec /plainqt | |
parent | d57e7753c06b6d293cd4e0c09fa1d471b828f797 (diff) |
Changes: QHeaderView styling
RevBy: Torsten Rahn
Diffstat (limited to 'plainqt')
-rw-r--r-- | plainqt/style/qtmaemo6style.cpp | 103 | ||||
-rw-r--r-- | plainqt/style/qtmaemo6style_p.h | 23 |
2 files changed, 126 insertions, 0 deletions
diff --git a/plainqt/style/qtmaemo6style.cpp b/plainqt/style/qtmaemo6style.cpp index e47b4cb7..4895f11a 100644 --- a/plainqt/style/qtmaemo6style.cpp +++ b/plainqt/style/qtmaemo6style.cpp @@ -49,6 +49,7 @@ #include <QComboBox> #include <QLineEdit> #include <QTime> +#include <QHeaderView> #include <DuiComponentData> #include <DuiTheme> @@ -669,6 +670,50 @@ QRect QtMaemo6StylePrivate::scrollBarSliderRect(const QStyleOptionComplex *optio return QRect(); } +QPixmap QtMaemo6StylePrivate::borderCroppedPixmap(const DuiScalableImage* image, + QSize size, + int borders, + int borderLines) const +{ + int usedLeftBorder, usedTopBorder, usedRightBorder, usedBottomBorder; + image->borders(&usedLeftBorder, &usedTopBorder, &usedRightBorder, &usedBottomBorder); + + if(!(borders & topBorder)) + usedTopBorder = 0; + if(!(borders & rightBorder)) + usedRightBorder = 0; + if(!(borders & bottomBorder)) + usedBottomBorder = 0; + if(!(borders & leftBorder)) + usedLeftBorder = 0; + + QSize tempPixmapSize = size; + + QPixmap pix(tempPixmapSize + QSize(usedLeftBorder + usedRightBorder, usedTopBorder + usedBottomBorder)); + pix.fill(Qt::transparent); + QPainter pixPainter(&pix); + image->draw(QRect(QPoint(0,0), pix.size()), &pixPainter); + + //take the border color from the outermost top centered pixel + QColor borderColor = pix.copy(QRect(pix.size().width() / 2, 0, 1, 1)).toImage().pixel(0,0); + + //cut away borders + QPixmap finalPix = pix.copy(QRect(QPoint(usedLeftBorder,usedTopBorder), size)); + + //draw the closing lines + QPainter finalPainter(&finalPix); + finalPainter.setPen(QPen(borderColor, 2)); + if(borderLines & leftBorder) + finalPainter.drawLine(QPoint(1, 0), QPoint(1, finalPix.height())); + if(borderLines & topBorder) + finalPainter.drawLine(QPoint(0, 1), QPoint(finalPix.width(), 1)); + if(borderLines & rightBorder) + finalPainter.drawLine(QPoint(finalPix.width()-1, 0), QPoint(finalPix.width()-1, finalPix.height())); + if(borderLines & bottomBorder) + finalPainter.drawLine(QPoint(0, finalPix.height()-1), QPoint(finalPix.width(), finalPix.height()-1)); + return finalPix; +} + Qt::Alignment QtMaemo6StylePrivate::invertAlignment(Qt::Alignment align) const { Qt::Alignment retAlign; @@ -873,6 +918,9 @@ void QtMaemo6Style::polish(QWidget *widget) comboBox->lineEdit()->setReadOnly(false); } } + if(QHeaderView* hView = qobject_cast<QHeaderView*>(widget)) { + hView->viewport()->setBackgroundRole(QPalette::Window); + } } void QtMaemo6Style::drawPrimitive(PrimitiveElement element, @@ -1327,6 +1375,61 @@ void QtMaemo6Style::drawControl(ControlElement element, } } break; + case CE_HeaderSection: { + if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { + const DuiButtonStyle * style = + static_cast<const DuiButtonStyle *>( QtMaemo6StylePrivate::duiStyle( header->state, + "DuiButtonStyle") ); + + int left, top, right, bottom; + style->backgroundImage()->borders(&left, &top, &right, &bottom); + + p->fillRect(opt->rect, Qt::transparent); + + QtMaemo6StylePrivate::Borders leftBorder = QtMaemo6StylePrivate::leftBorder; + QtMaemo6StylePrivate::Borders rightBorder = QtMaemo6StylePrivate::rightBorder; + + if(opt->direction == Qt::RightToLeft) { + leftBorder = QtMaemo6StylePrivate::rightBorder; + rightBorder = QtMaemo6StylePrivate::leftBorder; + } + + if(header->orientation == Qt::Horizontal) { + if(header->position == QStyleOptionHeader::Beginning) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::bottomBorder | rightBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } else if(header->position == QStyleOptionHeader::Middle) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::bottomBorder | rightBorder | leftBorder, + QtMaemo6StylePrivate::bottomBorder | rightBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } else if(header->position == QStyleOptionHeader::End) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::bottomBorder | leftBorder, + QtMaemo6StylePrivate::bottomBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } + } else if(header->orientation == Qt::Vertical) { + if(header->position == QStyleOptionHeader::Beginning) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::bottomBorder | rightBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } else if(header->position == QStyleOptionHeader::Middle) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::bottomBorder | QtMaemo6StylePrivate::topBorder | rightBorder, + QtMaemo6StylePrivate::bottomBorder | rightBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } else if(header->position == QStyleOptionHeader::End) { + QPixmap pix = d->borderCroppedPixmap(style->backgroundImage(), opt->rect.size(), + QtMaemo6StylePrivate::topBorder | rightBorder, + rightBorder); + p->drawPixmap(opt->rect.topLeft(), pix); + } + } + } + } + break; default: { QtMaemo6TestStyle::drawControl(element, opt, p, widget); } diff --git a/plainqt/style/qtmaemo6style_p.h b/plainqt/style/qtmaemo6style_p.h index 9f573906..0f0683c9 100644 --- a/plainqt/style/qtmaemo6style_p.h +++ b/plainqt/style/qtmaemo6style_p.h @@ -275,6 +275,29 @@ public: QRect scrollBarSliderRect(const QStyleOptionComplex *option, const QWidget *widget = 0) const; /*! + * \brief returns a Pixmap with the given borders cropped away + * The given borders of the scalable image are cut away, the resulting pixmap will + * have size as size. If drawLines is true, lines are drawn on the cut away borders + * to close the pixmap. The color of these lines is taken from one of the pixmaps + * outermost pixels. + * \param image the image used as base + * \param size target size of the pixmap + * \param borders combined Borders flags that should be cut away + * \param borderLines optional draw closing lines on the given border sides. If not + * given border lines are drawn for all cut borders + */ + enum Borders { + leftBorder = 1, + topBorder = 2, + rightBorder = 4, + bottomBorder = 8 + }; + QPixmap borderCroppedPixmap(const DuiScalableImage* image, QSize size, int borders, int borderLines) const; + QPixmap borderCroppedPixmap(const DuiScalableImage* image, QSize size, int borders) const { + return borderCroppedPixmap(image, size, borders, borders); + } + + /*! * returns an inverted Alignment, so align right will become align left, top * will become bottom and so on */ |