Commit 74928d01 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

Make disabled icons sharper in sidebar

This overrides the styles default behavior for disabled
icons and simply generates their grayscale equivalent so
they look a bit crisper.
parent f5e0dc40
......@@ -161,7 +161,7 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe
QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, highlight.lighter(112));
grad.setColorAt(0, highlight.lighter(117));
grad.setColorAt(1, shadow.darker(109));
p->fillRect(rect, grad);
......@@ -364,16 +364,33 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q
}
// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QPixmap &px, const QPoint &pos,
QPainter *p, int radius, const QColor &color, const QPoint &offset)
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset)
{
QPixmap cache;
QString pixmapName = QString("sdw %0").arg(px.cacheKey());
QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
if (!QPixmapCache::find(pixmapName, cache)) {
QPixmap px = icon.pixmap(rect.size());
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent);
QPainter cachePainter(&cache);
if (iconMode == QIcon::Disabled) {
QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
for (int y=0; y<im.height(); ++y) {
QRgb *scanLine = (QRgb*)im.scanLine(y);
for (int x=0; x<im.width(); ++x) {
QRgb pixel = *scanLine;
char intensity = qGray(pixel);
*scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
++scanLine;
}
}
px = QPixmap::fromImage(im);
}
// Draw shadow
QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
tmp.fill(Qt::transparent);
......@@ -396,15 +413,23 @@ void StyleHelper::drawIconWithShadow(const QPixmap &px, const QPoint &pos,
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
// draw the blurred drop shadow...
cachePainter.drawImage(QPoint(0, 0), tmp);
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
// Draw the actual pixmap...
cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
QPixmapCache::insert(pixmapName, cache);
}
p->drawPixmap(pos - QPoint(radius, radius), cache);
QRect targetRect = cache.rect();
targetRect.moveCenter(rect.center());
p->drawPixmap(targetRect.topLeft() - offset, cache);
}
// Draws a CSS-like border image where the defined borders are not stretched
......@@ -448,5 +473,4 @@ void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect re
}
}
} // namespace Utils
......@@ -80,9 +80,9 @@ public:
static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
static bool usePixmapCache() { return true; }
static void drawIconWithShadow(const QPixmap &px, const QPoint &pos, QPainter *p,
int radius = 3, const QColor &color = QColor(0, 0, 0, 70),
const QPoint &offset = QPoint(0, -1));
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
int radius = 3, const QColor &color = QColor(0, 0, 0, 130),
const QPoint &offset = QPoint(1, -2));
static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0, int bottom = 0);
......
......@@ -136,12 +136,12 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
QPixmap borderPixmap;
QMargins margins;
QPixmap pix = icon().pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE, isEnabled() ? QIcon::Normal : QIcon::Disabled);
QSizeF halfPixSize = pix.size()/2.0;
QRect iconRect(0, 0, Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
// draw popup texts
if (isTitledAction) {
QFont normalFont(painter.font());
QRect centerRect = rect();
normalFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
QFont boldFont(normalFont);
boldFont.setBold(true);
......@@ -150,22 +150,20 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
int lineHeight = boldFm.height();
int textFlags = Qt::AlignVCenter|Qt::AlignHCenter;
QRect iconRect = rect();
const QString projectName = defaultAction()->property("heading").toString();
if (!projectName.isNull())
iconRect.adjust(0, lineHeight + 4, 0, 0);
centerRect.adjust(0, lineHeight + 4, 0, 0);
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
if (!buildConfiguration.isNull())
iconRect.adjust(0, 0, 0, -lineHeight - 4);
centerRect.adjust(0, 0, 0, -lineHeight - 4);
QPoint center = iconRect.center();
Utils::StyleHelper::drawIconWithShadow(pix, center-QPoint(halfPixSize.width()-1, halfPixSize.height()-1), &painter);
iconRect.moveCenter(centerRect.center());
Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled);
painter.setFont(normalFont);
QPoint textOffset = center - QPoint(pix.rect().width()/2, pix.rect().height()/2);
textOffset = textOffset - QPoint(0, lineHeight+5);
QPoint textOffset = centerRect.center() - QPoint(iconRect.width()/2, iconRect.height()/2);
textOffset = textOffset - QPoint(0, lineHeight + 4);
QRectF r(0, textOffset.y(), rect().width(), lineHeight);
QColor penColor;
if (isEnabled())
......@@ -182,7 +180,7 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
painter.setPen(penColor);
}
painter.drawText(r, textFlags, ellidedProjectName);
textOffset = center + QPoint(pix.rect().width()/2, pix.rect().height()/2);
textOffset = iconRect.center() + QPoint(iconRect.width()/2, iconRect.height()/2);
r = QRectF(0, textOffset.y()+5, rect().width(), lineHeight);
painter.setFont(boldFont);
QString ellidedBuildConfiguration = boldFm.elidedText(buildConfiguration, Qt::ElideMiddle, r.width());
......@@ -196,12 +194,12 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
painter.drawText(r, textFlags, ellidedBuildConfiguration);
QStyleOption opt;
opt.initFrom(this);
opt.rect = iconRect.adjusted(iconRect.width() - 16, 0, -8, 0);
opt.rect = rect().adjusted(rect().width() - 16, 0, -8, 0);
Utils::StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt);
}
} else {
QPoint center = rect().center();
Utils::StyleHelper::drawIconWithShadow(pix, center-QPoint(halfPixSize.width()-1, halfPixSize.height()-1), &painter);
iconRect.moveCenter(rect().center());
Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled);
}
}
......
......@@ -245,7 +245,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
//background
painter->save();
QLinearGradient grad(rect.topLeft(), rect.topRight());
grad.setColorAt(0, QColor(255, 255, 255, 160));
grad.setColorAt(0, QColor(255, 255, 255, 140));
grad.setColorAt(1, QColor(255, 255, 255, 210));
painter->fillRect(rect.adjusted(0, 0, 0, -1), grad);
painter->restore();
......@@ -304,15 +304,8 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
tabIconRect.adjust(0, 4, 0, -textHeight);
QPixmap icon = tabIcon(tabIndex).pixmap(tabIconRect.size(), enabled ? QIcon::Normal : QIcon::Disabled);
Utils::StyleHelper::drawIconWithShadow(icon,
tabIconRect.center() - QPoint(icon.size().width()/2-1, icon.size().height()/2),
painter);
/* if (iconSize > 4)
style()->drawItemPixmap(painter, tabIconRect, Qt::AlignCenter | Qt::AlignVCenter,
tabIcon(tabIndex).pixmap(tabIconRect.size(), enabled ? QIcon::Normal : QIcon::Disabled));
*/
Utils::StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled);
painter->translate(0, -1);
painter->drawText(tabTextRect, textFlags, tabText);
painter->restore();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment