Kirigami2

units.h
1/*
2 * SPDX-FileCopyrightText: 2021 Jonah BrĂ¼chert <jbb@kaidan.im>
3 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#ifndef KIRIGAMI_UNITS_H
9#define KIRIGAMI_UNITS_H
10
11#include <memory>
12
13#include <QObject>
14#include <QQmlEngine>
15
16#include "kirigamiplatform_export.h"
17
18class QQmlEngine;
19
20namespace Kirigami
21{
22namespace Platform
23{
24class Units;
25class UnitsPrivate;
26
27/**
28 * @class IconSizes units.h <Kirigami/Units>
29 *
30 * Provides access to platform-dependent icon sizing
31 */
32class KIRIGAMIPLATFORM_EXPORT IconSizes : public QObject
33{
34 Q_OBJECT
35 QML_ELEMENT
36 QML_UNCREATABLE("Grouped Property")
37
38 Q_PROPERTY(int sizeForLabels READ sizeForLabels NOTIFY sizeForLabelsChanged FINAL)
39 Q_PROPERTY(int small READ small NOTIFY smallChanged FINAL)
40 Q_PROPERTY(int smallMedium READ smallMedium NOTIFY smallMediumChanged FINAL)
41 Q_PROPERTY(int medium READ medium NOTIFY mediumChanged FINAL)
42 Q_PROPERTY(int large READ large NOTIFY largeChanged FINAL)
43 Q_PROPERTY(int huge READ huge NOTIFY hugeChanged FINAL)
44 Q_PROPERTY(int enormous READ enormous NOTIFY enormousChanged FINAL)
45
46public:
47 IconSizes(Units *units);
48
49 int sizeForLabels() const;
50 int small() const;
51 int smallMedium() const;
52 int medium() const;
53 int large() const;
54 int huge() const;
55 int enormous() const;
56
57 Q_INVOKABLE int roundedIconSize(int size) const;
58
59private:
60 KIRIGAMIPLATFORM_NO_EXPORT float iconScaleFactor() const;
61
62 Units *m_units;
63
64Q_SIGNALS:
65 void sizeForLabelsChanged();
66 void smallChanged();
67 void smallMediumChanged();
68 void mediumChanged();
69 void largeChanged();
70 void hugeChanged();
71 void enormousChanged();
72};
73
74/**
75 * @class Units units.h <Kirigami/Units>
76 *
77 * A set of values to define semantically sizes and durations.
78 */
79class KIRIGAMIPLATFORM_EXPORT Units : public QObject
80{
81 Q_OBJECT
82 QML_ELEMENT
83 QML_SINGLETON
84
85 friend class IconSizes;
86
87 /**
88 * The fundamental unit of space that should be used for sizes, expressed in pixels.
89 */
90 Q_PROPERTY(int gridUnit READ gridUnit NOTIFY gridUnitChanged FINAL)
91
92 /**
93 * units.iconSizes provides access to platform-dependent icon sizing
94 *
95 * The icon sizes provided are normalized for different DPI, so icons
96 * will scale depending on the DPI.
97 *
98 * * sizeForLabels (the largest icon size that fits within fontMetrics.height) @since 5.80 @since org.kde.kirigami 2.16
99 * * small
100 * * smallMedium
101 * * medium
102 * * large
103 * * huge
104 * * enormous
105 */
106 Q_PROPERTY(Kirigami::Platform::IconSizes *iconSizes READ iconSizes CONSTANT FINAL)
107
108 /**
109 * This property holds the amount of spacing that should be used between smaller UI elements,
110 * such as a small icon and a label in a button.
111 */
112 Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY smallSpacingChanged FINAL)
113
114 /**
115 * This property holds the amount of spacing that should be used between medium UI elements,
116 * such as buttons and text fields in a toolbar.
117 */
118 Q_PROPERTY(int mediumSpacing READ mediumSpacing NOTIFY mediumSpacingChanged FINAL)
119
120 /**
121 * This property holds the amount of spacing that should be used between bigger UI elements,
122 * such as a large icon and a heading in a card.
123 */
124 Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY largeSpacingChanged FINAL)
125
126 /**
127 * units.veryLongDuration should be used for specialty animations that benefit
128 * from being even longer than longDuration.
129 */
130 Q_PROPERTY(int veryLongDuration READ veryLongDuration NOTIFY veryLongDurationChanged FINAL)
131
132 /**
133 * units.longDuration should be used for longer, screen-covering animations, for opening and
134 * closing of dialogs and other "not too small" animations
135 */
136 Q_PROPERTY(int longDuration READ longDuration NOTIFY longDurationChanged FINAL)
137
138 /**
139 * units.shortDuration should be used for short animations, such as accentuating a UI event,
140 * hover events, etc..
141 */
142 Q_PROPERTY(int shortDuration READ shortDuration NOTIFY shortDurationChanged FINAL)
143
144 /**
145 * units.veryShortDuration should be used for elements that should have a hint of smoothness,
146 * but otherwise animate near instantly.
147 */
148 Q_PROPERTY(int veryShortDuration READ veryShortDuration NOTIFY veryShortDurationChanged FINAL)
149
150 /**
151 * Time in milliseconds equivalent to the theoretical human moment, which can be used
152 * to determine whether how long to wait until the user should be informed of something,
153 * or can be used as the limit for how long something should wait before being
154 * automatically initiated.
155 *
156 * Some examples:
157 *
158 * - When the user types text in a search field, wait no longer than this duration after
159 * the user completes typing before starting the search
160 * - When loading data which would commonly arrive rapidly enough to not require interaction,
161 * wait this long before showing a spinner
162 *
163 * This might seem an arbitrary number, but given the psychological effect that three
164 * seconds seems to be what humans consider a moment (and in the case of waiting for
165 * something to happen, a moment is that time when you think "this is taking a bit long,
166 * isn't it?"), the idea is to postpone for just before such a conceptual moment. The reason
167 * for the two seconds, rather than three, is to function as a middle ground: Not long enough
168 * that the user would think that something has taken too long, for also not so fast as to
169 * happen too soon.
170 *
171 * See also
172 * https://www.psychologytoday.com/blog/all-about-addiction/201101/tick-tock-tick-hugs-and-life-in-3-second-intervals
173 * (the actual paper is hidden behind an academic paywall and consequently not readily
174 * available to us, so the source will have to be the blog entry above)
175 *
176 * \note This should __not__ be used as an animation duration, as it is deliberately not scaled according
177 * to the animation settings. This is specifically for determining when something has taken too long and
178 * the user should expect some kind of feedback. See veryShortDuration, shortDuration, longDuration, and
179 * veryLongDuration for animation duration choices.
180 *
181 * @since 5.81
182 * @since org.kde.kirigami 2.16
183 */
184 Q_PROPERTY(int humanMoment READ humanMoment NOTIFY humanMomentChanged FINAL)
185
186 /**
187 * time in ms by which the display of tooltips will be delayed.
188 *
189 * @sa ToolTip.delay property
190 */
191 Q_PROPERTY(int toolTipDelay READ toolTipDelay NOTIFY toolTipDelayChanged FINAL)
192
193 /**
194 * Corner radius value shared by buttons and other rectangle elements
195 *
196 * @since 6.2
197 */
198 Q_PROPERTY(qreal cornerRadius READ cornerRadius NOTIFY cornerRadiusChanged FINAL)
199
200public:
201 ~Units() override;
202
203 int gridUnit() const;
204 void setGridUnit(int size);
205
206 int smallSpacing() const;
207 void setSmallSpacing(int size);
208
209 int mediumSpacing() const;
210 void setMediumSpacing(int size);
211
212 int largeSpacing() const;
213 void setLargeSpacing(int size);
214
215 int veryLongDuration() const;
216 void setVeryLongDuration(int duration);
217
218 int longDuration() const;
219 void setLongDuration(int duration);
220
221 int shortDuration() const;
222 void setShortDuration(int duration);
223
224 int veryShortDuration() const;
225 void setVeryShortDuration(int duration);
226
227 int humanMoment() const;
228 void setHumanMoment(int duration);
229
230 int toolTipDelay() const;
231 void setToolTipDelay(int delay);
232
233 qreal cornerRadius() const;
234 void setcornerRadius(qreal cornerRadius);
235
236 IconSizes *iconSizes() const;
237
238 static Units *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine);
239
240Q_SIGNALS:
241 void gridUnitChanged();
242 void smallSpacingChanged();
243 void mediumSpacingChanged();
244 void largeSpacingChanged();
245 void veryLongDurationChanged();
246 void longDurationChanged();
247 void shortDurationChanged();
248 void veryShortDurationChanged();
249 void humanMomentChanged();
250 void toolTipDelayChanged();
251 void wheelScrollLinesChanged();
252 void cornerRadiusChanged();
253
254protected:
255 explicit Units(QObject *parent = nullptr);
256 bool eventFilter(QObject *watched, QEvent *event) override;
257
258private:
259 std::unique_ptr<UnitsPrivate> d;
260};
261
262}
263}
264
265#endif
Provides access to platform-dependent icon sizing.
Definition units.h:33
A set of values to define semantically sizes and durations.
Definition units.h:80
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:51:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.