plasma-framework/declarativeimports/plasmacomponents/qml/ToolBarLayout.qml

78 lines
2.0 KiB
QML
Raw Normal View History

2011-11-09 16:10:36 +01:00
/*
* Copyright (C) 2011 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2011-11-08 21:10:30 +01:00
// ToolBarLayout is a container for items on a toolbar that automatically
// implements an appropriate layout for its children.
2012-01-10 21:39:18 +01:00
/**Documented API
Inherits:
Row
Imports:
QtQuick 1.1
Description:
ToolBarLayout is a container for items on a toolbar that automatically implements an appropriate layout for its children.
**/
2011-11-08 21:10:30 +01:00
import QtQuick 1.1
import "." 0.1
2011-11-09 16:10:36 +01:00
Row {
id: root
2011-11-08 21:10:30 +01:00
visible: false
2011-11-09 16:10:36 +01:00
Item {
id: spacer
width: 10
height: 10
2011-11-08 21:10:30 +01:00
}
QtObject {
id: internal
2011-11-09 16:10:36 +01:00
property bool layouting: false
function layoutChildren()
{
var numChildren = root.children.length
if (layouting || parent == null ||
root.width == 0 || numChildren < 2) {
2011-11-08 21:10:30 +01:00
return
}
2011-11-09 16:10:36 +01:00
layouting = true
spacer.parent = null
2011-11-08 21:10:30 +01:00
spacer.width = root.parent.width - root.childrenRect.width -10
2011-11-08 21:10:30 +01:00
2011-11-09 16:10:36 +01:00
var last = root.children[numChildren-2]
last.parent = null
spacer.parent = root
last.parent = root
layouting = false
2011-11-08 21:10:30 +01:00
}
}
Component.onCompleted: internal.layoutChildren()
onChildrenChanged: internal.layoutChildren()
2011-11-09 16:10:36 +01:00
onWidthChanged: internal.layoutChildren()
2011-11-08 21:10:30 +01:00
}