Added light colored version of manhattan style's bars

Reviewed-by: jbache
This commit is contained in:
Olli Werwolff
2010-02-19 09:54:29 +01:00
parent a71b284078
commit 70b3f0e2b7
5 changed files with 132 additions and 72 deletions

View File

@@ -44,6 +44,7 @@ StyledBar::StyledBar(QWidget *parent)
{ {
setProperty("panelwidget", true); setProperty("panelwidget", true);
setProperty("panelwidget_singlerow", true); setProperty("panelwidget_singlerow", true);
setProperty("lightColored", false);
} }
void StyledBar::setSingleRow(bool singleRow) void StyledBar::setSingleRow(bool singleRow)
@@ -56,6 +57,16 @@ bool StyledBar::isSingleRow() const
return property("panelwidget_singlerow").toBool(); return property("panelwidget_singlerow").toBool();
} }
void StyledBar::setLightColored(bool lightColored)
{
setProperty("lightColored", lightColored);
}
bool StyledBar::isLightColored() const
{
return property("lightColored").toBool();
}
void StyledBar::paintEvent(QPaintEvent *event) void StyledBar::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)

View File

@@ -42,6 +42,10 @@ public:
StyledBar(QWidget *parent = 0); StyledBar(QWidget *parent = 0);
void setSingleRow(bool singleRow); void setSingleRow(bool singleRow);
bool isSingleRow() const; bool isSingleRow() const;
void setLightColored(bool lightColored);
bool isLightColored() const;
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
}; };

View File

@@ -83,40 +83,51 @@ QPalette StyleHelper::sidebarFontPalette(const QPalette &original)
return palette; return palette;
} }
QColor StyleHelper::panelTextColor() QColor StyleHelper::panelTextColor(bool lightColored)
{ {
//qApp->palette().highlightedText().color(); //qApp->palette().highlightedText().color();
return Qt::white; if (!lightColored)
return Qt::white;
else
return Qt::black;
} }
QColor StyleHelper::m_baseColor(0x666666); QColor StyleHelper::m_baseColor(0x666666);
QColor StyleHelper::baseColor() QColor StyleHelper::baseColor(bool lightColored)
{ {
return m_baseColor; if (!lightColored)
return m_baseColor;
else
return m_baseColor.lighter(230);
} }
QColor StyleHelper::highlightColor() QColor StyleHelper::highlightColor(bool lightColored)
{ {
QColor result = baseColor(); QColor result = baseColor(lightColored);
result.setHsv(result.hue(), if (!lightColored)
result.setHsv(result.hue(),
clamp(result.saturation()), clamp(result.saturation()),
clamp(result.value() * 1.16)); clamp(result.value() * 1.16));
else
result.setHsv(result.hue(),
clamp(result.saturation()),
clamp(result.value() * 1.06));
return result; return result;
} }
QColor StyleHelper::shadowColor() QColor StyleHelper::shadowColor(bool lightColored)
{ {
QColor result = baseColor(); QColor result = baseColor(lightColored);
result.setHsv(result.hue(), result.setHsv(result.hue(),
clamp(result.saturation() * 1.1), clamp(result.saturation() * 1.1),
clamp(result.value() * 0.70)); clamp(result.value() * 0.70));
return result; return result;
} }
QColor StyleHelper::borderColor() QColor StyleHelper::borderColor(bool lightColored)
{ {
QColor result = baseColor(); QColor result = baseColor(lightColored);
result.setHsv(result.hue(), result.setHsv(result.hue(),
result.saturation(), result.saturation(),
result.value() / 2); result.value() / 2);
@@ -132,13 +143,15 @@ void StyleHelper::setBaseColor(const QColor &color)
} }
} }
static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect) static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored)
{ {
QColor base = StyleHelper::baseColor(); QColor base = StyleHelper::baseColor(lightColored);
QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, StyleHelper::highlightColor()); grad.setColorAt(0, highlight);
grad.setColorAt(0.301, base); grad.setColorAt(0.301, base);
grad.setColorAt(1, StyleHelper::shadowColor()); grad.setColorAt(1, shadow);
p->fillRect(rect, grad); p->fillRect(rect, grad);
QColor light(255, 255, 255, 80); QColor light(255, 255, 255, 80);
@@ -146,67 +159,74 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe
p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
} }
void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored)
{ {
if (StyleHelper::usePixmapCache()) { if (StyleHelper::usePixmapCache()) {
QString key; QString key;
QColor keyColor = baseColor(lightColored);
key.sprintf("mh_vertical %d %d %d %d %d", key.sprintf("mh_vertical %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(), spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb());; clipRect.height(), keyColor.rgb());;
QPixmap pixmap; QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) { if (!QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size()); pixmap = QPixmap(clipRect.size());
QPainter p(&pixmap); QPainter p(&pixmap);
QRect rect(0, 0, clipRect.width(), clipRect.height()); QRect rect(0, 0, clipRect.width(), clipRect.height());
verticalGradientHelper(&p, spanRect, rect); verticalGradientHelper(&p, spanRect, rect, lightColored);
p.end(); p.end();
QPixmapCache::insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
painter->drawPixmap(clipRect.topLeft(), pixmap); painter->drawPixmap(clipRect.topLeft(), pixmap);
} else { } else {
verticalGradientHelper(painter, spanRect, clipRect); verticalGradientHelper(painter, spanRect, clipRect, lightColored);
} }
} }
static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const
QRect &rect) QRect &rect, bool lightColored)
{ {
QColor base = StyleHelper::baseColor(); QColor base = StyleHelper::baseColor(lightColored);
QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); QLinearGradient grad(rect.topLeft(), rect.bottomLeft());
grad.setColorAt(0, StyleHelper::highlightColor().lighter(120)); grad.setColorAt(0, highlight.lighter(120));
if (rect.height() == StyleHelper::navigationWidgetHeight()) { if (rect.height() == StyleHelper::navigationWidgetHeight()) {
grad.setColorAt(0.4, StyleHelper::highlightColor()); grad.setColorAt(0.4, highlight);
grad.setColorAt(0.401, base); grad.setColorAt(0.401, base);
} }
grad.setColorAt(1, StyleHelper::shadowColor()); grad.setColorAt(1, shadow);
p->fillRect(rect, grad); p->fillRect(rect, grad);
QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
QColor highlight = StyleHelper::highlightColor().lighter(130); QColor lighterHighlight;
highlight.setAlpha(100); if (!lightColored)
shadowGradient.setColorAt(0.7, highlight); lighterHighlight = highlight.lighter(130);
shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); else
lighterHighlight = highlight.lighter(90);
lighterHighlight.setAlpha(100);
shadowGradient.setColorAt(0.7, lighterHighlight);
shadowGradient.setColorAt(1, QColor(0, 0, 0, 40));
p->fillRect(rect, shadowGradient); p->fillRect(rect, shadowGradient);
} }
void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored)
{ {
if (StyleHelper::usePixmapCache()) { if (StyleHelper::usePixmapCache()) {
QString key; QString key;
QColor keyColor = baseColor(lightColored);
key.sprintf("mh_horizontal %d %d %d %d %d", key.sprintf("mh_horizontal %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(), spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb()); clipRect.height(), keyColor.rgb());
QPixmap pixmap; QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) { if (!QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size()); pixmap = QPixmap(clipRect.size());
QPainter p(&pixmap); QPainter p(&pixmap);
QRect rect = QRect(0, 0, clipRect.width(), clipRect.height()); QRect rect = QRect(0, 0, clipRect.width(), clipRect.height());
horizontalGradientHelper(&p, spanRect, rect); horizontalGradientHelper(&p, spanRect, rect, lightColored);
p.end(); p.end();
QPixmapCache::insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
@@ -214,7 +234,7 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c
painter->drawPixmap(clipRect.topLeft(), pixmap); painter->drawPixmap(clipRect.topLeft(), pixmap);
} else { } else {
horizontalGradientHelper(painter, spanRect, clipRect); horizontalGradientHelper(painter, spanRect, clipRect, lightColored);
} }
} }

View File

@@ -52,11 +52,11 @@ public:
static QPalette sidebarFontPalette(const QPalette &original); static QPalette sidebarFontPalette(const QPalette &original);
// This is our color table, all colors derive from baseColor // This is our color table, all colors derive from baseColor
static QColor baseColor(); static QColor baseColor(bool lightColored = false);
static QColor panelTextColor(); static QColor panelTextColor(bool lightColored = false);
static QColor highlightColor(); static QColor highlightColor(bool lightColored = false);
static QColor shadowColor(); static QColor shadowColor(bool lightColored = false);
static QColor borderColor(); static QColor borderColor(bool lightColored = false);
static QColor buttonTextColor() { return QColor(0x4c4c4c); } static QColor buttonTextColor() { return QColor(0x4c4c4c); }
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50); static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50);
@@ -64,8 +64,8 @@ public:
static void setBaseColor(const QColor &color); static void setBaseColor(const QColor &color);
// Gradients used for panels // Gradients used for panels
static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false);
static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false);
static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
// Pixmap cache should only be enabled for X11 due to slow gradients // Pixmap cache should only be enabled for X11 due to slow gradients

View File

@@ -96,6 +96,25 @@ bool panelWidget(const QWidget *widget)
return false; return false;
} }
// Consider making this a QStyle state
bool lightColored(const QWidget *widget)
{
if (!widget)
return false;
// Don't style dialogs or explicitly ignored widgets
if (qobject_cast<const QDialog *>(widget->window()))
return false;
const QWidget *p = widget;
while (p) {
if (p->property("lightColored").toBool())
return true;
p = p->parentWidget();
}
return false;
}
class ManhattanStylePrivate class ManhattanStylePrivate
{ {
public: public:
@@ -293,9 +312,9 @@ void ManhattanStyle::unpolish(QApplication *app)
d->style->unpolish(app); d->style->unpolish(app);
} }
QPalette panelPalette(const QPalette &oldPalette) QPalette panelPalette(const QPalette &oldPalette, bool lightColored = false)
{ {
QColor color = Utils::StyleHelper::panelTextColor(); QColor color = Utils::StyleHelper::panelTextColor(lightColored);
QPalette pal = oldPalette; QPalette pal = oldPalette;
pal.setBrush(QPalette::All, QPalette::WindowText, color); pal.setBrush(QPalette::All, QPalette::WindowText, color);
pal.setBrush(QPalette::All, QPalette::ButtonText, color); pal.setBrush(QPalette::All, QPalette::ButtonText, color);
@@ -848,29 +867,41 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
case CE_ToolBar: case CE_ToolBar:
{ {
QString key; QString key;
key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), Utils::StyleHelper::baseColor().rgb());; QColor keyColor = Utils::StyleHelper::baseColor(lightColored(widget));
key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), keyColor.rgb());;
QPixmap pixmap; QPixmap pixmap;
QPainter *p = painter; QPainter *p = painter;
QRect rect = option->rect; QRect rect = option->rect;
bool horizontal = option->state & State_Horizontal;
if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(option->rect.size()); pixmap = QPixmap(option->rect.size());
p = new QPainter(&pixmap); p = new QPainter(&pixmap);
rect = QRect(0, 0, option->rect.width(), option->rect.height()); rect = QRect(0, 0, option->rect.width(), option->rect.height());
} }
bool horizontal = option->state & State_Horizontal; if (!Utils::StyleHelper::usePixmapCache() || !QPixmapCache::find(key, pixmap)) {
// Map offset for global window gradient // Map offset for global window gradient
QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
widget->mapToGlobal(option->rect.topLeft()); widget->mapToGlobal(option->rect.topLeft());
QRect gradientSpan; QRect gradientSpan;
if (widget) { if (widget) {
gradientSpan = QRect(offset, widget->window()->size()); gradientSpan = QRect(offset, widget->window()->size());
}
bool drawLightColored = lightColored(widget);
if (horizontal)
Utils::StyleHelper::horizontalGradient(p, gradientSpan, rect, drawLightColored);
else
Utils::StyleHelper::verticalGradient(p, gradientSpan, rect, drawLightColored);
}
if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
delete p;
QPixmapCache::insert(key, pixmap);
}
if (Utils::StyleHelper::usePixmapCache()) {
painter->drawPixmap(rect.topLeft(), pixmap);
} }
if (horizontal)
Utils::StyleHelper::horizontalGradient(p, gradientSpan, rect);
else
Utils::StyleHelper::verticalGradient(p, gradientSpan, rect);
painter->setPen(Utils::StyleHelper::borderColor()); painter->setPen(Utils::StyleHelper::borderColor());
@@ -880,28 +911,20 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
// (needed for the find toolbar for instance) // (needed for the find toolbar for instance)
QColor lighter(255, 255, 255, 40); QColor lighter(255, 255, 255, 40);
if (widget && widget->property("topBorder").toBool()) { if (widget && widget->property("topBorder").toBool()) {
p->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.topLeft(), rect.topRight());
p->setPen(lighter); painter->setPen(lighter);
p->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1)); painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
} else { } else {
p->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight());
p->setPen(lighter); painter->setPen(lighter);
p->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.topLeft(), rect.topRight());
} }
} else { } else {
p->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topLeft(), rect.bottomLeft());
p->drawLine(rect.topRight(), rect.bottomRight()); painter->drawLine(rect.topRight(), rect.bottomRight());
}
if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
painter->drawPixmap(rect.topLeft(), pixmap);
p->end();
delete p;
QPixmapCache::insert(key, pixmap);
} }
} }
break; break;
default: default:
d->style->drawControl(element, option, painter, widget); d->style->drawControl(element, option, painter, widget);
break; break;
@@ -964,9 +987,11 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
} }
QStyleOptionToolButton label = *toolbutton; QStyleOptionToolButton label = *toolbutton;
label.palette = panelPalette(option->palette);
label.palette = panelPalette(option->palette, lightColored(widget));
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
label.rect = button.adjusted(fw, fw, -fw, -fw); label.rect = button.adjusted(fw, fw, -fw, -fw);
drawControl(CE_ToolButtonLabel, &label, painter, widget); drawControl(CE_ToolButtonLabel, &label, painter, widget);
if (toolbutton->subControls & SC_ToolButtonMenu) { if (toolbutton->subControls & SC_ToolButtonMenu) {