MauiKit Controls

Badge.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21import QtQuick.Controls
22
23import org.mauikit.controls 1.3 as Maui
24
25/**
26 * @inherit QtQuick.Controls.Control
27 * @since org.mauikit.controls 1.0
28 * @brief A Badge item to display text - as a counter - or an icon as a notification hint.
29 *
30 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-control.html">This controls inherits from QQC2 Control, to checkout its inherited properties refer to the Qt Docs.</a>
31 *
32 * @image html Badge/badges.png "Badges with different sizes and colors"
33 *
34 * @code
35 * Button
36 * {
37 * text: "Example1"
38 *
39 * Maui.Badge
40 * {
41 * icon.name: "actor"
42 * color: Maui.Theme.neutralBackgroundColor
43 * anchors.horizontalCenter: parent.right
44 * anchors.verticalCenter: parent.top
45 * }
46 * }
47 * @endcode
48 *
49 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/Badge.qml">You can find a more complete example at this link.</a>
50 *
51 */
52Control
53{
54 id: control
55
56 Maui.Theme.inherit: false
57 Maui.Theme.colorSet: Maui.Theme.Complementary
59 /**
60 * @brief Size of the badge. Used as width and height, unless the `implicitWidth` is wider.
61 * It is also used as the icon size doimentions.
62 * By default is set to `Style.iconSizes.small`
63 */
64 property int size: Maui.Style.iconSizes.small
65
66 /**
67 * @brief The icon group property. Exposed to define the icon name, color, and width and height.
68 * To know more about it you can check the QQC2 icon property.
69 */
70 property alias icon : _dummyButton.icon
71
72 /**
73 * @brief The text to be used in the label.
74 * Consider using short text, as this is meant to work as a notification hint.
75 */
76 property alias text : _dummyButton.text
77
78 /**
79 * @brief The color for the background of the badge
80 */
81 property color color: Maui.Theme.backgroundColor
82
83 font.weight: Font.Bold
84 font.bold: true
85 font.pointSize: Maui.Style.fontSizes.small
86
87 implicitWidth: implicitContentWidth + leftPadding + rightPadding
88 implicitHeight: implicitContentHeight + topPadding + bottomPadding
89
90 padding: Maui.Style.space.tiny
91
92 AbstractButton
93 {
94 id: _dummyButton
95 visible: false
96 icon.color: Maui.Theme.textColor
97 icon.width: size
98 icon.height: size
99 }
100
101 background: Rectangle
102 {
103 radius: Math.min(width, height)
104 color: control.color
105 border.color: Qt.lighter(control.color)
106
107 Behavior on color
108 {
109 Maui.ColorTransition{}
110 }
111 }
112
113 contentItem: Maui.IconLabel
114 {
115 text: control.text
116 font: control.font
117 icon: control.icon
118 color: control.icon.color
119 spacing: control.spacing
120 alignment: Qt.AlignHCenter
121 }
122}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.