plasma-framework/declarativeimports/plasmacomponents/platformcomponents/touch/Menu.qml

146 lines
4.0 KiB
QML
Raw Normal View History

2011-11-08 23:00:38 +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.
*/
import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
import "." 0.1
Item {
id: root
2012-01-02 15:31:19 +01:00
default property alias content: menuColumn.children
2011-11-08 23:00:38 +01:00
property Item visualParent
property int status: DialogStatus.Closed
2012-01-02 15:58:11 +01:00
onVisualParentChanged: {
//if is a menuitem move to menuColumn
if (visualParent.separator !== undefined) {
var obj = arrowComponent.createObject(visualParent)
}
}
Component {
id: arrowComponent
PlasmaCore.SvgItem {
svg: PlasmaCore.Svg {imagePath: "widgets/arrows"}
elementId: "right-arrow"
width: naturalSize.width
height: naturalSize.height
anchors {
right: parent.right
verticalCenter: parent.verticalCenter
}
}
}
2011-11-08 23:00:38 +01:00
function open()
{
var parent = root.visualParent ? root.visualParent : root.parent
var pos = dialog.popupPosition(parent, Qt.alignCenter)
dialog.x = pos.x
dialog.y = pos.y
dialog.visible = true
2011-11-16 21:11:58 +01:00
dialog.activateWindow()
2011-11-08 23:00:38 +01:00
}
function close()
{
dialog.visible = false
}
2012-01-02 15:17:37 +01:00
function addMenuItem(item)
{
2012-01-02 15:31:19 +01:00
item.parent = menuColumn
2012-01-02 15:17:37 +01:00
}
onChildrenChanged: {
for (var i = 0; i < children.length; ++i) {
var item = children[i]
2012-01-02 15:58:11 +01:00
//if is a menuitem move to menuColumn
2012-01-02 15:17:37 +01:00
if (item.separator !== undefined) {
2012-01-02 15:31:19 +01:00
item.parent = menuColumn
2012-01-02 15:17:37 +01:00
}
}
}
2011-11-08 23:00:38 +01:00
visible: false
PlasmaCore.Dialog {
id: dialog
visible: false
windowFlags: Qt.Popup
onVisibleChanged: {
if (visible) {
status = DialogStatus.Open
} else {
status = DialogStatus.Closed
}
}
mainItem: Item {
id: contentItem
2012-01-02 15:31:19 +01:00
width: Math.max(menuColumn.width, theme.defaultFont.mSize.width * 12)
height: Math.min(menuColumn.height, theme.defaultFont.mSize.height * 25)
2012-01-02 15:17:37 +01:00
2011-11-08 23:00:38 +01:00
2012-01-02 15:17:37 +01:00
Flickable {
2011-11-08 23:00:38 +01:00
id: listView
anchors.fill: parent
clip: true
2012-01-02 15:17:37 +01:00
Column {
2012-01-02 15:31:19 +01:00
id: menuColumn
spacing: 4
2011-11-08 23:00:38 +01:00
onChildrenChanged: {
for (var i = 0; i < children.length; ++i) {
if (children[i].clicked != undefined)
children[i].clicked.connect(root.close)
}
}
}
}
ScrollBar {
id: scrollBar
flickableItem: listView
visible: listView.contentHeight > contentItem.height
//platformInverted: root.platformInverted
anchors { top: listView.top; right: listView.right }
}
}
}
onStatusChanged: {
if (status == DialogStatus.Opening) {
if (listView.currentItem != null) {
listView.currentItem.focus = false
}
listView.currentIndex = -1
listView.positionViewAtIndex(0, ListView.Beginning)
}
else if (status == DialogStatus.Open) {
listView.focus = true
}
}
}