1 /***************************************************************************
2  *   Copyright (C) 2007-2021 by Ilya Kotov                                 *
3  *   forkotov02@ya.ru                                                      *
4  *                                                                         *
5  *   Based on Promoe, an XMMS2 Client                                      *
6  *   Copyright (C) 2005-2006 by XMMS2 Team                                 *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
22  ***************************************************************************/
23 
24 #ifndef SKIN_H
25 #define SKIN_H
26 
27 #include <QObject>
28 #include <QMap>
29 #include <QPixmap>
30 #include <QDir>
31 #include <QRegion>
32 #include <QCursor>
33 
34 class Skin : public QObject
35 {
36     Q_OBJECT
37 public:
38     Skin(QObject *parent = nullptr);
39     ~Skin();
40 
41     static Skin *instance();
42     static QPixmap getPixmap(const QString &name, QDir dir);
43     int ratio() const;
44     const QPixmap &getMain() const;
45     const QPixmap getButton(uint bt) const;
46     const QCursor getCursor(uint cu) const;
47     const QPixmap getTitleBar(uint tb) const;
48     const QPixmap &getPosBar() const;
49     const QPixmap &getNumber(uint n) const;
50     /*!
51      * Returns count of numbers in number list.
52      * We need this to check if we have "-" in pixmaps.
53      * if no we should draw it manually.
54      */
55     uint getNumCount(void) const;
56     const QPixmap getPlPart(uint p) const;
57     const QPixmap getEqPart(uint p) const;
58     const QPixmap &getEqSlider(uint n) const;
59     const QPixmap &getEqSpline(uint n) const;
60     const QPixmap getMSPart(uint n) const;
61     const QPixmap getLetter(const QChar& ch) const;
62     const QPixmap getItem(uint n) const;
63     const QPixmap &getVolumeBar(int n) const;
64     const QPixmap &getBalanceBar(int n) const;
65     const QByteArray getPLValue (QByteArray c) const;
66     const QColor getMainColor(int n) const;
67     const QColor &getVisColor(int n) const;
68     const QRegion getRegion(uint r) const;
69 
70     enum Button
71     {
72         BT_PREVIOUS_N = 0,
73         BT_PREVIOUS_P,
74         BT_PLAY_N,
75         BT_PLAY_P,
76         BT_PAUSE_N,
77         BT_PAUSE_P,
78         BT_STOP_N,
79         BT_STOP_P,
80         BT_NEXT_N,
81         BT_NEXT_P,
82         BT_EJECT_N,
83         BT_EJECT_P,
84         /*titlebar.* */
85         BT_MENU_N,
86         BT_MENU_P,
87         BT_MINIMIZE_N,
88         BT_MINIMIZE_P,
89         BT_CLOSE_N,
90         BT_CLOSE_P,
91         BT_SHADE1_N,
92         BT_SHADE1_P,
93         BT_SHADE2_N,
94         BT_SHADE2_P,
95         BT_CLOSE_SHADED_N,
96         BT_CLOSE_SHADED_P,
97 
98         /* posbar.* */
99         BT_POSBAR_N,
100         BT_POSBAR_P,
101         /* pledit.* */
102         PL_BT_ADD,
103         PL_BT_SUB,
104         PL_BT_SEL,
105         PL_BT_SORT,
106         PL_BT_LST,
107         PL_BT_SCROLL_N,
108         PL_BT_SCROLL_P,
109         PL_BT_CLOSE_N,
110         PL_BT_CLOSE_P,
111         PL_BT_SHADE1_N,
112         PL_BT_SHADE1_P,
113         PL_BT_SHADE2_N,
114         PL_BT_SHADE2_P,
115 
116         /* eqmain.* */
117         EQ_BT_BAR_N,
118         EQ_BT_BAR_P,
119         EQ_BT_ON_N,
120         EQ_BT_ON_P,
121         EQ_BT_OFF_N,
122         EQ_BT_OFF_P,
123         EQ_BT_PRESETS_N,
124         EQ_BT_PRESETS_P,
125         EQ_BT_AUTO_1_N,
126         EQ_BT_AUTO_1_P,
127         EQ_BT_AUTO_0_N,
128         EQ_BT_AUTO_0_P,
129         EQ_BT_CLOSE_N,
130         EQ_BT_CLOSE_P,
131         EQ_BT_SHADE1_N,
132 
133         /* eq_ex.* */
134         EQ_BT_SHADE1_P,
135         EQ_BT_SHADE2_N,
136         EQ_BT_SHADE2_P,
137 
138         /* shufrep.* */
139         BT_EQ_ON_N,
140         BT_EQ_ON_P,
141         BT_EQ_OFF_N,
142         BT_EQ_OFF_P,
143         BT_PL_ON_N,
144         BT_PL_ON_P,
145         BT_PL_OFF_N,
146         BT_PL_OFF_P,
147         BT_PL_CLOSE_N,
148         BT_PL_CLOSE_P,
149         REPEAT_ON_N,
150         REPEAT_ON_P,
151         REPEAT_OFF_N,
152         REPEAT_OFF_P,
153         SHUFFLE_ON_N,
154         SHUFFLE_ON_P,
155         SHUFFLE_OFF_N,
156         SHUFFLE_OFF_P,
157         /* volume.* */
158         BT_VOL_N,
159         BT_VOL_P,
160         /* balance.* */
161         BT_BAL_N,
162         BT_BAL_P,
163     };
164     enum TitleBarPart
165     {
166         TITLEBAR_A = 0,
167         TITLEBAR_I,
168         TITLEBAR_SHADED_A,
169         TITLEBAR_SHADED_I
170     };
171     enum PlayListPart
172     {
173         PL_CORNER_UL_A = 0,
174         PL_CORNER_UL_I,
175         PL_CORNER_UR_A,
176         PL_CORNER_UR_I,
177         PL_TITLEBAR_A,
178         PL_TITLEBAR_I,
179         PL_TFILL1_A,
180         PL_TFILL1_I,
181         PL_TFILL2_A,
182         PL_TFILL2_I,
183         PL_LFILL,
184         PL_RFILL,
185         PL_LSBAR,
186         PL_RSBAR,
187         PL_SFILL1,
188         PL_SFILL2,
189         PL_CONTROL,
190         PL_TITLEBAR_SHADED1_A,
191         PL_TITLEBAR_SHADED1_I,
192         PL_TITLEBAR_SHADED2,
193         PL_TFILL_SHADED
194     };
195     enum EqualizerPart
196     {
197         EQ_MAIN = 0,
198         EQ_TITLEBAR_A,
199         EQ_TITLEBAR_I,
200         EQ_GRAPH,
201         EQ_TITLEBAR_SHADED_A,
202         EQ_TITLEBAR_SHADED_I,
203         EQ_VOLUME1,
204         EQ_VOLUME2,
205         EQ_VOLUME3,
206         EQ_BALANCE1,
207         EQ_BALANCE2,
208         EQ_BALANCE3
209     };
210     enum MonoSterPart
211     {
212         MONO_A = 0,
213         MONO_I,
214         STEREO_A,
215         STEREO_I
216     };
217     enum OtherPart
218     {
219         PLAY = 0,
220         PAUSE,
221         STOP
222     };
223     enum Regions
224     {
225         NORMAL = 0,
226         EQUALIZER,
227         WINDOW_SHADE,
228         EQUALIZER_WS
229     };
230     enum Cursor
231     {
232         CUR_NORMAL = 0,
233         CUR_CLOSE,
234         CUR_MAINMENU,
235         CUR_MIN,
236         CUR_POSBAR,
237         CUR_SONGNAME,
238         CUR_TITLEBAR,
239         CUR_VOLBAL,
240         CUR_WINBUT,
241 
242         CUR_WSNORMAL,
243         CUR_WSPOSBAR,
244 
245         CUR_EQCLOSE,
246         CUR_EQNORMAL,
247         CUR_EQSLID,
248         CUR_EQTITLE,
249 
250         CUR_PCLOSE,
251         CUR_PNORMAL,
252         CUR_PSIZE,
253         CUR_PTBAR,
254         CUR_PVSCROLL,
255         CUR_PWINBUT,
256 
257         CUR_PWSNORM,
258         CUR_PWSSIZE,
259 
260         CUR_VOLBAR,
261         CUR_WSCLOSE,
262         CUR_WSMIN,
263         CUR_WSWINBUT
264     };
265     enum Color
266     {
267         MW_BACKGROUND = 0,
268         MW_FOREGROUND
269     };
270 
271 public slots:
272     void setSkin(const QString& path);
273     void reloadSkin();
274 
275 signals:
276     void skinChanged();
277 
278 private:
279     QPixmap *getPixmap(const QString &name, const QString &fallback = QString());
280     QString getPath(const QString&);
281     const QString findFile(const QString &name);
282     /*!
283      * As far as there is no standard in skin making we cannot be sure
284      * that all needful images we can find in skin :( This will cause
285      * segfaults and asserts. So to prevent this we need such method
286      * to load pixmap from default skin.
287      */
288     QPixmap *getDummyPixmap(const QString &name, const QString &fallback);
289     QPixmap scalePixmap(const QPixmap &pix, int ratio = 2);
290     static Skin *m_instance;
291     QDir m_skin_dir;
292     QMap<uint, QPixmap> m_buttons;
293     QMap<uint, QCursor> m_cursors;
294     QMap<uint, QPixmap> m_titlebar;
295     QMap<uint, QPixmap> m_pl_parts;
296     QMap<uint, QPixmap> m_eq_parts;
297     QMap<uint, QPixmap> m_ms_parts;
298     QMap<uint, QPixmap> m_parts;
299     QMap<QChar, QPixmap> m_letters;
300     QMap<QByteArray, QByteArray> m_pledit_txt;
301     QMap<uint, QRegion> m_regions;
302     QPixmap m_main;
303     QPixmap posbar;
304     QList<QPixmap> m_numbers;
305     QList<QPixmap> m_eq_bar;
306     QList<QPixmap> m_eq_spline;
307     QList<QPixmap> m_volume;
308     QList<QPixmap> m_balance;
309     QList<QColor> m_vis_colors;
310     QMap<uint, QColor> m_main_colors;
311     bool m_use_cursors;
312     bool m_double_size;
313     bool m_antialiasing;
314 
315     void loadMain();
316     void loadButtons();
317     void loadCursors();
318     void loadColors();
319     void loadTitleBar();
320     void loadPosBar();
321     void loadNumbers();
322     void loadPlayList();
323     void loadPLEdit();
324     void loadEqMain();
325     void loadEq_ex();
326     void loadVisColor();
327     void loadShufRep();
328     void loadLetters();
329     void loadMonoSter();
330     void loadVolume();
331     void loadBalance();
332     void loadRegion();
333     QRegion createRegion(const QString &path, const QString &group);
334     QPixmap *correctSize(QPixmap *pixmap, int w, int h);
335 };
336 
337 #endif
338