OpenWalnut  1.5.0dev
WIconManager.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WICONMANAGER_H
26 #define WICONMANAGER_H
27 
28 #include <map>
29 #include <string>
30 
31 #include <boost/filesystem/path.hpp>
32 
33 #include <QIcon>
34 
35 #include "core/graphicsEngine/WGEImage.h"
36 
37 /**
38  * Manages icon access. Icons stored either here inside or inside of modules.
39  */
41 {
42 public:
43  /**
44  * Searches icons in the internal map and all modules for the given icon name.
45  * \param name Name of the requested icon
46  * \return A QIcon copy if the icon name was found otherwise a WAssert will fail.
47  */
48  QIcon getIcon( const std::string name );
49 
50  /**
51  * Searches icons in the internal map and all modules for the given icon name. In contrast to the single argument getIcon, this does not throw
52  * an exception if the icon is not found. It returns a default.
53  * \param name Name of the requested icon
54  * \param defaultIcon the default icon to return if no other icon was found.
55  * \return A QIcon copy if the icon name was found otherwise, the default is returned
56  */
57  QIcon getIcon( const std::string name, const QIcon& defaultIcon );
58 
59  /**
60  * Add a mapping for icons. This is useful if you want to use "telling" icons names in your code but want to map these names to some standard
61  * icon. The mapping of the new name needs to be unique. Adding multiple mappings for the newName will be ignored. You can overwrite a
62  * mapping.
63  *
64  * \param newName the name getting mapped
65  * \param mapToThis the icon to use when calling getIcon( newName ). Never add a file anding as png or jpg!
66  */
67  void addMapping( const std::string& newName, const std::string& mapToThis );
68 
69  /**
70  * Convert a WGEImage to an QIcon. Image must be 2D. Everything else causes an empty icon to be returned.
71  *
72  * \param image the image.
73  *
74  * \return icon
75  */
76  static QIcon convertToIcon( WGEImage::SPtr image );
77 
78  /**
79  * Return an icon representing a default "No Icon" icon.
80  *
81  * \return the icon
82  */
83  static QIcon getNoIconDefault();
84 protected:
85 private:
86  std::map< std::string, std::string > m_iconMappingList; //!< A map storing icons and the names used to identify them
87 };
88 
89 #endif // WICONMANAGER_H
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
Manages icon access.
Definition: WIconManager.h:41
void addMapping(const std::string &newName, const std::string &mapToThis)
Add a mapping for icons.
std::map< std::string, std::string > m_iconMappingList
A map storing icons and the names used to identify them.
Definition: WIconManager.h:86
static QIcon getNoIconDefault()
Return an icon representing a default "No Icon" icon.
static QIcon convertToIcon(WGEImage::SPtr image)
Convert a WGEImage to an QIcon.
QIcon getIcon(const std::string name)
Searches icons in the internal map and all modules for the given icon name.