Build the monolithic client (-DWANT_MONO=ON) by default again, as it's usable now
[quassel.git] / src / uisupport / iconloader.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
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 General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************
20  * Based in part on KDE's kiconloader.h                                    *
21  * This declares a subset of that API.                                     *
22  ***************************************************************************/
23
24 #ifndef ICONLOADER_H_
25 #define ICONLOADER_H_
26
27 #include <QPixmap>
28
29 /// Provides basic facilities to load icons from standard locations or resources
30 /** This implements a (very) basic subset of KIconLoader's API, such that we can use those classes
31  *  interchangeably in Quassel.
32  *
33  *  We currently (unless somebody does a more fancy implementation ;-)) assume the Oxygen icon theme
34  *  to be used. In particular, this means that we do assume its directory layout and existing icons to
35  *  be present. Though it should be easy to switch to a different theme name, we don't currently support
36  *  any fallback mechanism if this other theme misses an icon for a given size. Also, we only support PNG.
37  *
38  *  Since we do support integrating the required part of Oxygen into the binary via Qt Resources, this
39  *  should work for everyone for now.
40  *
41  *  - $XDG_DATA_DIRS/icons/$theme (in order)
42  *  - :/icons/$theme (fallback in case we use Qt Resources)
43  *  - $XDG_DATA_DIRS/apps/quassel/icons/hicolor (our own unthemed icons)
44  *  - :/icons/hicolor
45  *  - $XDG_DATA_DIRS/apps/quassel/pics
46  *  - :/pics
47  *
48  *  We don't search for size/context dirs in /pics, i.e. for a given $name, we expect pics/$name.png.
49  */
50 class IconLoader : public QObject {
51   Q_OBJECT
52
53 public:
54   enum Group {
55     NoGroup = -1,   ///< No group
56     Desktop = 0,    ///< Desktop icons
57     Toolbar,        ///< Toolbar icons
58     MainToolbar,    ///< Main toolbar icons
59     Small,          ///< Small icons, e.g. for buttons
60     Panel,          ///< Panel icons
61     Dialog,         ///< Icons for use in dialog title etc.
62     LastGroup
63   };
64
65   /// Standard icon sizes
66   enum StdSizes {
67     SizeSmall=16,         ///< Small icons for menu entries
68     SizeSmallMedium=22,   ///< Slightly larger small icons for toolbars, panels, etc
69     SizeMedium=32,        ///< Medium-sized icons for the desktop
70     SizeLarge=48,         ///< Large icons for the panel
71     SizeHuge=64,          ///< Huge icons for iconviews
72     SizeEnormous=128      ///< Enormous icons for iconviews
73   };
74
75   explicit IconLoader(QObject *parent = 0);
76   ~IconLoader();
77
78   static IconLoader *global();
79
80   /// Load a pixmap for the given name and group
81   QPixmap loadIcon(const QString& name, IconLoader::Group group, int size = 0);
82
83   inline QString theme() const;
84   void setTheme(const QString &name);
85
86 private:
87   QString findIconPath(const QString &name, int size);
88
89   static IconLoader _iconLoader;
90   QString _theme;
91   QStringList _themedIconDirNames;
92   QStringList _plainIconDirNames;
93   static int _groupSize[];
94 };
95
96 // convenience
97 QPixmap DesktopIcon(const QString& name, int size = 0);
98 QPixmap BarIcon(const QString& name, int size = 0);
99 QPixmap MainBarIcon(const QString& name, int size = 0);
100 QPixmap SmallIcon(const QString& name, int size = 0);
101 //QPixmap SmallMediumIcon(const QString &name, int size = 0);  // not part of KIconLoader
102
103 QString IconLoader::theme() const { return _theme; }
104
105 #endif