Warning, file /plasma/oxygen/kdecoration/oxygendecohelper.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2013 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0003     SPDX-FileCopyrightText: 2008 Long Huynh Huu <long.upcase@googlemail.com>
0004     SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2007 Casper Boemann <cbr@boemann.dk>
0006     SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-only
0009 */
0010 
0011 #include "oxygendecohelper.h"
0012 
0013 #include <KColorUtils>
0014 #include <QPainter>
0015 
0016 #include <cmath>
0017 
0018 namespace Oxygen
0019 {
0020 
0021 //______________________________________________________________________________
0022 DecoHelper::DecoHelper()
0023     : Helper(KSharedConfig::openConfig(QStringLiteral("oxygenrc")))
0024 {
0025 }
0026 
0027 //______________________________________________________________________________
0028 void DecoHelper::invalidateCaches(void)
0029 {
0030     // base class call
0031     Helper::invalidateCaches();
0032 
0033     // local caches
0034     _windecoButtonCache.clear();
0035 }
0036 
0037 //______________________________________________________________________________
0038 QPixmap DecoHelper::windecoButton(const QColor &color, const QColor &glow, bool sunken, int size)
0039 {
0040     Oxygen::Cache<QPixmap>::Value cache(_windecoButtonCache.get(color));
0041 
0042     const quint64 key((colorKey(glow) << 32) | (sunken << 23) | size);
0043 
0044     if (QPixmap *cachedPixmap = cache->object(key)) {
0045         return *cachedPixmap;
0046     }
0047 
0048     QPixmap pixmap(size, size);
0049     pixmap.fill(Qt::transparent);
0050 
0051     QPainter p(&pixmap);
0052     p.setRenderHints(QPainter::Antialiasing);
0053     p.setPen(Qt::NoPen);
0054     p.setWindow(0, 0, 21, 21);
0055 
0056     // button shadow
0057     if (color.isValid()) {
0058         p.save();
0059         p.translate(0, -0.2);
0060         drawShadow(p, calcShadowColor(color), 21);
0061         p.restore();
0062     }
0063 
0064     // button glow
0065     if (glow.isValid()) {
0066         p.save();
0067         p.translate(0, -0.2);
0068         drawOuterGlow(p, glow, 21);
0069         p.restore();
0070     }
0071 
0072     // button slab
0073     p.translate(0, 1);
0074     p.setWindow(0, 0, 18, 18);
0075     if (color.isValid()) {
0076         p.translate(0, (0.5 - 0.668));
0077 
0078         const QColor light(calcLightColor(color));
0079         const QColor dark(calcDarkColor(color));
0080 
0081         {
0082             // plain background
0083             QLinearGradient lg(0, 1.665, 0, (12.33 + 1.665));
0084             if (sunken) {
0085                 lg.setColorAt(1, light);
0086                 lg.setColorAt(0, dark);
0087             } else {
0088                 lg.setColorAt(0, light);
0089                 lg.setColorAt(1, dark);
0090             }
0091 
0092             const QRectF r(0.5 * (18 - 12.33), 1.665, 12.33, 12.33);
0093             p.setBrush(lg);
0094             p.drawEllipse(r);
0095         }
0096 
0097         {
0098             // outline circle
0099             const qreal penWidth(0.7);
0100             QLinearGradient lg(0, 1.665, 0, (2.0 * 12.33 + 1.665));
0101             lg.setColorAt(0, light);
0102             lg.setColorAt(1, dark);
0103             const QRectF r(0.5 * (18 - 12.33 + penWidth), (1.665 + penWidth), (12.33 - penWidth), (12.33 - penWidth));
0104             p.setPen(QPen(lg, penWidth));
0105             p.setBrush(Qt::NoBrush);
0106             p.drawEllipse(r);
0107         }
0108     }
0109 
0110     p.end();
0111     cache->insert(key, new QPixmap(pixmap));
0112 
0113     return pixmap;
0114 }
0115 }