Tulip  6.0.0
Large graphs analysis and drawing
TulipFontIconEngine.h
1 /*
2  *
3  * This file is part of Tulip (https://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 <QFont>
27 #include <tulip/tulipconf.h>
28 #include <tulip/TulipSettings.h>
29 
30 class TLP_QT_SCOPE TulipFontIconEngine : public QIconEngine {
31  QString iconQString;
32  QFont font;
33  bool darkMode;
34 
35  void init(const std::string &iconName);
36 
37 public:
38  TulipFontIconEngine(const std::string &iconName, bool darkMode = false);
39  TulipFontIconEngine(const QString &iconName, bool darkMode = false);
40  TulipFontIconEngine(const TulipFontIconEngine &engine)
41  : QIconEngine(), iconQString(engine.iconQString), font(engine.font) {}
42 
43  TulipFontIconEngine *clone() const override {
44  return new TulipFontIconEngine(*this);
45  }
46 
47  void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
48 
49  QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
50 
51  static inline QIcon icon(const char *iconName, bool darkMode = false) {
52  return QIcon(new TulipFontIconEngine(std::string(iconName), darkMode));
53  }
54 
55  static inline QIcon icon(const std::string &iconName, bool darkMode = false) {
56  return QIcon(new TulipFontIconEngine(iconName, darkMode));
57  }
58 
59  static inline QIcon icon(const QString &iconName, bool darkMode = false) {
60  return QIcon(new TulipFontIconEngine(iconName, darkMode));
61  }
62 
63  static inline QPixmap pixmap(const std::string &iconName, unsigned int height,
64  bool dm = tlp::TulipSettings::isDisplayInDarkMode(),
65  QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::On) {
66  return TulipFontIconEngine(iconName, dm).pixmap(QSize(height, height), mode, state);
67  }
68 
69  static inline QPixmap pixmap(const QString &iconName, unsigned int height,
70  bool dm = tlp::TulipSettings::isDisplayInDarkMode(),
71  QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::On) {
72  return TulipFontIconEngine(iconName, dm).pixmap(QSize(height, height), mode, state);
73  }
74 };
75 
76 #endif
77 ///@endcond