Changeset View
Changeset View
Standalone View
Standalone View
src/icon.h
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> | 2 | * SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> | ||
3 | * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> | 3 | * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> | ||
4 | * SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com> | ||||
4 | * | 5 | * | ||
5 | * SPDX-License-Identifier: LGPL-2.0-or-later | 6 | * SPDX-License-Identifier: LGPL-2.0-or-later | ||
6 | */ | 7 | */ | ||
7 | 8 | | |||
8 | #pragma once | 9 | #pragma once | ||
9 | 10 | | |||
10 | #include <QIcon> | 11 | #include <QIcon> | ||
11 | #include <QQuickItem> | 12 | #include <QQuickItem> | ||
12 | #include <QVariant> | 13 | #include <QVariant> | ||
13 | #include <QPointer> | 14 | #include <QPointer> | ||
14 | 15 | | |||
15 | class QNetworkAccessManager; | 16 | class QNetworkAccessManager; | ||
16 | class QNetworkReply; | 17 | class QNetworkReply; | ||
17 | 18 | | |||
18 | namespace Kirigami { | 19 | namespace Kirigami { | ||
19 | class PlatformTheme; | 20 | class PlatformTheme; | ||
20 | } | 21 | } | ||
21 | 22 | | |||
23 | /** | ||||
24 | * Class for rendering an icon in UI. | ||||
25 | */ | ||||
22 | class Icon : public QQuickItem | 26 | class Icon : public QQuickItem | ||
23 | { | 27 | { | ||
24 | Q_OBJECT | 28 | Q_OBJECT | ||
25 | 29 | | |||
30 | /** | ||||
31 | * The source of this icon. An `Icon` can pull from: | ||||
32 | * | ||||
33 | * * The icon theme: | ||||
34 | * @include icon/IconThemeSource.qml | ||||
35 | * * The filesystem: | ||||
36 | * @include icon/FilesystemSource.qml | ||||
37 | * * Remote URIs: | ||||
nicolasfella: Maybe instead of internet something like "a remote url" since it may be from the local network… | |||||
38 | * @include icon/InternetSource.qml | ||||
39 | * * Custom providers: | ||||
40 | * @include icon/CustomSource.qml | ||||
41 | * * Your application's bundled resources: | ||||
42 | * @include icon/ResourceSource.qml | ||||
43 | * | ||||
44 | * @note See https://doc.qt.io/qt-5/qtquickcontrols2-icons.html for how to | ||||
45 | * bundle icon themes in your application to refer to them by name instead of | ||||
46 | * by resource URL. | ||||
47 | * | ||||
48 | * @note Use `fallback` to provide a fallback theme name for icons. | ||||
49 | */ | ||||
26 | Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged) | 50 | Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged) | ||
51 | | ||||
52 | /** | ||||
53 | * The name of a fallback icon to load from the icon theme when the `source` | ||||
broulik: Mention `Default is "unknown"` | |||||
54 | * cannot be found. The default fallback icon is `"unknown"`. | ||||
55 | * | ||||
56 | * @include icon/Fallback.qml | ||||
57 | * | ||||
58 | * @note This will only be loaded if source is unavailable (e.g. it doesn't exist, or network issues have prevented loading). | ||||
broulik: is not found, or is it "failed to load"? | |||||
59 | */ | ||||
60 | Q_PROPERTY(QString fallback READ fallback WRITE setFallback NOTIFY fallbackChanged) | ||||
61 | | ||||
62 | /** | ||||
63 | * Whether pixmaps will be scaled smoothly if the size of this `Icon` is | ||||
64 | * different from the source size. | ||||
65 | */ | ||||
27 | Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) | 66 | Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) | ||
67 | | ||||
68 | /** | ||||
69 | * The `implicitWidth` of this item, derived from the `source` image. | ||||
Maybe mention that it's read-only. Do we have some standard way of doing that? nicolasfella: Maybe mention that it's read-only. Do we have some standard way of doing that? | |||||
cblack: It's mentioned by Doxygen | |||||
70 | */ | ||||
28 | Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT) | 71 | Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT) | ||
72 | | ||||
73 | /** | ||||
74 | * The `implicitHeight` of this item, derived from the `source` image. | ||||
75 | */ | ||||
broulik: Urgh, I wonder why this property got shadowed and why it is `CONSTANT` :0 | |||||
29 | Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT) | 76 | Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT) | ||
77 | | ||||
78 | /** | ||||
79 | * Whether this icon will use the QIcon::Active mode when drawing the icon, | ||||
80 | * resulting in a graphical effect being applied to the icon to indicate that | ||||
81 | * it is currently active. | ||||
broulik: "Typically used when an element is hovered"? | |||||
82 | * | ||||
83 | * This is typically used to indicate when an item is being hovered or pressed. | ||||
84 | * | ||||
85 | * @image html icon/active.png | ||||
broulik: Huh? | |||||
86 | * | ||||
87 | * The color differences under the default KDE color palette, Breeze. Note | ||||
88 | * that a dull highlight background is typically displayed behind active icons and | ||||
89 | * it is recommended to add one if you are creating a custom component. | ||||
90 | */ | ||||
30 | Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) | 91 | Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) | ||
92 | | ||||
93 | /** | ||||
94 | * Whether this icon's `source` is valid and it is being used. | ||||
95 | */ | ||||
31 | Q_PROPERTY(bool valid READ valid NOTIFY validChanged) | 96 | Q_PROPERTY(bool valid READ valid NOTIFY validChanged) | ||
97 | | ||||
98 | /** | ||||
99 | * Whether this icon will use the QIcon::Selected mode when drawing the icon, | ||||
broulik: `Selected` | |||||
100 | * resulting in a graphical effect being applied to the icon to indicate that | ||||
101 | * it is currently selected. | ||||
102 | * | ||||
103 | * This is typically used to indicate when a list item is currently selected. | ||||
104 | * | ||||
105 | * @image html icon/selected.png | ||||
106 | * | ||||
107 | * The color differences under the default KDE color palette, Breeze. Note | ||||
108 | * that a blue background is typically displayed behind selected elements. | ||||
109 | */ | ||||
32 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) | 110 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) | ||
111 | | ||||
112 | /** | ||||
113 | * Whether this icon will be treated as a mask. When an icon is being used | ||||
broulik: This sounds to me as if you end up with a colored square. :) | |||||
114 | * as a mask, all non-transparent colors are replaced with the color provided in the Icon's | ||||
115 | * @link Icon::color color @endlink property. | ||||
116 | * | ||||
117 | * @see color | ||||
118 | */ | ||||
33 | Q_PROPERTY(bool isMask READ isMask WRITE setIsMask NOTIFY isMaskChanged) | 119 | Q_PROPERTY(bool isMask READ isMask WRITE setIsMask NOTIFY isMaskChanged) | ||
120 | | ||||
121 | /** | ||||
122 | * The color to use when drawing this icon when `isMask` is enabled. | ||||
123 | * If this property is not set or is `Qt::transparent`, the icon will use | ||||
124 | * the text or the selected text color, depending on if `selected` is set to | ||||
125 | * true. | ||||
126 | */ | ||||
34 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | 127 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | ||
35 | Q_PROPERTY(QString fallback READ fallback WRITE setFallback NOTIFY fallbackChanged) | | |||
36 | 128 | | |||
37 | public: | 129 | public: | ||
38 | Icon(QQuickItem *parent = nullptr); | 130 | Icon(QQuickItem *parent = nullptr); | ||
39 | ~Icon(); | 131 | ~Icon(); | ||
40 | 132 | | |||
41 | void setSource(const QVariant &source); | 133 | void setSource(const QVariant &source); | ||
42 | QVariant source() const; | 134 | QVariant source() const; | ||
43 | 135 | | |||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Maybe instead of internet something like "a remote url" since it may be from the local network as well