1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.icon;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.list;
20 import qt.core.metatype;
21 import qt.core.namespace;
22 import qt.core.rect;
23 import qt.core.size;
24 import qt.core.string;
25 import qt.core.stringlist;
26 import qt.core.typeinfo;
27 import qt.core.variant;
28 import qt.gui.painter;
29 import qt.gui.pixmap;
30 import qt.gui.windowdefs;
31 import qt.helpers;
32 
33 extern(C++, class) struct QIconPrivate;
34 extern(C++, class) struct QIconEngine;
35 /+ class QPainter; +/
36 
37 @Q_MOVABLE_TYPE @(QMetaType.Type.QIcon) extern(C++, class) struct /+ Q_GUI_EXPORT +/ QIcon
38 {
39 public:
40     enum Mode { Normal, Disabled, Active, Selected }
41     enum State { On, Off }
42 
43     /+this()/+ noexcept+/;+/
44 
45     this(ref const(QPixmap) pixmap);
46     @disable this(this);
47     this(ref const(QIcon) other);
48     /+ QIcon(QIcon &&other) noexcept
49         : d(other.d)
50     { other.d = nullptr; } +/
51     /+ explicit +/this(ref const(QString) fileName); // file or resource name
52     /+ explicit +/this(QIconEngine* engine);
53     ~this();
54     /+ref QIcon operator =(ref const(QIcon) other);+/
55     /+ inline QIcon &operator=(QIcon &&other) noexcept
56     { swap(other); return *this; } +/
57     /+ inline void swap(QIcon &other) noexcept
58     { qSwap(d, other.d); } +/
59 
60     /+auto opCast(T : QVariant)() const;+/
61 
62     QPixmap pixmap(ref const(QSize) size, Mode mode = Mode.Normal, State state = State.Off) const;
63     pragma(inline, true) QPixmap pixmap(int w, int h, Mode mode = Mode.Normal, State state = State.Off) const
64         { auto tmp = QSize(w, h); return pixmap(tmp, mode, state); }
65     pragma(inline, true) QPixmap pixmap(int extent, Mode mode = Mode.Normal, State state = State.Off) const
66         { auto tmp = QSize(extent, extent); return pixmap(tmp, mode, state); }
67     QPixmap pixmap(QWindow* window, ref const(QSize) size, Mode mode = Mode.Normal, State state = State.Off) const;
68 
69     QSize actualSize(ref const(QSize) size, Mode mode = Mode.Normal, State state = State.Off) const;
70     QSize actualSize(QWindow* window, ref const(QSize) size, Mode mode = Mode.Normal, State state = State.Off) const;
71 
72     QString name() const;
73 
74     void paint(QPainter* painter, ref const(QRect) rect, /+ Qt:: +/qt.core.namespace.Alignment alignment = /+ Qt:: +/qt.core.namespace.AlignmentFlag.AlignCenter, Mode mode = Mode.Normal, State state = State.Off) const;
75     pragma(inline, true) void paint(QPainter* painter, int x, int y, int w, int h, /+ Qt:: +/qt.core.namespace.Alignment alignment = /+ Qt:: +/qt.core.namespace.AlignmentFlag.AlignCenter, Mode mode = Mode.Normal, State state = State.Off) const
76         { auto tmp = QRect(x, y, w, h); paint(painter, tmp, alignment, mode, state); }
77 
78     bool isNull() const;
79     bool isDetached() const;
80     void detach();
81 
82 /+ #if QT_DEPRECATED_SINCE(5, 0)
83     QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
84 #endif +/
85     qint64 cacheKey() const;
86 
87     void addPixmap(ref const(QPixmap) pixmap, Mode mode = Mode.Normal, State state = State.Off);
88     void addFile(ref const(QString) fileName, ref const(QSize) size = globalInitVar!QSize, Mode mode = Mode.Normal, State state = State.Off);
89 
90     QList!(QSize) availableSizes(Mode mode = Mode.Normal, State state = State.Off) const;
91 
92     void setIsMask(bool isMask);
93     bool isMask() const;
94 
95     static QIcon fromTheme(ref const(QString) name);
96     static QIcon fromTheme(ref const(QString) name, ref const(QIcon) fallback);
97     static bool hasThemeIcon(ref const(QString) name);
98 
99     static QStringList themeSearchPaths();
100     static void setThemeSearchPaths(ref const(QStringList) searchpath);
101 
102     static QStringList fallbackSearchPaths();
103     static void setFallbackSearchPaths(ref const(QStringList) paths);
104 
105     static QString themeName();
106     static void setThemeName(ref const(QString) path);
107 
108     static QString fallbackThemeName();
109     static void setFallbackThemeName(ref const(QString) name);
110 
111     /+ Q_DUMMY_COMPARISON_OPERATOR(QIcon) +/
112 
113 private:
114     QIconPrivate* d;
115     version(QT_NO_DATASTREAM){}else
116     {
117         /+ friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); +/
118         /+ friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); +/
119     }
120 
121 public:
122     alias DataPtr = QIconPrivate*;
123     pragma(inline, true) ref DataPtr data_ptr() return { return d; }
124 }
125 
126 /+ Q_DECLARE_SHARED(QIcon)
127 
128 #if !defined(QT_NO_DATASTREAM)
129 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
130 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
131 #endif
132 
133 #ifndef QT_NO_DEBUG_STREAM
134 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
135 #endif +/
136 
137 /+ Q_GUI_EXPORT +/ QString qt_findAtNxFile(ref const(QString) baseFileName, qreal targetDevicePixelRatio,
138                                      qreal* sourceDevicePixelRatio = null);
139