forked from qt-creator/qt-creator
Simplify drawing of styled bar by just using the style.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
#include <QtGui/QPixmapCache>
|
#include <QtGui/QPixmapCache>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
|
#include <QtGui/QStyleOption>
|
||||||
|
|
||||||
using namespace Core::Utils;
|
using namespace Core::Utils;
|
||||||
|
|
||||||
@@ -30,48 +31,10 @@ void StyledBar::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
QStyleOption option;
|
||||||
QRect selfRect = rect();
|
option.rect = rect();
|
||||||
QString key;
|
option.state = QStyle::State_Horizontal;
|
||||||
key.sprintf("mh_toolbar %d %d %d", selfRect.width(), selfRect.height(), StyleHelper::baseColor().rgb());;
|
style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this);
|
||||||
|
|
||||||
QPixmap pixmap;
|
|
||||||
QPainter *p = &painter;
|
|
||||||
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
|
|
||||||
pixmap = QPixmap(selfRect.size());
|
|
||||||
p = new QPainter(&pixmap);
|
|
||||||
selfRect = QRect(0, 0, selfRect.width(), selfRect.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map offset for global window gradient
|
|
||||||
QPoint offset = window()->mapToGlobal(selfRect.topLeft()) -
|
|
||||||
mapToGlobal(selfRect.topLeft());
|
|
||||||
QRect gradientSpan;
|
|
||||||
gradientSpan = QRect(offset, window()->size());
|
|
||||||
StyleHelper::horizontalGradient(p, gradientSpan, selfRect);
|
|
||||||
|
|
||||||
p->setPen(StyleHelper::borderColor());
|
|
||||||
|
|
||||||
// Note: This is a hack to determine if the
|
|
||||||
// toolbar should draw the top or bottom outline
|
|
||||||
// (needed for the find toolbar for instance)
|
|
||||||
QColor lighter(255, 255, 255, 40);
|
|
||||||
if (property("topBorder").toBool()) {
|
|
||||||
p->drawLine(selfRect.topLeft(), selfRect.topRight());
|
|
||||||
p->setPen(lighter);
|
|
||||||
p->drawLine(selfRect.topLeft() + QPoint(0, 1), selfRect.topRight() + QPoint(0, 1));
|
|
||||||
} else {
|
|
||||||
p->drawLine(selfRect.bottomLeft(), selfRect.bottomRight());
|
|
||||||
p->setPen(lighter);
|
|
||||||
p->drawLine(selfRect.topLeft(), selfRect.topRight());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
|
|
||||||
painter.drawPixmap(selfRect.topLeft(), pixmap);
|
|
||||||
p->end();
|
|
||||||
delete p;
|
|
||||||
QPixmapCache::insert(key, pixmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledSeparator::StyledSeparator(QWidget *parent)
|
StyledSeparator::StyledSeparator(QWidget *parent)
|
||||||
@@ -84,15 +47,9 @@ void StyledSeparator::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QRect selfRect = rect();
|
QStyleOption option;
|
||||||
|
option.rect = rect();
|
||||||
QColor separatorColor = StyleHelper::borderColor();
|
option.state = QStyle::State_Horizontal;
|
||||||
separatorColor.setAlpha(100);
|
option.palette = palette();
|
||||||
painter.setPen(separatorColor);
|
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &option, &painter, this);
|
||||||
const int margin = 6;
|
|
||||||
const int offset = selfRect.width()/2;
|
|
||||||
painter.drawLine(selfRect.bottomLeft().x() + offset,
|
|
||||||
selfRect.bottomLeft().y() - margin,
|
|
||||||
selfRect.topLeft().x() + offset,
|
|
||||||
selfRect.topLeft().y() + margin);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user