Kirigami2

IconTitleSubtitle.qml
1/*
2 * SPDX-FileCopyrightText: 2010 Marco Martin <notmart@gmail.com>
3 * SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk>
4 * SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9import QtQuick
10import org.kde.kirigami as Kirigami
11import org.kde.kirigami.delegates as KD
12import org.kde.kirigami.templates.private as KTP
13
14/**
15 * A simple item containing an icon, title and subtitle.
16 *
17 * This is an extension of TitleSubtitle that adds an icon to the side.
18 * It is intended as a contentItem for ItemDelegate and related controls.
19 *
20 * When using it as a contentItem, make sure to bind the appropriate properties
21 * to those of the Control. Prefer binding to the Control's properties over
22 * setting the properties directly, as the Control's properties may affect other
23 * things like setting accessible names.
24 *
25 * This (and TitleSubtitle) can be combined with other controls in a layout to
26 * create complex content items for controls.
27 *
28 * Example usage creating a CheckDelegate with an extra button on the side:
29 *
30 * ```qml
31 * CheckDelegate {
32 * id: delegate
33 *
34 * text: "Example"
35 * icon.name: "document-new"
36 *
37 * contentItem: RowLayout {
38 * spacing: Kirigami.Theme.smallSpacing
39 *
40 * Kirigami.IconTitleSubtitle {
41 * Layout.fillWidth: true
42 *
43 * icon: icon.fromControlsIcon(delegate.icon)
44 * title: delegate.text
45 * selected: delegate.highlighted || delegate.down
46 * font: delegate.font
47 * }
48 *
49 * Button {
50 * icon.name: "document-open"
51 * text: "Extra Action"
52 * }
53 * }
54 * }
55 * ```
56 *
57 * \sa Kirigami::Delegates::TitleSubtitle
58 * \sa Kirigami::Delegates::ItemDelegate
59 */
60Item {
61 id: root
62
63 /**
64 * @copydoc Kirigami::TitleSubtitle::title
65 */
66 required property string title
67 /**
68 * @copydoc Kirigami::TitleSubtitle::subtitle
69 */
70 property alias subtitle: titleSubtitle.subtitle
71 /**
72 * @copydoc Kirigami::TitleSubtitle::color
73 */
74 property alias color: titleSubtitle.color
75 /**
76 * @copydoc Kirigami::TitleSubtitle::subtitleColor
77 */
78 property alias subtitleColor: titleSubtitle.subtitleColor
79 /**
80 * @copydoc Kirigami::TitleSubtitle::font
81 */
82 property alias font: titleSubtitle.font
83 /**
84 * @copydoc Kirigami::TitleSubtitle::subtitleFont
85 */
86 property alias subtitleFont: titleSubtitle.subtitleFont
87 /**
88 * @copydoc Kirigami::TitleSubtitle::reserveSpaceForSubtitle
89 */
90 property alias reserveSpaceForSubtitle: titleSubtitle.reserveSpaceForSubtitle
91 /**
92 * @copydoc Kirigami::TitleSubtitle::selected
93 */
94 property alias selected: titleSubtitle.selected
95 /**
96 * @copydoc Kirigami::TitleSubtitle::elide
97 */
98 property alias elide: titleSubtitle.elide
99 /**
100 * @copydoc Kirigami::TitleSubtitle::wrapMode
101 */
102 property alias wrapMode: titleSubtitle.wrapMode
103 /**
104 * @copydoc Kirigami::TitleSubtitle::truncated
105 */
106 property alias truncated: titleSubtitle.truncated
107
108 /**
109 * Grouped property for icon properties.
111 * \note By default, IconTitleSubtitle will reserve the space for the icon,
112 * even if it is not set. To remove that space, set `icon.width` to 0.
113 */
114 property KTP.IconPropertiesGroup icon: KTP.IconPropertiesGroup {
115 width: titleSubtitle.subtitleVisible ? Kirigami.Units.iconSizes.medium : Kirigami.Units.iconSizes.smallMedium
116 height: width
117 }
118
119 implicitWidth: iconItem.implicitWidth + titleSubtitle.anchors.leftMargin + titleSubtitle.implicitWidth
120 implicitHeight: Math.max(iconItem.implicitHeight, titleSubtitle.implicitHeight)
121
122 Kirigami.Icon {
123 id: iconItem
124
125 anchors {
126 left: parent.left
127 top: parent.top
128 bottom: parent.bottom
129 }
130
131 source: root.icon.name.length > 0 ? root.icon.name : root.icon.source
132 implicitWidth: root.icon.width
133 implicitHeight: root.icon.height
134 selected: root.selected
135 color: root.icon.color
136 }
137
138 KD.TitleSubtitle {
139 id: titleSubtitle
140
141 anchors {
142 left: iconItem.right
143 leftMargin: root.icon.width > 0 ? Kirigami.Units.mediumSpacing : 0
144 top: parent.top
145 bottom: parent.bottom
146 right: parent.right
147 }
148
149 title: root.title
150 }
151}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.