Replace reflection by generated drop shadows in sidebar

The sidebar is a diffuse surface. Hence the reflection
does not really make sense there. Additionally, this
allows us to get more unified spacing and we can apply
the same shadow to system icons.
This commit is contained in:
Jens Bache-Wiig
2010-03-15 17:09:57 +01:00
parent 1ded9ce798
commit 40aa17a2e2
12 changed files with 61 additions and 5 deletions

View File

@@ -363,6 +363,50 @@ 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)
{
QPixmap cache;
QString pixmapName = QString("sdw %0").arg(px.cacheKey());
if (!QPixmapCache::find(pixmapName, cache)) {
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent);
QPainter cachePainter(&cache);
QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
tmp.fill(Qt::transparent);
QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QPoint(radius, radius), px);
tmpPainter.end();
// blur the alpha channel
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
blurred.fill(Qt::transparent);
QPainter blurPainter(&blurred);
qt_blurImage(&blurPainter, tmp, radius, false, true);
blurPainter.end();
tmp = blurred;
// blacken the image...
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);
// Draw the actual pixmap...
cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
QPixmapCache::insert(pixmapName, cache);
}
p->drawPixmap(pos - QPoint(radius, radius), cache);
}
// Draws a CSS-like border image where the defined borders are not stretched // Draws a CSS-like border image where the defined borders are not stretched
void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect, void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left, int top, int right, int bottom) int left, int top, int right, int bottom)

View File

@@ -41,6 +41,10 @@ class QPainter;
class QRect; class QRect;
QT_END_NAMESPACE QT_END_NAMESPACE
// Note, this is exported but in a private header as qtopengl depends on it.
// We should consider adding this as a public helper function.
extern void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
// Helper class holding all custom color values // Helper class holding all custom color values
namespace Utils { namespace Utils {
@@ -79,6 +83,9 @@ public:
// Pixmap cache should only be enabled for X11 due to slow gradients // Pixmap cache should only be enabled for X11 due to slow gradients
static bool usePixmapCache() { return true; } 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 drawCornerImage(const QImage &img, QPainter *painter, QRect rect, static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0, int bottom = 0); int left = 0, int top = 0, int right = 0, int bottom = 0);

View File

@@ -158,8 +158,9 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
if (!buildConfiguration.isNull()) if (!buildConfiguration.isNull())
iconRect.adjust(0, 0, 0, -lineHeight - 4); iconRect.adjust(0, 0, 0, -lineHeight - 4);
QPoint center = iconRect.center(); QPoint center = iconRect.center();
painter.drawPixmap(center-QPointF(halfPixSize.width()-1, halfPixSize.height()-1), pix); Utils::StyleHelper::drawIconWithShadow(pix, center-QPoint(halfPixSize.width()-1, halfPixSize.height()-1), &painter);
painter.setFont(normalFont); painter.setFont(normalFont);
QPoint textOffset = center - QPoint(pix.rect().width()/2, pix.rect().height()/2); QPoint textOffset = center - QPoint(pix.rect().width()/2, pix.rect().height()/2);
@@ -199,7 +200,7 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
} }
} else { } else {
QPoint center = rect().center(); QPoint center = rect().center();
painter.drawPixmap(center-QPointF(halfPixSize.width()-1, halfPixSize.height()-1), pix); Utils::StyleHelper::drawIconWithShadow(pix, center-QPoint(halfPixSize.width()-1, halfPixSize.height()-1), &painter);
} }
} }

View File

@@ -304,11 +304,15 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
tabIconRect.adjust(0, 4, 0, -textHeight); tabIconRect.adjust(0, 4, 0, -textHeight);
int iconSize = qMin(tabIconRect.width(), tabIconRect.height()); QPixmap icon = tabIcon(tabIndex).pixmap(tabIconRect.size(), enabled ? QIcon::Normal : QIcon::Disabled);
if (iconSize > 4) 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, style()->drawItemPixmap(painter, tabIconRect, Qt::AlignCenter | Qt::AlignVCenter,
tabIcon(tabIndex).pixmap(tabIconRect.size(), enabled ? QIcon::Normal : QIcon::Disabled)); tabIcon(tabIndex).pixmap(tabIconRect.size(), enabled ? QIcon::Normal : QIcon::Disabled));
*/
painter->translate(0, -1); painter->translate(0, -1);
painter->drawText(tabTextRect, textFlags, tabText); painter->drawText(tabTextRect, textFlags, tabText);
painter->restore(); painter->restore();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 939 B

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 725 B

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB