hydrogen 1.2.6
Skin.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include "Skin.h"
25
26#include <QApplication>
27
30
31 int nFactorGradient = 120;
32 int nHover = 10;
33
34 QColor buttonBackgroundLight = pPref->getColorTheme()->m_widgetColor.lighter( nFactorGradient );
35 QColor buttonBackgroundDark = pPref->getColorTheme()->m_widgetColor.darker( nFactorGradient );
36 QColor buttonBackgroundLightHover = pPref->getColorTheme()->m_widgetColor.lighter( nFactorGradient + nHover );
37 QColor buttonBackgroundDarkHover = pPref->getColorTheme()->m_widgetColor.darker( nFactorGradient + nHover );
38
39 QColor buttonBackgroundCheckedLight = pPref->getColorTheme()->m_accentColor.lighter( nFactorGradient );
40 QColor buttonBackgroundCheckedDark = pPref->getColorTheme()->m_accentColor.darker( nFactorGradient );
41 QColor buttonBackgroundCheckedLightHover = pPref->getColorTheme()->m_accentColor.lighter( nFactorGradient + nHover );
42 QColor buttonBackgroundCheckedDarkHover = pPref->getColorTheme()->m_accentColor.darker( nFactorGradient + nHover );
43 QColor buttonTextChecked = pPref->getColorTheme()->m_accentTextColor;
44 QColor spinBoxSelection = pPref->getColorTheme()->m_spinBoxColor.darker( 120 );
45
46 return QString( "\
47QToolTip { \
48 padding: 1px; \
49 border: 1px solid %1; \
50 background-color: %2; \
51 color: %1; \
52} \
53QPushButton { \
54 color: %12; \
55 border-radius: 2px; \
56 padding: 5px; \
57 background-color: qlineargradient(x1: 0.1, y1: 0.1, x2: 1, y2: 1, \
58 stop: 0 %4, stop: 1 %5); \
59} \
60QPushButton:hover { \
61 background-color: qlineargradient(x1: 0.1, y1: 0.1, x2: 1, y2: 1, \
62 stop: 0 %6, stop: 1 %7); \
63} \
64QPushButton:checked { \
65 color: %3; \
66 background-color: qlineargradient(x1: 0.1, y1: 0.1, x2: 1, y2: 1, \
67 stop: 0 %8, stop: 1 %9); \
68} \
69QPushButton:checked:hover { \
70 color: %3; \
71 background-color: qlineargradient(x1: 0.1, y1: 0.1, x2: 1, y2: 1, \
72 stop: 0 %10, stop: 1 %11); \
73} \
74QComboBox { \
75 color: %12; \
76 background-color: %13; \
77} \
78QComboBox QAbstractItemView { \
79 background-color: #babfcf; \
80} \
81QLineEdit, QTextEdit { \
82 color: %12; \
83 background-color: %13; \
84} \
85QDoubleSpinBox, QSpinBox { \
86 color: %14; \
87 background-color: %15; \
88 selection-color: %14; \
89 selection-background-color: %16; \
90}"
91 )
92 .arg( pPref->getColorTheme()->m_toolTipTextColor.name() )
93 .arg( pPref->getColorTheme()->m_toolTipBaseColor.name() )
94 .arg( buttonTextChecked.name() )
95 .arg( buttonBackgroundLight.name() ).arg( buttonBackgroundDark.name() )
96 .arg( buttonBackgroundLightHover.name() ).arg( buttonBackgroundDarkHover.name() )
97 .arg( buttonBackgroundCheckedLight.name() ).arg( buttonBackgroundCheckedDark.name() )
98 .arg( buttonBackgroundCheckedLightHover.name() ).arg( buttonBackgroundCheckedDarkHover.name() )
99 .arg( pPref->getColorTheme()->m_widgetTextColor.name() )
100 .arg( pPref->getColorTheme()->m_widgetColor.name() )
101 .arg( pPref->getColorTheme()->m_spinBoxTextColor.name() )
102 .arg( pPref->getColorTheme()->m_spinBoxColor.name() )
103 .arg( spinBoxSelection.name() );
104}
105
106void Skin::setPalette( QApplication *pQApp ) {
108
109 // create the default palette
110 QPalette defaultPalette;
111
112 defaultPalette.setColor( QPalette::Window, pPref->getColorTheme()->m_windowColor );
113 defaultPalette.setColor( QPalette::WindowText, pPref->getColorTheme()->m_windowTextColor );
114 defaultPalette.setColor( QPalette::Base, pPref->getColorTheme()->m_baseColor );
115 defaultPalette.setColor( QPalette::AlternateBase, pPref->getColorTheme()->m_alternateBaseColor );
116 defaultPalette.setColor( QPalette::Text, pPref->getColorTheme()->m_textColor );
117 defaultPalette.setColor( QPalette::Button, pPref->getColorTheme()->m_buttonColor );
118 defaultPalette.setColor( QPalette::ButtonText, pPref->getColorTheme()->m_buttonTextColor );
119 defaultPalette.setColor( QPalette::Light, pPref->getColorTheme()->m_lightColor );
120 defaultPalette.setColor( QPalette::Midlight, pPref->getColorTheme()->m_midLightColor );
121 defaultPalette.setColor( QPalette::Dark, pPref->getColorTheme()->m_darkColor );
122 defaultPalette.setColor( QPalette::Mid, pPref->getColorTheme()->m_midColor );
123 defaultPalette.setColor( QPalette::Shadow, pPref->getColorTheme()->m_shadowTextColor );
124 defaultPalette.setColor( QPalette::Highlight, pPref->getColorTheme()->m_highlightColor );
125 defaultPalette.setColor( QPalette::HighlightedText, pPref->getColorTheme()->m_highlightedTextColor );
126 defaultPalette.setColor( QPalette::ToolTipBase, pPref->getColorTheme()->m_toolTipBaseColor );
127 defaultPalette.setColor( QPalette::ToolTipText, pPref->getColorTheme()->m_toolTipTextColor );
128
129 // Desaturate disabled widgets by blending with the alternate colour
130 for ( QPalette::ColorRole role : { QPalette::Window, QPalette::Base, QPalette::AlternateBase, QPalette::Dark,
131 QPalette::Light, QPalette::Midlight, QPalette::Mid, QPalette::Shadow,
132 QPalette::Text } ) {
133 QColor normalColor = defaultPalette.color( QPalette::Normal, role );
134 QColor disabledColor = QColor( ( normalColor.red() + 138 ) / 2,
135 ( normalColor.green() + 144 ) / 2,
136 ( normalColor.blue() + 162 ) / 2);
137 defaultPalette.setColor( QPalette::Disabled, role, disabledColor );
138 }
139
140 pQApp->setPalette( defaultPalette );
141 pQApp->setStyleSheet( getGlobalStyleSheet() );
142}
143
144void Skin::drawListBackground( QPainter* p, QRect rect, QColor background,
145 bool bHovered ) {
146
147 if ( bHovered ) {
148 background = background.lighter( 110 );
149 }
150
151 QColor backgroundLight = background.lighter( 150 );
152 QColor backgroundDark = background.darker( 220 );
153
154 p->fillRect( QRect( rect.x() + 1, rect.y() + 1,
155 rect.width() - 2, rect.height() - 2 ),
156 background );
157 p->fillRect( QRect( rect.x(), rect.y(), rect.width(), 1 ),
158 backgroundLight );
159 p->fillRect( QRect( rect.x(), rect.y(), 1, rect.height() ),
160 backgroundLight );
161 p->fillRect( QRect( rect.x(), rect.y() + rect.height() - 1, rect.width(), 1 ),
162 backgroundDark );
163 p->fillRect( QRect( rect.x() + rect.width() - 1, rect.y(), 1, rect.height() ),
164 backgroundDark );
165}
166
167QColor Skin::makeWidgetColorInactive( QColor color ){
168 int nHue, nSaturation, nValue;
169 color.getHsv( &nHue, &nSaturation, &nValue );
170 nValue = std::max( 0, nValue - 40 );
171 color.setHsv( nHue, nSaturation, nValue );
172
173 return color;
174}
175
176QColor Skin::makeTextColorInactive( QColor color ) {
177 int nHue, nSaturation, nValue;
178 color.getHsv( &nHue, &nSaturation, &nValue );
179 if ( nValue >= 130 ) {
180 // TextInactive color is more white than black. Make it darker.
181 nValue -= 55;
182 } else {
183 nValue += 55;
184 }
185 color.setHsv( nHue, nSaturation, nValue );
186
187 return color;
188}
189
190void Skin::setPlayheadPen( QPainter* p, bool bHovered ) {
191
192 QColor playheadColor( H2Core::Preferences::get_instance()->getColorTheme()->m_playheadColor );
193 if ( bHovered ) {
194 playheadColor = Skin::makeTextColorInactive( playheadColor );
195 }
196 QPen pen ( playheadColor );
197 pen.setWidth( 2 );
198
199 p->setPen( pen );
200 p->setRenderHint( QPainter::Antialiasing );
201}
202
203void Skin::drawPlayhead( QPainter* p, int x, int y, bool bHovered ) {
204
205 const QPointF points[3] = {
206 QPointF( x, y ),
207 QPointF( x + Skin::nPlayheadWidth - 1, y ),
208 QPointF( x + Skin::getPlayheadShaftOffset(),
210 };
211
212 QColor playheadColor( H2Core::Preferences::get_instance()->getColorTheme()->m_playheadColor );
213 if ( bHovered ) {
214 playheadColor = Skin::makeTextColorInactive( playheadColor );
215 }
216
217 Skin::setPlayheadPen( p, bHovered );
218 p->setBrush( playheadColor );
219 p->drawPolygon( points, 3 );
220 p->setBrush( Qt::NoBrush );
221}
222
223void Skin::drawStackedIndicator( QPainter* p, int x, int y, Skin::Stacked stacked ) {
224
226
227 const QPointF points[3] = {
228 QPointF( x, y ),
229 QPointF( x + 8, y + 6 ),
230 QPointF( x, y + 12 )
231 };
232
233 QPen pen( Qt::black );
234 pen.setWidth( 1 );
235
236 QColor fillColor;
237 switch ( stacked ) {
239 fillColor = QColor( 0, 0, 0 );
240 fillColor.setAlpha( 0 );
241 break;
243 fillColor = pPref->getColorTheme()->m_songEditor_stackedModeOffNextColor;
244 break;
246 fillColor = pPref->getColorTheme()->m_songEditor_stackedModeOnColor;
247 break;
249 fillColor = pPref->getColorTheme()->m_songEditor_stackedModeOnNextColor;
250 break;
251 }
252
253 p->setPen( pen );
254 p->setBrush( fillColor );
255 p->setRenderHint( QPainter::Antialiasing );
256 p->drawPolygon( points, 3 );
257 p->setBrush( Qt::NoBrush );
258}
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
static void setPalette(QApplication *pQApp)
Function used to update the global palette of the QApplication.
Definition Skin.cpp:106
static constexpr int nPlayheadHeight
Definition Skin.h:78
static QString getGlobalStyleSheet()
Top-level stylesheet for Hydrogen.
Definition Skin.cpp:28
static QColor makeTextColorInactive(QColor color)
If a widget is marked inactive the value of its text color are reduced by this factor.
Definition Skin.cpp:176
Stacked
Definition Skin.h:84
static void drawPlayhead(QPainter *p, int x, int y, bool bHovered=false)
Definition Skin.cpp:203
static constexpr int nPlayheadWidth
Definition Skin.h:77
static void drawListBackground(QPainter *p, QRect rect, QColor background, bool bHovered)
Draws the background of a row in both the pattern list of the SongEditor and the instrument list in t...
Definition Skin.cpp:144
static void drawStackedIndicator(QPainter *p, int x, int y, Skin::Stacked stacked)
Definition Skin.cpp:223
static void setPlayheadPen(QPainter *p, bool bHovered=false)
Definition Skin.cpp:190
static QColor makeWidgetColorInactive(QColor color)
If a widget is marked inactive the value of its background color are reduced by this factor.
Definition Skin.cpp:167
static int getPlayheadShaftOffset()
Definition Skin.h:79