Make sure NickView::customEvent() has a valid model
[quassel.git] / src / uisupport / iconloader.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
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 #ifndef HAVE_KDE
28
29 #include <QPixmap>
30
31 /// Provides basic facilities to load icons from standard locations or resources
32 /** This implements a (very) basic subset of KIconLoader's API, such that we can use those classes
33  *  interchangeably in Quassel.
34  *
35  *  We currently (unless somebody does a more fancy implementation ;-)) assume the Oxygen icon theme
36  *  to be used. In particular, this means that we do assume its directory layout and existing icons to
37  *  be present. Though it should be easy to switch to a different theme name, we don't currently support
38  *  any fallback mechanism if this other theme misses an icon for a given size. Also, we only support PNG.
39  *
40  *  Since we do support integrating the required part of Oxygen into the binary via Qt Resources, this
41  *  should work for everyone for now.
42  *
43  *  - $XDG_DATA_DIRS/icons/$theme (in order)
44  *  - :/icons/$theme (fallback in case we use Qt Resources)
45  *  - $XDG_DATA_DIRS/apps/quassel/icons/hicolor (our own unthemed icons)
46  *  - :/icons/hicolor
47  *  - $XDG_DATA_DIRS/apps/quassel/pics
48  *  - :/pics
49  *
50  *  We don't search for size/context dirs in /pics, i.e. for a given $name, we expect pics/$name.png.
51  */
52 class IconLoader : public QObject {
53   Q_OBJECT
54
55 public:
56   enum Group {
57     NoGroup = -1,   ///< No group
58     Desktop = 0,    ///< Desktop icons
59     Toolbar,        ///< Toolbar icons
60     MainToolbar,    ///< Main toolbar icons
61     Small,          ///< Small icons, e.g. for buttons
62     Panel,          ///< Panel icons
63     Dialog,         ///< Icons for use in dialog title etc.
64     LastGroup
65   };
66
67   /// Standard icon sizes
68   enum StdSizes {
69     SizeSmall=16,         ///< Small icons for menu entries
70     SizeSmallMedium=22,   ///< Slightly larger small icons for toolbars, panels, etc
71     SizeMedium=32,        ///< Medium-sized icons for the desktop
72     SizeLarge=48,         ///< Large icons for the panel
73     SizeHuge=64,          ///< Huge icons for iconviews
74     SizeEnormous=128      ///< Enormous icons for iconviews
75   };
76
77   explicit IconLoader(QObject *parent = 0);
78   ~IconLoader();
79
80   static IconLoader *global();
81
82   /// Load a pixmap for the given name and group
83   QPixmap loadIcon(const QString& name, IconLoader::Group group, int size = 0);
84
85   inline QString theme() const;
86   void setTheme(const QString &name);
87
88 private:
89   QString findIconPath(const QString &name, int size);
90
91   static IconLoader _iconLoader;
92   QString _theme;
93   QStringList _themedIconDirNames;
94   QStringList _plainIconDirNames;
95   static int _groupSize[];
96 };
97
98 // convenience
99 QPixmap DesktopIcon(const QString& name, int size = 0);
100 QPixmap BarIcon(const QString& name, int size = 0);
101 QPixmap MainBarIcon(const QString& name, int size = 0);
102 QPixmap SmallIcon(const QString& name, int size = 0);
103 //QPixmap SmallMediumIcon(const QString &name, int size = 0);  // not part of KIconLoader
104
105 QString IconLoader::theme() const { return _theme; }
106
107 #else /* HAVE_KDE */
108
109 #include <KIconLoader>
110 class IconLoader : public KIconLoader { Q_OBJECT };
111
112 #endif /* HAVE_KDE */
113
114 #endif