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.platform as Platform
11import org.kde.kirigami.primitives as Primitives
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 ? Platform.Units.iconSizes.medium : Platform.Units.iconSizes.smallMedium
116 height: width
117 }
119 /**
120 * @copydoc Kirigami::TitleSubtitle::linkActivated
121 */
122 signal linkActivated(string link)
123
124 /**
125 * @copydoc Kirigami::TitleSubtitle::linkHovered
126 */
127 signal linkHovered(string link)
128
129 implicitWidth: iconItem.implicitWidth + titleSubtitle.anchors.leftMargin + titleSubtitle.implicitWidth
130 implicitHeight: Math.max(iconItem.implicitHeight, titleSubtitle.implicitHeight)
131
132 Primitives.Icon {
133 id: iconItem
134
135 anchors {
136 left: parent.left
137 top: parent.top
138 bottom: parent.bottom
139 }
140
141 source: root.icon.name.length > 0 ? root.icon.name : root.icon.source
142 implicitWidth: root.icon.width
143 implicitHeight: root.icon.height
144 selected: root.selected
145 color: root.icon.color
146 }
147
148 TitleSubtitle {
149 id: titleSubtitle
150
151 anchors {
152 left: iconItem.right
153 leftMargin: root.icon.width > 0 ? Platform.Units.mediumSpacing : 0
154 top: parent.top
155 bottom: parent.bottom
156 right: parent.right
157 }
158
159 title: root.title
160
161 onLinkActivated: link => root.linkActivated(link)
162 onLinkHovered: link => root.linkHovered(link)
163 }
164}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.