Debian Codegraph @

src/imports/Components/ListItems/2.0/SingleControl.qml

raw
1 /*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components
19 import Lomiri.Components.ListItems
20
21 /*!
22 \qmltype SingleControl
23 \inqmlmodule Lomiri.Components.ListItems 1.0
24 \ingroup lomiri-listitems
25 \brief A list item containing a single control
26 \note \b{The component is deprecated. Use ListItem component instead.}
27
28 Examples:
29 \qml
30 import Lomiri.Components
31 import Lomiri.Components.ListItems as ListItem
32 Column {
33 ListItem.SingleControl {
34 control: Button {
35 anchors {
36 margins: units.gu(1)
37 fill: parent
38 }
39 text: "Large button"
40 }
41 }
42 }
43 \endqml
44 */
45 // TODO: Add more examples when more types of controls become available.
46 Empty {
47 id: singleControlListItem
48
49 /*!
50 The control of this SingleControl list item.
51 The control will automatically be re-parented to, and centered in, this list item.
52 */
53 property Item control
54
55 /*! \internal */
56 onClicked: if (control && control.enabled && control.hasOwnProperty("clicked")) control.clicked()
57 /*! \internal */
58 property bool pressed: __mouseArea.pressed || (control && control.hasOwnProperty("pressed") && control.pressed)
59 /*! \internal */
60 onPressedChanged: if (control && control.enabled && control.hasOwnProperty("pressed")) control.pressed = singleControlListItem.pressed
61
62 // Ensure that there is always enough vertical padding around the control
63 __height: control.height + __contentsMargins
64
65 /*!
66 \internal
67 */
68 function __updateControl() {
69 if (control) {
70 control.parent = __contents;
71 control.anchors.centerIn = __contents;
72 }
73 }
74
75 /*!
76 \internal
77 This handler is an implementation detail. Mark as internal to prevent QDoc publishing it
78 */
79 onControlChanged: __updateControl()
80 }