KSvg

framesvgitem.h
1/*
2 SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7#ifndef FRAMESVGITEM_P
8#define FRAMESVGITEM_P
9
10#include <QQmlParserStatus>
11#include <QQuickItem>
12
13#include <KSvg/FrameSvg>
14
15#include <qqmlregistration.h>
16
17namespace Kirigami
18{
19namespace Platform
20{
21class PlatformTheme;
22}
23};
24
25namespace KSvg
26{
27class FrameSvg;
28
29/**
30 * @class FrameSvgItemMargins
31 *
32 * @short The sizes of a frame's margins.
33 */
35{
37 QML_ELEMENT
38 QML_UNCREATABLE("FrameSvgItemMargins are read-only properties of FrameSvgItem")
39
40 /**
41 * @brief This property holds the left margin's width in pixels.
42 * @property real left
43 */
44 Q_PROPERTY(qreal left READ left NOTIFY marginsChanged)
45
46 /**
47 * @brief This property holds the top margin's width in pixels.
48 * @property real top
49 */
50 Q_PROPERTY(qreal top READ top NOTIFY marginsChanged)
51
52 /**
53 * @brief This property holds the right margin's width in pixels.
54 * @property real right
55 */
56 Q_PROPERTY(qreal right READ right NOTIFY marginsChanged)
57
58 /**
59 * @brief This property holds the bottom margin's width in pixels.
60 * @property real bottom
61 */
62 Q_PROPERTY(qreal bottom READ bottom NOTIFY marginsChanged)
63
64 /**
65 * @brief This property holds the combined width of the left and right margins.
66 * @property real horizontal
67 */
68 Q_PROPERTY(qreal horizontal READ horizontal NOTIFY marginsChanged)
69
70 /**
71 * @brief This property holds the combined width of the top and bottom margins.
72 * @property real vertical
73 */
74 Q_PROPERTY(qreal vertical READ vertical NOTIFY marginsChanged)
75
76public:
77 FrameSvgItemMargins(KSvg::FrameSvg *frameSvg, QObject *parent = nullptr);
78
79 qreal left() const;
80 qreal top() const;
81 qreal right() const;
82 qreal bottom() const;
83 qreal horizontal() const;
84 qreal vertical() const;
85
86 /// returns a vector with left, top, right, bottom
87 QList<qreal> margins() const;
88
89 void setFixed(bool fixed);
90 bool isFixed() const;
91
92 void setInset(bool inset);
93 bool isInset() const;
94
95public Q_SLOTS:
96 void update();
97
99 void marginsChanged();
100
101private:
102 FrameSvg *m_frameSvg;
103 bool m_fixed;
104 bool m_inset;
105};
106
107/**
108 * @class FrameSvgItem
109 * @short An SVG Item with borders.
110 * @import org.kde.ksvg
111 */
113{
115 QML_ELEMENT
117
118 /**
119 * @brief This property specifies the relative path of the SVG in the theme.
120 *
121 * Example: "widgets/background"
122 *
123 * @property QString imagePath
124 */
125 Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged)
126
127 /**
128 * This property holds the prefix for the SVG.
129 * prefix for the 9-piece SVG, like "pushed" or "normal" for a button.
130 * see https://techbase.kde.org/Development/Tutorials/Plasma5/ThemeDetails
131 * for a list of paths and prefixes
132 * It can also be an array of strings, specifying a fallback chain in case
133 * the first element isn't found in the theme, eg ["toolbutton-normal", "normal"]
134 * so it's easy to keep backwards compatibility with old themes
135 * (Note: fallback chain is supported only @since 5.32)
136 */
137 Q_PROPERTY(QVariant prefix READ prefix WRITE setPrefix NOTIFY prefixChanged)
138
139 /**
140 * @brief This property holds the actual prefix that was used, if a fallback
141 * chain array was set as "prefix".
142 *
143 * @since 5.34
144 * @property QString usedPrefix
145 */
146 Q_PROPERTY(QString usedPrefix READ usedPrefix NOTIFY usedPrefixChanged)
147
148 /**
149 * @brief This property holds the frame's margins.
150 * @see FrameSvgItemMargins
151 * @property FrameSvgItemMargins margins
152 */
154
155 /**
156 * @brief This property holds the fixed margins of the frame which are used
157 * regardless of any margins being enabled or not.
158 *
159 * @see FrameSvgItemMargins
160 * @property FrameSvgItemMargins margins
161 */
162 Q_PROPERTY(KSvg::FrameSvgItemMargins *fixedMargins READ fixedMargins CONSTANT)
163
164 /**
165 * @brief This property holds the frame's inset.
166 *
167 * @see FrameSvgItemMargins
168 *
169 * @since 5.77
170 * @property FrameSvgItemMargins margins
171 */
172 Q_PROPERTY(KSvg::FrameSvgItemMargins *inset READ inset CONSTANT)
173
174 /**
175 * @brief This property specifies which borders are shown.
176 * @see KSvg::FrameSvg::EnabledBorder
177 * @property flags<KSvg::FrameSvg::EnabledBorder> enabledBorders
178 */
179 Q_PROPERTY(KSvg::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged)
180
181 /**
182 * @brief This property holds whether the current SVG is present in
183 * the currently-used theme and no fallback is involved.
184 */
185 Q_PROPERTY(bool fromCurrentImageSet READ fromCurrentImageSet NOTIFY fromCurrentImageSetChanged)
186
187 /**
188 * @brief This property specifies the SVG's status.
189 *
190 * Depending on the specified status, the SVG will use different colors:
191 * * Normal: text's color is textColor, and background color is
192 * backgroundColor.
193 * * Selected: text color becomes highlightedText and background color is
194 * changed to highlightColor.
195 *
196 * @see Kirigami::PlatformTheme
197 * @see KSvg::Svg::status
198 * @since 5.23
199 * @property enum<KSvg::Svg::Status> status
200 */
201 Q_PROPERTY(KSvg::Svg::Status status READ status WRITE setStatus NOTIFY statusChanged)
202
203 /**
204 * @brief This property holds the mask that contains the SVG's painted areas.
205 * @since 5.58
206 * @property QRegion mask
207 */
208 Q_PROPERTY(QRegion mask READ mask NOTIFY maskChanged)
209
210 /**
211 * @brief This property holds the minimum height required to correctly draw
212 * this SVG.
213 *
214 * @since 5.101
215 * @property int minimumDrawingHeight
216 */
217 Q_PROPERTY(int minimumDrawingHeight READ minimumDrawingHeight NOTIFY repaintNeeded)
218
219 /**
220 * @brief This property holds the minimum width required to correctly draw
221 * this SVG.
222 *
223 * @since 5.101
224 * @property int minimumDrawingWidth
225 */
226 Q_PROPERTY(int minimumDrawingWidth READ minimumDrawingWidth NOTIFY repaintNeeded)
227
228public:
229 /**
230 * @return whether the svg has the necessary elements with the given prefix
231 * to draw a frame.
232 *
233 * @param prefix the given prefix we want to check if drawable
234 */
235 Q_INVOKABLE bool hasElementPrefix(const QString &prefix) const;
236
237 /**
238 * @return whether the SVG includes the given element.
239 *
240 * This is a convenience function that forwards to hasElement().
241 *
242 * @see KSvg::Svg::hasElement()
243 */
244 Q_INVOKABLE bool hasElement(const QString &elementName) const;
245
246 /// @cond INTERNAL_DOCS
247 FrameSvgItem(QQuickItem *parent = nullptr);
248 ~FrameSvgItem() override;
249
250 void setImagePath(const QString &path);
251 QString imagePath() const;
252
253 void setPrefix(const QVariant &prefix);
254 QVariant prefix() const;
255
256 QString usedPrefix() const;
257
258 void setEnabledBorders(const KSvg::FrameSvg::EnabledBorders borders);
259 KSvg::FrameSvg::EnabledBorders enabledBorders() const;
260
261 void setColorSet(KSvg::Svg::ColorSet colorSet);
262 KSvg::Svg::ColorSet colorSet() const;
263
265 FrameSvgItemMargins *fixedMargins();
266 FrameSvgItemMargins *inset();
267
268 bool fromCurrentImageSet() const;
269
270 void setStatus(KSvg::Svg::Status status);
271 KSvg::Svg::Status status() const;
272 int minimumDrawingHeight() const;
273 int minimumDrawingWidth() const;
274
275 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
276
277 QRegion mask() const;
278
279 /**
280 * Only to be used from inside this library, is not intended to be invokable
281 */
282 KSvg::FrameSvg *frameSvg() const;
283
284 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
285
286 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
287
288protected:
289 void classBegin() override;
290 void componentComplete() override;
291
292 /// @endcond
293
295 void imagePathChanged();
296 void prefixChanged();
297 void enabledBordersChanged();
298 void fromCurrentImageSetChanged();
299 void repaintNeeded();
300 void statusChanged();
301 void usedPrefixChanged();
302 void maskChanged();
303
304private Q_SLOTS:
305 void doUpdate();
306
307private:
308 void updateDevicePixelRatio();
309 void applyPrefixes();
310
311 KSvg::FrameSvg *m_frameSvg;
312 Kirigami::Platform::PlatformTheme *m_kirigamiTheme;
313 FrameSvgItemMargins *m_margins;
314 FrameSvgItemMargins *m_fixedMargins;
315 FrameSvgItemMargins *m_insetMargins;
316 // logged margins to check for changes
317 QList<qreal> m_oldMargins;
318 QList<qreal> m_oldFixedMargins;
319 QList<qreal> m_oldInsetMargins;
320 QStringList m_prefixes;
321 bool m_textureChanged;
322 bool m_sizeChanged;
323 bool m_fastPath;
324};
325
326}
327
328#endif
The sizes of a frame's margins.
QList< qreal > margins() const
returns a vector with left, top, right, bottom
qreal vertical
This property holds the combined width of the top and bottom margins.
qreal top
This property holds the top margin's width in pixels.
qreal left
This property holds the left margin's width in pixels.
qreal horizontal
This property holds the combined width of the left and right margins.
qreal bottom
This property holds the bottom margin's width in pixels.
qreal right
This property holds the right margin's width in pixels.
An SVG Item with borders.
Provides an SVG with borders.
Definition framesvg.h:61
A theme aware image-centric SVG class.
Definition svg.h:46
Q_SCRIPTABLE CaptureState status()
The KSvg namespace.
Q_INTERFACES(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.