Tulip  5.2.0
Large graphs analysis and drawing
TulipFontIconEngine.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip 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.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef TULIPFONTICONENGINE_H
22 #define TULIPFONTICONENGINE_H
23 
24 #include <QIconEngine>
25 #include <QPixmap>
26 #include <QString>
27 #include <tulip/tulipconf.h>
28 
29 class TLP_QT_SCOPE TulipFontIconEngine : public QIconEngine {
30  unsigned int codePoint;
31  QString fontName;
32 
33  void init(const std::string &iconName);
34 
35 public:
36  TulipFontIconEngine(const std::string &iconName);
37  TulipFontIconEngine(const QString &iconName);
38  TulipFontIconEngine(const TulipFontIconEngine &engine)
39  : QIconEngine(), codePoint(engine.codePoint), fontName(engine.fontName) {}
40 
41  TulipFontIconEngine *clone() const {
42  return new TulipFontIconEngine(*this);
43  }
44 
45  void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
46 
47  QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
48 
49  static inline QIcon icon(const char *iconName) {
50  return QIcon(new TulipFontIconEngine(std::string(iconName)));
51  }
52 
53  static inline QIcon icon(const std::string &iconName) {
54  return QIcon(new TulipFontIconEngine(iconName));
55  }
56 
57  static inline QIcon icon(const QString &iconName) {
58  return QIcon(new TulipFontIconEngine(iconName));
59  }
60 
61  static inline QPixmap pixmap(const std::string &iconName, unsigned int height,
62  QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::On) {
63  return TulipFontIconEngine(iconName).pixmap(QSize(height, height), mode, state);
64  }
65 
66  static inline QPixmap pixmap(const QString &iconName, unsigned int height,
67  QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::On) {
68  return TulipFontIconEngine(iconName).pixmap(QSize(height, height), mode, state);
69  }
70 };
71 
72 #endif
73 ///@endcond