Libplasma

Heading.qml
1/*
2 SPDX-FileCopyrightText: 2012 Sebastian Kügler <sebas@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import org.kde.plasma.components
9import org.kde.kirigami as Kirigami
10
11/**
12 * A heading label used for subsections of texts.
13 *
14 * The characteristics of the text will be automatically set according to the
15 * plasma theme. Use this components for section titles or headings in your UI,
16 * for example page or section titles.
17 *
18 * Example usage:
19 *
20 * @code
21 * import org.kde.plasma.components as PlasmaComponents3
22 * import org.kde.plasma.extras as PlasmaExtras
23 * [...]
24 * Column {
25 * PlasmaExtras.Heading { text: "Fruit sweetness on the rise"; level: 1 }
26 * PlasmaExtras.Heading { text: "Apples in the sunlight"; level: 2 }
27 * PlasmaComponents3.Label { text: "Long text about fruit and apples [...]" }
28 * [...]
29 * }
30 * @endcode
31 *
32 * The most important property is "text", which applies to the text property of
33 * Label. See PlasmaComponents Label and primitive QML Text element API for
34 * additional properties, methods and signals.
35 */
36Label {
37 id: heading
38
39 /**
40 * The level determines how big the section header is display, values
41 * between 1 (big) and 5 (small) are accepted. (default: 1)
42 */
43 property int level: 1
44
45 enum Type {
46 Normal,
47 Primary,
48 Secondary
49 }
50
51 /**
52 * The type of the heading. This can be:
53 *
54 * * PlasmaExtras.Heading.Type.Normal: Create a normal heading (default)
55 * * PlasmaExtras.Heading.Type.Primary: Makes the heading more prominent. Useful
56 * when making the heading bigger is not enough.
57 * * PlasmaExtras.Heading.Type.Secondary: Makes the heading less prominent.
58 * Useful when an heading is for a less important section in an application.
59 *
60 * @since 5.88
61 */
62 property int type: Heading.Type.Normal
63
64 font.pointSize: __headerPointSize(level)
65 font.weight: type === Heading.Type.Primary ? Font.DemiBold : Font.Normal
66 wrapMode: Text.WordWrap
67
68 opacity: type === Heading.Type.Secondary ? 0.7 : 1
69
70 Accessible.role: Accessible.Heading
71
72 //
73 // W A R N I N G
74 // -------------
75 //
76 // This method is not part of the PlasmaExtras API. It exists purely as an
77 // implementation detail. It may change from version to
78 // version without notice, or even be removed.
79 //
80 // We mean it.
81 //
82 function __headerPointSize(level) {
83 const n = Kirigami.Theme.defaultFont.pointSize;
84 switch (level) {
85 case 1:
86 return n * 1.35;
87 case 2:
88 return n * 1.20;
89 case 3:
90 return n * 1.15;
91 case 4:
92 return n * 1.10;
93 default:
94 return n;
95 }
96 }
97}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.