Remove juce completely, cleanup
[carla.git] / source / theme / CarlaStylePrivate.hpp
blob10157d0cf534a927d0f033306de96ed34471e28d
1 /*
2 * Carla Style, based on Qt5 fusion style
3 * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies)
4 * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * For a full copy of the license see the doc/LGPL.txt file
18 #ifndef CARLA_STYLE_PRIVATE_HPP_INCLUDED
19 #define CARLA_STYLE_PRIVATE_HPP_INCLUDED
21 #include "CarlaStyle.hpp"
22 #include "CarlaStyleAnimations.hpp"
24 #include <QtCore/QHash>
26 static inline
27 const QColor& qt_palette_bg_color(const QPalette& pal)
29 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
30 return pal.window().color();
31 #else
32 return pal.background().color();
33 #endif
36 static inline
37 const QColor& qt_palette_fg_color(const QPalette& pal)
39 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
40 return pal.windowText().color();
41 #else
42 return pal.foreground().color();
43 #endif
46 class QStyleAnimation;
48 class CarlaStylePrivate : public QObject
50 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
51 # pragma clang diagnostic push
52 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
53 #endif
54 Q_OBJECT
55 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
56 # pragma clang diagnostic pop
57 #endif
59 public:
60 enum {
61 menuItemHMargin = 3, // menu item hor text margin
62 menuArrowHMargin = 6, // menu arrow horizontal margin
63 menuRightBorder = 15, // right border on menus
64 menuCheckMarkWidth = 12 // checkmarks width on menus
67 CarlaStylePrivate(CarlaStyle* const style)
68 : fStyle(style),
69 fAnimationFps(60)
73 ~CarlaStylePrivate() override
75 qDeleteAll(fAnimations);
78 int animationFps() const
80 return fAnimationFps;
83 // Used for grip handles
84 QColor lightShade() const
86 return QColor(255, 255, 255, 36);
89 QColor darkShade() const
91 return QColor(0, 0, 0, 60);
94 QColor topShadow() const
96 return QColor(0, 0, 0, 18);
99 QColor innerContrastLine() const
101 return QColor(255, 255, 255, 30);
104 QColor highlight(const QPalette& pal) const
106 return pal.color(QPalette::Active, QPalette::Highlight);
109 QColor highlightedText(const QPalette& pal) const
111 return pal.color(QPalette::Active, QPalette::HighlightedText);
114 QColor outline(const QPalette& pal) const
116 if (! pal.window().texture().isNull())
117 return QColor(0, 0, 0, 160);
118 const QColor& col = qt_palette_bg_color(pal);
119 return col.blackF() > 0.4 ? col.lighter(160) : col.darker(140);
122 QColor highlightedOutline(const QPalette &pal) const
124 QColor highlightedOutline = highlight(pal).darker(125);
125 if (highlightedOutline.value() > 160)
126 highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
127 return highlightedOutline;
130 QColor tabFrameColor(const QPalette& pal) const
132 if (! pal.button().texture().isNull())
133 return QColor(255, 255, 255, 8);
134 return buttonColor(pal).lighter(104);
137 QColor buttonColor(const QPalette& pal) const
139 QColor buttonColor = pal.button().color();
140 const int val = qGray(buttonColor.rgb());
141 buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
142 buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
143 return buttonColor;
146 QIcon tabBarcloseButtonIcon;
148 QList<const QObject*> animationTargets() const
150 return fAnimations.keys();
153 CarlaStyleAnimation* animation(const QObject* target) const
155 return fAnimations.value(target);
158 void startAnimation(CarlaStyleAnimation* animation) const
160 stopAnimation(animation->target());
161 fStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection);
162 fAnimations.insert(animation->target(), animation);
163 animation->start();
166 void stopAnimation(const QObject* target) const
168 CarlaStyleAnimation* const animation = fAnimations.take(target);
169 if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped)
170 animation->stop();
173 private:
174 CarlaStyle* const fStyle;
175 int fAnimationFps;
176 mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations;
178 private slots:
179 void _removeAnimation()
181 if (QObject* const animation = fStyle->sender())
182 fAnimations.remove(animation->parent());
186 #endif // CARLA_STYLE_PRIVATE_HPP_INCLUDED