32#include <QPixmapCache> 
   34#include <QtCore/QRect> 
   36#include <QApplication> 
   38#include <QStyleOption> 
   39#include <QtCore/QObject> 
   42static int clamp(
float x)
 
   44    const int val = x > 255 ? 255 : 
static_cast<int>(x);
 
   45    return val < 0 ? 0 : val;
 
   53#if defined(Q_OS_MACOS) 
   71QColor StyleHelper::m_baseColor;
 
   72QColor StyleHelper::m_requestedBaseColor;
 
   80        return m_baseColor.lighter(230);
 
   88        result.setHsv(result.hue(),
 
   89                      clamp(result.saturation()),
 
   90                      clamp(result.value() * 1.16));
 
   92        result.setHsv(result.hue(),
 
   93                      clamp(result.saturation()),
 
   94                      clamp(result.value() * 1.06));
 
  101    result.setHsv(result.hue(),
 
  102                  clamp(result.saturation() * 1.1),
 
  103                  clamp(result.value() * 0.70));
 
  110    result.setHsv(result.hue(),
 
  121    m_requestedBaseColor = newcolor;
 
  124    color.setHsv(newcolor.hue(),
 
  125                 newcolor.saturation() * 0.7,
 
  126                 64 + newcolor.value() / 3);
 
  128    if (color.isValid() && color != m_baseColor) {
 
  131        auto const l_topLevelWidgets = QApplication::topLevelWidgets();
 
  132        for (QWidget* w : l_topLevelWidgets) {
 
  138static void verticalGradientHelper(QPainter* p, 
const QRect &spanRect, 
const QRect &rect, 
bool lightColored)
 
  142    QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
 
  143    grad.setColorAt(0, highlight.lighter(117));
 
  144    grad.setColorAt(1, shadow.darker(109));
 
  145    p->fillRect(rect, grad);
 
  147    QColor 
light(255, 255, 255, 80);
 
  149    p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
 
  150    QColor dark(0, 0, 0, 90);
 
  152    p->drawLine(rect.topLeft(), rect.bottomLeft());
 
  159        QColor keyColor = 
baseColor(lightColored);
 
  160        key.asprintf(
"mh_vertical %d %d %d %d %d",
 
  161                     spanRect.width(), spanRect.height(), clipRect.width(),
 
  162                     clipRect.height(), keyColor.rgb());
 
  165        if (!QPixmapCache::find(key, &pixmap)) {
 
  166            pixmap = QPixmap(clipRect.size());
 
  168            QRect rect(0, 0, clipRect.width(), clipRect.height());
 
  169            verticalGradientHelper(&p, spanRect, rect, lightColored);
 
  171            QPixmapCache::insert(key, pixmap);
 
  174        painter->drawPixmap(clipRect.topLeft(), pixmap);
 
  177        verticalGradientHelper(painter, spanRect, clipRect, lightColored);
 
  183                                     QPainter* p, QIcon::Mode iconMode, 
int radius, 
const QColor &color, 
const QPoint &offset)
 
  186    QString pixmapName = 
QSL(
"icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
 
  188    if (!QPixmapCache::find(pixmapName, &cache)) {
 
  189        QPixmap px = icon.pixmap(rect.size(), iconMode);
 
  190        px.setDevicePixelRatio(qApp->devicePixelRatio());
 
  191        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
 
  192        cache.setDevicePixelRatio(px.devicePixelRatioF());
 
  193        cache.fill(Qt::transparent);
 
  195        QPainter cachePainter(&cache);
 
  198        QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
 
  199        tmp.setDevicePixelRatio(px.devicePixelRatioF());
 
  200        tmp.fill(Qt::transparent);
 
  202        QPainter tmpPainter(&tmp);
 
  203        tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
 
  204        tmpPainter.drawPixmap(QPoint(radius, radius), px);
 
  208        QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
 
  209        blurred.fill(Qt::transparent);
 
  210        QPainter blurPainter(&blurred);
 
  217        tmpPainter.begin(&tmp);
 
  218        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
 
  219        tmpPainter.fillRect(tmp.rect(), color);
 
  222        tmpPainter.begin(&tmp);
 
  223        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
 
  224        tmpPainter.fillRect(tmp.rect(), color);
 
  228        cachePainter.drawImage(QRect(0, 0, cache.rect().width() / cache.devicePixelRatioF(), cache.rect().height() / cache.devicePixelRatioF()), tmp);
 
  231        cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
 
  232        QPixmapCache::insert(pixmapName, cache);
 
  235    QRect targetRect = cache.rect();
 
  236    targetRect.setWidth(cache.rect().width() / cache.devicePixelRatioF());
 
  237    targetRect.setHeight(cache.rect().height() / cache.devicePixelRatioF());
 
  238    targetRect.moveCenter(rect.center());
 
  239    p->drawPixmap(targetRect.topLeft() - offset, cache);
 
static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored=false)
static qreal sidebarFontSize()
static QColor baseColor(bool lightColored=false)
static QColor highlightColor(bool lightColored=false)
static QColor borderColor(bool lightColored=false)
static QColor shadowColor(bool lightColored=false)
static void setBaseColor(const QColor &color)
static bool usePixmapCache()
static QColor panelTextColor(bool lightColored=false)
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))
QColor light(const QColor &c, int value)
void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed=0)