Kirigami2

Heading.qml
1 /*
2  * SPDX-FileCopyrightText: 2012 by Sebastian K├╝gler <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.0
8 import QtQuick.Controls 2.0 as QQC2
9 import org.kde.kirigami 2.4 as Kirigami
10 
11 /**
12  * @brief A heading label used for subsections of texts.
13  *
14  * The characteristics of the text will be automatically set according to the
15  * Kirigami.Theme. Use this components for section titles or headings in your UI,
16  * for example page or section titles.
17  *
18  * Example usage:
19  * @code
20  * import org.kde.kirigami 2.4 as Kirigami
21  * [...]
22  * Column {
23  * Kirigami.Heading {
24  * text: "Apples in the sunlight"
25  * level: 2
26  * }
27  * [...]
28  * }
29  * @endcode
30  *
31  * The most important property is "text", which applies to the text property of
32  * Label. See the Label component from QtQuick.Controls 2 and primitive QML Text
33  * element API for additional properties, methods and signals.
34  *
35  * @inherit QtQuick.Controls.Label
36  */
37 QQC2.Label {
38  id: heading
39 
40  /**
41  * @brief This property holds the level of the heading, which determines its size.
42  *
43  * This property holds the level, which determines how large the header is.
44  *
45  * Acceptable values range from 1 (big) to 5 (small).
46  *
47  * default: ``1``
48  */
49  property int level: 1
50 
51  /**
52  * @brief This property holds the point size between heading levels.
53  *
54  * default: ``0``
55  *
56  * @deprecated
57  */
58  property int step: 0
59 
60  /**
61  * @brief This enumeration defines heading types.
62  *
63  * This enum helps with heading visibility (making it less or more important).
64  */
65  enum Type {
66  Normal,
67  Primary,
68  Secondary
69  }
70 
71  /**
72  * @brief This property holds the heading type.
73  *
74  * The type of the heading. This can be:
75  * * ``Kirigami.Heading.Type.Normal``: Create a normal heading (default)
76  * * ``Kirigami.Heading.Type.Primary``: Makes the heading more prominent. Useful
77  * when making the heading bigger is not enough.
78  * * ``Kirigami.Heading.Type.Secondary``: Makes the heading less prominent.
79  * Useful when an heading is for a less important section in an application.
80  *
81  * @property Heading::Type type
82  * @since 5.82
83  */
84  property int type: Kirigami.Heading.Type.Normal
85 
86  font.pointSize: __headerPointSize(level)
87  font.weight: type === Kirigami.Heading.Type.Primary ? Font.DemiBold : Font.Normal
88 
89  opacity: type === Kirigami.Heading.Type.Secondary ? 0.7 : 1
90 
91  Accessible.role: Accessible.Heading
92 
93  // TODO KF6: Remove this public method
94  function headerPointSize(l) {
95  console.warn("org.kde.plasma.extras/Heading::headerPointSize() is deprecated. Use font.pointSize directly instead");
96  return __headerPointSize(l);
97  }
98 
99  //
100  // W A R N I N G
101  // -------------
102  //
103  // This method is not part of the Kirigami API. It exists purely as an
104  // implementation detail. It may change from version to
105  // version without notice, or even be removed.
106  //
107  // We mean it.
108  //
109  function __headerPointSize(level) {
110  const n = Kirigami.Theme.defaultFont.pointSize;
111  switch (level) {
112  case 1:
113  return n * 1.35 + step;
114  case 2:
115  return n * 1.20 + step;
116  case 3:
117  return n * 1.15 + step;
118  case 4:
119  return n * 1.10 + step;
120  default:
121  return n + step;
122  }
123  }
124 }
Type
This enumeration defines heading types.
Definition: Heading.qml:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.