forked from qt-creator/qt-creator
Added light colored version of manhattan style's bars
Reviewed-by: jbache
This commit is contained in:
@@ -44,6 +44,7 @@ StyledBar::StyledBar(QWidget *parent)
|
||||
{
|
||||
setProperty("panelwidget", true);
|
||||
setProperty("panelwidget_singlerow", true);
|
||||
setProperty("lightColored", false);
|
||||
}
|
||||
|
||||
void StyledBar::setSingleRow(bool singleRow)
|
||||
@@ -56,6 +57,16 @@ bool StyledBar::isSingleRow() const
|
||||
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)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
@@ -42,6 +42,10 @@ public:
|
||||
StyledBar(QWidget *parent = 0);
|
||||
void setSingleRow(bool singleRow);
|
||||
bool isSingleRow() const;
|
||||
|
||||
void setLightColored(bool lightColored);
|
||||
bool isLightColored() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
};
|
||||
|
||||
@@ -83,40 +83,51 @@ QPalette StyleHelper::sidebarFontPalette(const QPalette &original)
|
||||
return palette;
|
||||
}
|
||||
|
||||
QColor StyleHelper::panelTextColor()
|
||||
QColor StyleHelper::panelTextColor(bool lightColored)
|
||||
{
|
||||
//qApp->palette().highlightedText().color();
|
||||
if (!lightColored)
|
||||
return Qt::white;
|
||||
else
|
||||
return Qt::black;
|
||||
}
|
||||
|
||||
QColor StyleHelper::m_baseColor(0x666666);
|
||||
|
||||
QColor StyleHelper::baseColor()
|
||||
QColor StyleHelper::baseColor(bool lightColored)
|
||||
{
|
||||
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);
|
||||
if (!lightColored)
|
||||
result.setHsv(result.hue(),
|
||||
clamp(result.saturation()),
|
||||
clamp(result.value() * 1.16));
|
||||
else
|
||||
result.setHsv(result.hue(),
|
||||
clamp(result.saturation()),
|
||||
clamp(result.value() * 1.06));
|
||||
return result;
|
||||
}
|
||||
|
||||
QColor StyleHelper::shadowColor()
|
||||
QColor StyleHelper::shadowColor(bool lightColored)
|
||||
{
|
||||
QColor result = baseColor();
|
||||
QColor result = baseColor(lightColored);
|
||||
result.setHsv(result.hue(),
|
||||
clamp(result.saturation() * 1.1),
|
||||
clamp(result.value() * 0.70));
|
||||
return result;
|
||||
}
|
||||
|
||||
QColor StyleHelper::borderColor()
|
||||
QColor StyleHelper::borderColor(bool lightColored)
|
||||
{
|
||||
QColor result = baseColor();
|
||||
QColor result = baseColor(lightColored);
|
||||
result.setHsv(result.hue(),
|
||||
result.saturation(),
|
||||
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());
|
||||
grad.setColorAt(0, StyleHelper::highlightColor());
|
||||
grad.setColorAt(0, highlight);
|
||||
grad.setColorAt(0.301, base);
|
||||
grad.setColorAt(1, StyleHelper::shadowColor());
|
||||
grad.setColorAt(1, shadow);
|
||||
p->fillRect(rect, grad);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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()) {
|
||||
QString key;
|
||||
QColor keyColor = baseColor(lightColored);
|
||||
key.sprintf("mh_vertical %d %d %d %d %d",
|
||||
spanRect.width(), spanRect.height(), clipRect.width(),
|
||||
clipRect.height(), StyleHelper::baseColor().rgb());;
|
||||
clipRect.height(), keyColor.rgb());;
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!QPixmapCache::find(key, pixmap)) {
|
||||
pixmap = QPixmap(clipRect.size());
|
||||
QPainter p(&pixmap);
|
||||
QRect rect(0, 0, clipRect.width(), clipRect.height());
|
||||
verticalGradientHelper(&p, spanRect, rect);
|
||||
verticalGradientHelper(&p, spanRect, rect, lightColored);
|
||||
p.end();
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
}
|
||||
|
||||
painter->drawPixmap(clipRect.topLeft(), pixmap);
|
||||
} else {
|
||||
verticalGradientHelper(painter, spanRect, clipRect);
|
||||
verticalGradientHelper(painter, spanRect, clipRect, lightColored);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
grad.setColorAt(0, StyleHelper::highlightColor().lighter(120));
|
||||
grad.setColorAt(0, highlight.lighter(120));
|
||||
if (rect.height() == StyleHelper::navigationWidgetHeight()) {
|
||||
grad.setColorAt(0.4, StyleHelper::highlightColor());
|
||||
grad.setColorAt(0.4, highlight);
|
||||
grad.setColorAt(0.401, base);
|
||||
}
|
||||
grad.setColorAt(1, StyleHelper::shadowColor());
|
||||
grad.setColorAt(1, shadow);
|
||||
p->fillRect(rect, grad);
|
||||
|
||||
QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
|
||||
shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
|
||||
QColor highlight = StyleHelper::highlightColor().lighter(130);
|
||||
highlight.setAlpha(100);
|
||||
shadowGradient.setColorAt(0.7, highlight);
|
||||
QColor lighterHighlight;
|
||||
if (!lightColored)
|
||||
lighterHighlight = highlight.lighter(130);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
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()) {
|
||||
QString key;
|
||||
QColor keyColor = baseColor(lightColored);
|
||||
key.sprintf("mh_horizontal %d %d %d %d %d",
|
||||
spanRect.width(), spanRect.height(), clipRect.width(),
|
||||
clipRect.height(), StyleHelper::baseColor().rgb());
|
||||
clipRect.height(), keyColor.rgb());
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!QPixmapCache::find(key, pixmap)) {
|
||||
pixmap = QPixmap(clipRect.size());
|
||||
QPainter p(&pixmap);
|
||||
QRect rect = QRect(0, 0, clipRect.width(), clipRect.height());
|
||||
horizontalGradientHelper(&p, spanRect, rect);
|
||||
horizontalGradientHelper(&p, spanRect, rect, lightColored);
|
||||
p.end();
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
}
|
||||
@@ -214,7 +234,7 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c
|
||||
painter->drawPixmap(clipRect.topLeft(), pixmap);
|
||||
|
||||
} else {
|
||||
horizontalGradientHelper(painter, spanRect, clipRect);
|
||||
horizontalGradientHelper(painter, spanRect, clipRect, lightColored);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ public:
|
||||
static QPalette sidebarFontPalette(const QPalette &original);
|
||||
|
||||
// This is our color table, all colors derive from baseColor
|
||||
static QColor baseColor();
|
||||
static QColor panelTextColor();
|
||||
static QColor highlightColor();
|
||||
static QColor shadowColor();
|
||||
static QColor borderColor();
|
||||
static QColor baseColor(bool lightColored = false);
|
||||
static QColor panelTextColor(bool lightColored = false);
|
||||
static QColor highlightColor(bool lightColored = false);
|
||||
static QColor shadowColor(bool lightColored = false);
|
||||
static QColor borderColor(bool lightColored = false);
|
||||
static QColor buttonTextColor() { return QColor(0x4c4c4c); }
|
||||
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50);
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
static void setBaseColor(const QColor &color);
|
||||
|
||||
// Gradients used for panels
|
||||
static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
|
||||
static void verticalGradient(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, bool lightColored = false);
|
||||
static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
|
||||
|
||||
// Pixmap cache should only be enabled for X11 due to slow gradients
|
||||
|
||||
@@ -96,6 +96,25 @@ bool panelWidget(const QWidget *widget)
|
||||
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
|
||||
{
|
||||
public:
|
||||
@@ -293,9 +312,9 @@ void ManhattanStyle::unpolish(QApplication *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;
|
||||
pal.setBrush(QPalette::All, QPalette::WindowText, color);
|
||||
pal.setBrush(QPalette::All, QPalette::ButtonText, color);
|
||||
@@ -848,18 +867,20 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
||||
case CE_ToolBar:
|
||||
{
|
||||
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;
|
||||
QPainter *p = painter;
|
||||
QRect rect = option->rect;
|
||||
bool horizontal = option->state & State_Horizontal;
|
||||
if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
|
||||
pixmap = QPixmap(option->rect.size());
|
||||
p = new QPainter(&pixmap);
|
||||
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
|
||||
QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
|
||||
widget->mapToGlobal(option->rect.topLeft());
|
||||
@@ -867,10 +888,20 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
||||
if (widget) {
|
||||
gradientSpan = QRect(offset, widget->window()->size());
|
||||
}
|
||||
bool drawLightColored = lightColored(widget);
|
||||
if (horizontal)
|
||||
Utils::StyleHelper::horizontalGradient(p, gradientSpan, rect);
|
||||
Utils::StyleHelper::horizontalGradient(p, gradientSpan, rect, drawLightColored);
|
||||
else
|
||||
Utils::StyleHelper::verticalGradient(p, gradientSpan, rect);
|
||||
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);
|
||||
}
|
||||
|
||||
painter->setPen(Utils::StyleHelper::borderColor());
|
||||
|
||||
@@ -880,28 +911,20 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
||||
// (needed for the find toolbar for instance)
|
||||
QColor lighter(255, 255, 255, 40);
|
||||
if (widget && widget->property("topBorder").toBool()) {
|
||||
p->drawLine(rect.topLeft(), rect.topRight());
|
||||
p->setPen(lighter);
|
||||
p->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
|
||||
painter->drawLine(rect.topLeft(), rect.topRight());
|
||||
painter->setPen(lighter);
|
||||
painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
|
||||
} else {
|
||||
p->drawLine(rect.bottomLeft(), rect.bottomRight());
|
||||
p->setPen(lighter);
|
||||
p->drawLine(rect.topLeft(), rect.topRight());
|
||||
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
|
||||
painter->setPen(lighter);
|
||||
painter->drawLine(rect.topLeft(), rect.topRight());
|
||||
}
|
||||
} else {
|
||||
p->drawLine(rect.topLeft(), rect.bottomLeft());
|
||||
p->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);
|
||||
painter->drawLine(rect.topLeft(), rect.bottomLeft());
|
||||
painter->drawLine(rect.topRight(), rect.bottomRight());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
d->style->drawControl(element, option, painter, widget);
|
||||
break;
|
||||
@@ -964,9 +987,11 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
|
||||
}
|
||||
|
||||
QStyleOptionToolButton label = *toolbutton;
|
||||
label.palette = panelPalette(option->palette);
|
||||
|
||||
label.palette = panelPalette(option->palette, lightColored(widget));
|
||||
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
|
||||
label.rect = button.adjusted(fw, fw, -fw, -fw);
|
||||
|
||||
drawControl(CE_ToolButtonLabel, &label, painter, widget);
|
||||
|
||||
if (toolbutton->subControls & SC_ToolButtonMenu) {
|
||||
|
||||
Reference in New Issue
Block a user