Kirigami2

icon.h
1 /*
2  * SPDX-FileCopyrightText: 2011 Marco Martin <[email protected]>
3  * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <[email protected]>
4  * SPDX-FileCopyrightText: 2020 Carson Black <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.0-or-later
7  */
8 
9 #pragma once
10 
11 #include <QIcon>
12 #include <QQuickItem>
13 #include <QVariant>
14 #include <QPointer>
15 
17 class QNetworkReply;
18 
19 namespace Kirigami {
20  class PlatformTheme;
21 }
22 
26 class Icon : public QQuickItem
27 {
28  Q_OBJECT
29 
50  Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged)
51 
52 
60  Q_PROPERTY(QString fallback READ fallback WRITE setFallback NOTIFY fallbackChanged)
61 
66  Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
67 
71  Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT)
72 
76  Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT)
77 
91  Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
92 
96  Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
97 
110  Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
111 
119  Q_PROPERTY(bool isMask READ isMask WRITE setIsMask NOTIFY isMaskChanged)
120 
127  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
128 
129 public:
130  Icon(QQuickItem *parent = nullptr);
131  ~Icon();
132 
133  void setSource(const QVariant &source);
134  QVariant source() const;
135 
136  int implicitWidth() const;
137  int implicitHeight() const;
138 
139  void setSmooth(const bool smooth);
140  bool smooth() const;
141 
142  void setActive(bool active = true);
143  bool active() const;
144 
145  bool valid() const;
146 
147  void setSelected(bool selected = true);
148  bool selected() const;
149 
150  void setIsMask(bool mask);
151  bool isMask() const;
152 
153  void setColor(const QColor &color);
154  QColor color() const;
155 
156  QString fallback() const;
157  void setFallback(const QString &fallback);
158 
159  QSGNode* updatePaintNode(QSGNode* node, UpdatePaintNodeData* data) override;
160 
161 Q_SIGNALS:
162  void sourceChanged();
163  void smoothChanged();
164  void enabledChanged();
165  void activeChanged();
166  void validChanged();
167  void selectedChanged();
168  void isMaskChanged();
169  void colorChanged();
170  void fallbackChanged(const QString &fallback);
171 
172 protected:
173  void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
174  QImage findIcon(const QSize& size);
175  void handleFinished(QNetworkReply* reply);
176  void handleRedirect(QNetworkReply* reply);
177  QIcon::Mode iconMode() const;
178  bool guessMonochrome(const QImage &img);
179  void updatePolish() override;
180 
181 private:
182  Kirigami::PlatformTheme *m_theme = nullptr;
183  QPointer<QNetworkReply> m_networkReply;
184  QHash<int, bool> m_monochromeHeuristics;
185  QVariant m_source;
186  bool m_smooth;
187  bool m_changed;
188  bool m_active;
189  bool m_selected;
190  bool m_isMask;
191  bool m_isMaskHeuristic = false;
192  QImage m_loadedImage;
193  QColor m_color = Qt::transparent;
194  QString m_fallback = QStringLiteral("unknown");
195 
196  QImage m_icon;
197 };
198 
Definition: icon.h:19
Class for rendering an icon in UI.
Definition: icon.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 22:38:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.