Salome HOME
067ef6ea5ca5662a15ee84a353cc02d8cc47e102
[modules/shaper.git] / src / ModuleBase / ModuleBase_IconFactory.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModuleBase_IconFactory.h"
22
23 #include "Config_XMLReader.h"
24
25 #include <QDir>
26
27 ModuleBase_IconFactory* MYIconFactory = 0;
28
29
30 ModuleBase_IconFactory::ModuleBase_IconFactory()
31 {
32   setFactory(this);
33 }
34
35 void ModuleBase_IconFactory::setFactory(ModuleBase_IconFactory* theFactory)
36 {
37   if (MYIconFactory)
38     delete MYIconFactory;
39   MYIconFactory = theFactory;
40 }
41
42 ModuleBase_IconFactory* ModuleBase_IconFactory::get()
43 {
44   if (!MYIconFactory) {
45     MYIconFactory = new ModuleBase_IconFactory();
46   }
47   return MYIconFactory;
48 }
49
50 QIcon ModuleBase_IconFactory::getIcon(ObjectPtr theIcon)
51 {
52   return QIcon();
53 }
54
55 QIcon ModuleBase_IconFactory::loadIcon(const QString& theValue)
56 {
57   return QIcon(loadPixmap(theValue));
58 }
59
60 QPixmap ModuleBase_IconFactory::loadPixmap(const QString& theValue)
61 {
62   QPixmap aPixmap(theValue);
63
64   if (aPixmap.isNull()) {
65     std::string aPluginPath = Config_XMLReader::pluginConfigFile();
66     QString aPath = QString::fromStdString(aPluginPath) + QDir::separator() + theValue;
67     if (QFile::exists(aPath))
68       aPixmap = QPixmap(aPath);
69   }
70   return aPixmap;
71 }
72
73 QImage ModuleBase_IconFactory::loadImage(const QString& theValue)
74 {
75   QImage anImage(theValue);
76
77   if (anImage.isNull()) {
78     std::string aPluginPath = Config_XMLReader::pluginConfigFile();
79     QString aPath = QString::fromStdString(aPluginPath) + QDir::separator() + theValue;
80     if (QFile::exists(aPath))
81       anImage = QImage(aPath);
82   }
83   return anImage;
84 }