Commit 40aa17a2 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

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.
parent 1ded9ce7
......@@ -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
void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left, int top, int right, int bottom)
......
......@@ -41,6 +41,10 @@ class QPainter;
class QRect;
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
namespace Utils {
......@@ -79,6 +83,9 @@ public:
// Pixmap cache should only be enabled for X11 due to slow gradients
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,
int left = 0, int top = 0, int right = 0, int bottom = 0);
......
......@@ -158,8 +158,9 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
if (!buildConfiguration.isNull())
iconRect.adjust(0, 0, 0, -lineHeight - 4);
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);
QPoint textOffset = center - QPoint(pix.rect().width()/2, pix.rect().height()/2);
......@@ -199,7 +200,7 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
}
} else {
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);
}
}
......
......@@ -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();
tabIconRect.adjust(0, 4, 0, -textHeight);
int iconSize = qMin(tabIconRect.width(), tabIconRect.height());
if (iconSize > 4)
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));
*/
painter->translate(0, -1);
painter->drawText(tabTextRect, textFlags, tabText);
painter->restore();
......
src/plugins/coreplugin/images/mode_Design.png

939 Bytes | W: | H:

src/plugins/coreplugin/images/mode_Design.png

908 Bytes | W: | H:

src/plugins/coreplugin/images/mode_Design.png
src/plugins/coreplugin/images/mode_Design.png
src/plugins/coreplugin/images/mode_Design.png
src/plugins/coreplugin/images/mode_Design.png
  • 2-up
  • Swipe
  • Onion skin
src/plugins/coreplugin/images/mode_Edit.png

725 Bytes | W: | H:

src/plugins/coreplugin/images/mode_Edit.png

663 Bytes | W: | H:

src/plugins/coreplugin/images/mode_Edit.png
src/plugins/coreplugin/images/mode_Edit.png
src/plugins/coreplugin/images/mode_Edit.png
src/plugins/coreplugin/images/mode_Edit.png
  • 2-up
  • Swipe
  • Onion skin
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