2
* Copyright 2011 Intel Corporation.
4
* This program is licensed under the terms and conditions of the
5
* LGPL, version 2.1. The full text of the LGPL License is at
6
* http://www.gnu.org/licenses/lgpl.html
10
\qmlclass ExpandingBox
12
\section1 ExpandingBox
13
This is a box which can be given any content and adapts its size accordingly.
14
The default state of the box only show a header line and an icon which
15
indicates if the box is expanded or not. Clicking on the header expands the
16
box and shows the content.
18
The behaviour isn't final because detailed specifications are missing.
20
\section2 API properties
21
\qmlproperty bool expanded
22
\qmlcm true if the box is currently expanded
24
\qmlproperty Row iconRow
25
\qmlcm area that can hold a set of icons
27
\qmlproperty string titleText
28
\qmlcm sets the text shown on the header
30
\qmlproperty color titleTextColor
31
\qmlcm sets the color of the text shown on the header
33
\qmlproperty Component detailsComponent
34
\qmlcm contains the content to be shown when the box is expanded
36
\qmlproperty Item detailsItem
37
\qmlcm stores the contents when created
39
\qmlproperty int buttonHeight
40
\qmlcm this defines how big the Expanding box is when it's not extended. If you change the orientation and the size, you have to set these too.
42
\qmlproperty int buttonWidth
43
\qmlcm this defines how big the Expanding box is when it's not extended. If you change the orientation and the size, you have to set these too.
45
\qmlproperty Item headerContent
46
\qmlcm this Item will appear in the header. It can be used to create complex custom headers.
48
\qmlproperty string orientation
49
\qmlcm this value defines how ExpandingBox is orientated. Possible values are: "horizontal" - expands to lower; "vertical" - expands to the right. Default is 'horizontal'.
50
If you change the orientation and the size during runtime, make sure you change the buttonWidth and buttonHeight too.
52
\qmlproperty bool lazyCreation
53
\qmlcm this value defines how ExpandingBox is created. By default (false), content to expand is created when the ExpandingBox is first instantiated. Setting this property to true delays content created if and until the box is expanded.
56
\qmlproperty [signal] expandingChanged
57
\qmlcm emitted if the box switches between expanded and not expanded
59
\qmlpcm indicates if the box is expanded or not \endparam
71
titleText: "ExpandingBox"
72
titleTextColor: "black"
73
anchors.centerIn: parent
74
detailsComponent: expandingBoxComponent
77
id: expandingBoxComponent
83
height: 50; width: 150
84
anchors.centerIn: parent
87
text: "Switch" // switches orientation to vertical
89
expandingBox.width = 75
90
expandingBox.height = 200
91
expandingBox.buttonWidth = 75
92
expandingBox.buttonHeight = 200
93
expandingBox.orientation = "vertical" // this has to be last, since it triggers the changes
103
import MeeGo.Ux.Kernel 0.1
104
import MeeGo.Ux.Components.Common 0.1
105
import org.kde.plasma.core 0.1 as PlasmaCore
106
import org.kde.plasma.components 0.1 as PlasmaComponents
108
PlasmaComponents.ListItem {
113
onClicked: expanded = !expanded
115
property bool expanded: false
116
property alias titleText: titleText.text
117
property alias titleTextColor: titleText.color
118
property Component detailsComponent: null
119
property Item detailsItem: null
120
property alias iconRow: iconArea.children
121
property int buttonHeight: 13
122
property int buttonWidth: 13
123
property alias headerContent: headerContentArea.children
124
property string orientation: "horizontal"
125
property bool lazyCreation: false
127
signal expandingChanged( bool expanded )
130
height: 45// + ( ( titleText.font.pixelSize > expandButton.height ) ? titleText.font.pixelSize : expandButton.height )
133
// if new content is set, destroy any old content and create the new one
134
onDetailsComponentChanged: {
136
detailsItem.destroy()
139
if (expanded || !lazyCreation) {
140
//console.log("Creating expanding box!")
141
detailsItem = detailsComponent.createObject( boxDetailsArea )
143
pulldownImage.componentCompleted = true
146
// if content has been set, destroy any old content and create the new one
147
Component.onCompleted: {
148
buttonHeight = height
150
pulldownImage.boxReady = true
151
if( !lazyCreation && detailsComponent && !pulldownImage.componentCompleted ) {
152
if ( detailsItem ) detailsItem.destroy()
153
detailsItem = detailsComponent.boxDetailsArea( boxDetailsArea )
157
// if the expanded state changes, propagate the change via signal
161
//console.log("Creating expanding box!")
162
detailsItem = detailsComponent.createObject( boxDetailsArea )
165
expandingBox.expandingChanged( expanded )
171
property bool componentCompleted: false
172
property int animationTime: 200
173
property bool boxReady: false
176
height: expandingBox.height
177
width: expandingBox.width
180
// the header item contains the title, the image for the button which indicates
181
// the expanded state and a GestreuArea to change the expanded state on click
185
// the header adapts its height to the height of the title and the button plus some space
186
height: ( expandingBox.orientation == "horizontal" ) ? buttonHeight : parent.height
187
width: ( expandingBox.orientation == "horizontal" ) ? parent.width : buttonWidth
189
anchors.top: parent.top
194
anchors { left: parent.left; margins: 5 }
195
anchors.verticalCenter: expandButton.verticalCenter
196
spacing: anchors.margins
199
PlasmaComponents.Label {
202
elide: Text.ElideRight
203
anchors.left: iconArea.right
204
anchors.right: expandButton.left
205
anchors.leftMargin: 10
206
anchors.verticalCenter: expandButton.verticalCenter
210
id: headerContentArea
215
width: ( expandingBox.orientation == "horizontal" ) ? expandingBox.width - expandButton.width - 6 * 2 - 10 : parent.width - 10
216
height: ( expandingBox.orientation == "horizontal" ) ? parent.height -10 : expandingBox.height - expandButton.height - 6 * 2 - 10
225
x: ( expandingBox.orientation == "horizontal" ) ? expandingBox.width - width - 6 : (header.width - width) / 2
226
y: ( expandingBox.orientation == "horizontal" ) ? (header.height - height) / 2 : expandingBox.height - height - 6
228
svg: PlasmaCore.Svg {
229
imagePath: "widgets/arrows"
231
width: naturalSize.width
232
height: naturalSize.height
233
elementId: expandingBox.expanded ? "up-arrow" : "down-arrow"
237
// this item is used when creating the content in the detailsItem to set some general properties
241
property int itemMargins: 3
245
visible: expandingBox.expanded
247
top: ( expandingBox.orientation == "horizontal" ) ? header.bottom : parent.top
248
left: ( expandingBox.orientation == "horizontal" ) ? parent.left : header.right
249
bottom: parent.bottom
256
onOrientationChanged: {
257
if(!pulldownImage.boxReady)
260
var oldExpanded = expanded
261
pulldownImage.animationTime = 0
263
height = buttonHeight
265
expanded = oldExpanded
266
pulldownImage.animationTime = 200
275
height: buttonHeight + detailsItem.height + boxDetailsArea.itemMargins * 2
279
target: boxDetailsArea
284
when: { expandingBox.expanded && expandingBox.orientation == "horizontal" }
288
name: "expandedVertical"
292
width: buttonWidth + detailsItem.width + boxDetailsArea.itemMargins * 2
296
target: boxDetailsArea
301
when: { expandingBox.expanded && expandingBox.orientation == "vertical" }
307
SequentialAnimation {
311
duration: pulldownImage.animationTime
312
easing.type: Easing.InCubic
316
duration: pulldownImage.animationTime
317
easing.type: Easing.InCubic
321
properties: "opacity"
322
duration: pulldownImage.animationTime
323
easing.type: Easing.OutCubic