1 /*
2  * %kadu copyright begin%
3  * Copyright 2014 Piotr Dąbrowski (ultr@ultr.pl)
4  * Copyright 2011, 2012 Bartosz Brachaczek (b.brachaczek@gmail.com)
5  * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
6  * %kadu copyright end%
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (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, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef KADU_ICON_H
23 #define KADU_ICON_H
24 
25 #include <QtCore/QString>
26 
27 #include "exports.h"
28 
29 class QIcon;
30 
31 /**
32  * @addtogroup Icons
33  * @{
34  */
35 
36 /**
37  * @class KaduIcon
38  * @author Bartosz 'beevvy' Brachaczek
39  * @author Rafał 'Vogel' Malinowski
40  * @short Object that stores Kadu-specific information about icon and allows to retrieve the icon itself.
41  *
42  * Objects of this class store Kadu-specific information about icons and allow to retrieve the icons
43  * themselves, as well as their paths and sizes and also full system paths and WebKit-friendly paths.
44  * KaduIcon objects can be bound to specific theme or to current one (default behavior). Use setThemePath()
45  * method to set specific theme.
46  *
47  * Creating objects of this class is relatively cheap as no data is verified or additionally retrieved
48  * in the constructor.
49  *
50  * It is recommended for use everywhere using icons provided by IconsManager. It saves direct calls to
51  * IconsManager and helps managing icons, especially when one wants to store for example both the icon
52  * path and QIcon object.
53  */
54 class KADUAPI KaduIcon
55 {
56 	QString ThemePath;
57 	QString Path;
58 	QString IconSize;
59 
60 public:
61 	/**
62 	 * @author Bartosz 'beevvy' Brachaczek
63 	 * @short Creates null KaduIcon object.
64 	 *
65 	 * Creates null KaduIcon object. isNull() will return true.
66 	 */
KaduIcon()67 	KaduIcon() {}
68 
69 	/**
70 	 * @author Bartosz 'beevvy' Brachaczek
71 	 * @short Creates KaduIcon object.
72 	 * @param path path to this icon
73 	 * @param size requested size as string formatted as "WIDTHxHEIGHT" or "svg"
74 	 *
75 	 * Creates KaduIcon object from given path and optionally size and name.
76 	 */
Path(path)77 	explicit KaduIcon(const QString &path, const QString &size = QString()) : Path(path), IconSize(size) {}
78 
79 	/**
80 	 * @author Bartosz 'beevvy' Brachaczek
81 	 * @short Returns true if this object is null.
82 	 * @return true if this object is null, false otherwise
83 	 *
84 	 * Returns true if this object is null. Every object with empty path() is considered null.
85 	 */
isNull()86 	bool isNull() const { return path().isEmpty(); }
87 
88 	/**
89 	 * @author Rafał 'Vogel' Malinowski
90 	 * @short Return theme path of this icon.
91 	 * @return theme path of this icon
92 	 *
93 	 * If this method returns empty string, then current theme path should be used.
94 	 */
themePath()95 	const QString & themePath() const { return ThemePath; }
96 
97 	/**
98 	 * @author Rafał 'Vogel' Malinowski
99 	 * @short Set theme path of this icon.
100 	 * @param themePath new theme path of this icon
101 	 *
102 	 * Empty value of themePath means that current theme path should be used for this icon.
103 	 */
setThemePath(const QString & themePath)104 	void setThemePath(const QString &themePath) { ThemePath = themePath; }
105 
106 	/**
107 	 * @author Bartosz 'beevvy' Brachaczek
108 	 * @short Returns path to this icon.
109 	 * @return path to this icon
110 	 *
111 	 * Returns path to this icon.
112 	 */
path()113 	const QString & path() const { return Path; }
114 
115 	/**
116 	 * @author Bartosz 'beevvy' Brachaczek
117 	 * @short Sets path to this icon and resets all other data.
118 	 * @param path path to this icon
119 	 *
120 	 * Sets path to this icon and resets its size.
121 	 */
setPath(const QString & path)122 	void setPath(const QString &path) { Path = path; }
123 
124 	/**
125 	 * @author Bartosz 'beevvy' Brachaczek
126 	 * @short Returns requested size of file pointed by fullPath() and webKitPath(), if set.
127 	 * @return size as string formatted like "WIDTHxHEIGHT"
128 	 *
129 	 * Returns requested size of file pointed by fullPath() and webKitPath(), if set.
130 	 */
size()131 	const QString & size() const { return IconSize; }
132 
133 	/**
134 	 * @author Bartosz 'beevvy' Brachaczek
135 	 * @short Sets the requested size of icon file.
136 	 * @param size requested size as string formatted as "WIDTHxHEIGHT" or "svg"
137 	 *
138 	 * Sets the requested size of icon file returned by fullPath() and webKitPath() methods.
139 	 */
setSize(const QString & size)140 	void setSize(const QString &size) { IconSize = size; }
141 
142 };
143 
144 /**
145  * @}
146  */
147 
148 #endif // KADU_ICON_H
149