File indexing completed on 2025-01-19 04:01:43

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 // Self
0022 #include <hud/hudtheme.h>
0023 
0024 // Qt
0025 #include <QMap>
0026 
0027 // KF
0028 
0029 // Local
0030 
0031 namespace Gwenview
0032 {
0033 namespace HudTheme
0034 {
0035 struct RenderInfoSet {
0036     QMap<HudTheme::State, HudTheme::RenderInfo> infos;
0037 };
0038 
0039 static QLinearGradient createGradient()
0040 {
0041     QLinearGradient gradient(0, 0, 0, 1.);
0042     gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
0043     return gradient;
0044 }
0045 
0046 RenderInfo renderInfo(WidgetType widget, State state)
0047 {
0048     static QMap<WidgetType, RenderInfoSet> renderInfoMap;
0049     if (renderInfoMap.isEmpty()) {
0050         QLinearGradient gradient;
0051 
0052         // Button, normal
0053         RenderInfo button;
0054         button.borderRadius = 5;
0055         button.borderPen = QPen(QColor::fromHsvF(0, 0, .25, .8));
0056         gradient = createGradient();
0057         gradient.setColorAt(0, QColor::fromHsvF(0, 0, .34, .66));
0058         gradient.setColorAt(0.5, QColor::fromHsvF(0, 0, 0, .66));
0059         button.bgBrush = gradient;
0060         button.padding = 6;
0061         button.textPen = QPen(QColor(0xcc, 0xcc, 0xcc));
0062         renderInfoMap[ButtonWidget].infos[NormalState] = button;
0063 
0064         // Button, over
0065         RenderInfo overButton = button;
0066         overButton.bgBrush = gradient;
0067         overButton.borderPen = QPen(QColor(0xcc, 0xcc, 0xcc));
0068         renderInfoMap[ButtonWidget].infos[MouseOverState] = overButton;
0069 
0070         // Button, down
0071         RenderInfo downButton = button;
0072         gradient = createGradient();
0073         gradient.setColorAt(0, QColor::fromHsvF(0, 0, .12));
0074         gradient.setColorAt(0.6, Qt::black);
0075         downButton.bgBrush = gradient;
0076         downButton.borderPen = QPen(QColor(0x44, 0x44, 0x44));
0077         renderInfoMap[ButtonWidget].infos[DownState] = downButton;
0078 
0079         // Frame
0080         RenderInfo frame;
0081         gradient = createGradient();
0082         gradient.setColorAt(0, QColor::fromHsvF(0, 0, 0.1, .6));
0083         gradient.setColorAt(.6, QColor::fromHsvF(0, 0, 0, .6));
0084         frame.bgBrush = gradient;
0085         frame.borderPen = QPen(QColor::fromHsvF(0, 0, .4, .6));
0086         frame.borderRadius = 8;
0087         frame.textPen = QPen(QColor(0xcc, 0xcc, 0xcc));
0088         renderInfoMap[FrameWidget].infos[NormalState] = frame;
0089 
0090         // CountDown
0091         RenderInfo countDownWidget;
0092         countDownWidget.bgBrush = QColor::fromHsvF(0, 0, .5);
0093         countDownWidget.borderPen = QPen(QColor::fromHsvF(0, 0, .8));
0094         renderInfoMap[CountDown].infos[NormalState] = countDownWidget;
0095 
0096         // SliderWidgetHandle
0097         RenderInfo sliderWidgetHandle = button;
0098         sliderWidgetHandle.borderPen = QPen(QColor(0x66, 0x66, 0x66));
0099         sliderWidgetHandle.borderRadius = 7;
0100         renderInfoMap[SliderWidgetHandle].infos[NormalState] = sliderWidgetHandle;
0101 
0102         // SliderWidgetHandle, over
0103         sliderWidgetHandle = overButton;
0104         sliderWidgetHandle.borderPen = QPen(QColor(0xcc, 0xcc, 0xcc));
0105         sliderWidgetHandle.borderRadius = 7;
0106         renderInfoMap[SliderWidgetHandle].infos[MouseOverState] = sliderWidgetHandle;
0107 
0108         // SliderWidgetHandle, down
0109         sliderWidgetHandle = downButton;
0110         sliderWidgetHandle.borderRadius = 7;
0111         renderInfoMap[SliderWidgetHandle].infos[DownState] = sliderWidgetHandle;
0112 
0113         // SliderWidgetGroove
0114         RenderInfo sliderWidgetGroove = button;
0115         sliderWidgetGroove.borderPen = QPen(QColor(0x66, 0x66, 0x66));
0116         gradient = createGradient();
0117         gradient.setColorAt(0, Qt::black);
0118         gradient.setColorAt(1, QColor(0x44, 0x44, 0x44));
0119         sliderWidgetGroove.bgBrush = gradient;
0120         sliderWidgetGroove.borderRadius = 3;
0121         renderInfoMap[SliderWidgetGroove].infos[NormalState] = sliderWidgetGroove;
0122 
0123         // SliderWidgetGroove, over
0124         RenderInfo overSliderWidgetGroove = sliderWidgetGroove;
0125         overSliderWidgetGroove.borderPen = QPen(QColor(0xcc, 0xcc, 0xcc));
0126         renderInfoMap[SliderWidgetGroove].infos[MouseOverState] = overSliderWidgetGroove;
0127     }
0128     const RenderInfo normalInfo = renderInfoMap[widget].infos.value(NormalState);
0129     if (state == NormalState) {
0130         return normalInfo;
0131     } else {
0132         return renderInfoMap[widget].infos.value(state, normalInfo);
0133     }
0134 }
0135 
0136 } // HudTheme namespace
0137 
0138 } // Gwenview namespace