diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index f4a6c5eb6..ccca36ac7 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -38,13 +38,12 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) KConfigGroup cg(KSharedConfig::openConfig("kdeclarativerc"), "Components-platform"); const QString componentsPlatform = cg.readEntry("name", "desktop"); - qmlRegisterType(uri, 0, 1, "Menu"); - qmlRegisterType(uri, 0, 1, "ContextMenu"); - qmlRegisterType(uri, 0, 1, "MenuItem"); - - if (componentsPlatform == "desktop") { qmlRegisterType(uri, 0, 1, "QueryDialog"); + + qmlRegisterType(uri, 0, 1, "Menu"); + qmlRegisterType(uri, 0, 1, "ContextMenu"); + qmlRegisterType(uri, 0, 1, "MenuItem"); } qmlRegisterType(uri, 0, 1, "RangeModel"); diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/Menu.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/Menu.qml new file mode 100644 index 000000000..b60c7c037 --- /dev/null +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/Menu.qml @@ -0,0 +1,109 @@ +/* +* Copyright (C) 2011 by Marco Martin +* +* 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 + + default property alias content: visualModel.children + property Item visualParent + property int status: DialogStatus.Closed + + 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 + dialog.focus = true + } + + function close() + { + dialog.visible = false + } + + 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 + + width: theme.defaultFont.mSize.width * 12 + height: Math.min(listView.contentHeight, theme.defaultFont.mSize.height * 25) + + + ListView { + id: listView + anchors.fill: parent + + currentIndex : -1 + clip: true + + model: VisualItemModel { + id: visualModel + 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 + } + } +} diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/MenuItem.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/MenuItem.qml new file mode 100644 index 000000000..9ef171d5c --- /dev/null +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/MenuItem.qml @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Components project. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import org.kde.plasma.core 0.1 as PlasmaCore + +Item { + id: root + + property alias text: textArea.text + + signal clicked + + property int implicitWidth: textArea.paintedWidth + 6 + width: parent.width + height: textArea.paintedHeight + 6 + + Label { + id: textArea + anchors.centerIn: parent + horizontalAlignment: Text.AlignHCenter + elide: Text.ElideRight + } + + + MouseArea { + id: mouseArea + + property bool canceled: false + + anchors.fill: parent + + onPressed: { + canceled = false + } + onClicked: { + if (!canceled) + root.clicked() + } + onExited: canceled = true + } + + Keys.onPressed: { + event.accepted = true + switch (event.key) { + case Qt.Key_Select: + case Qt.Key_Enter: + case Qt.Key_Return: { + if (!event.isAutoRepeat) { + root.clicked() + } + break + } + + case Qt.Key_Up: { + if (ListView.view != null) + ListView.view.decrementCurrentIndex() + else + event.accepted = false + break + } + + case Qt.Key_Down: { + if (ListView.view != null) + ListView.view.incrementCurrentIndex() + else + event.accepted = false + break + } + default: { + event.accepted = false + break + } + } + } +} diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/qmldir b/declarativeimports/plasmacomponents/platformcomponents/touch/qmldir index b3dde581a..27cf61792 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/qmldir +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/qmldir @@ -29,6 +29,9 @@ QueryDialog 0.1 QueryDialog.qml SelectionDialog 0.1 SelectionDialog.qml Window 0.1 Window.qml ToolBarLayout 0.1 ToolBarLayout.qml +Menu 0.1 Menu.qml +ContextMenu 0.1 Menu.qml +MenuItem 0.1 MenuItem.qml Page 0.1 Page.qml PageStack 0.1 PageStack.qml