aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-11-16 16:06:07 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-02 16:16:31 +0000
commitb185fc1ac02d4887d2b187a4043b1fdedb95305e (patch)
tree9650c29786a86d7272541702d59cfa285216f7f0 /src/imports/controls
parent5823d6230f5b1fbbd27c3b00b334e062a21b3d65 (diff)
Add Menu
An item-based menu derived from QQuickPanel. Eventually we'd like to make Panel itself a QQuickItem, as it makes both the implementation and the actual usage of Menu a lot easier. Change-Id: Ic1bf2a05ab98d9e17824c402ed8326ef65d26c69 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports/controls')
-rw-r--r--src/imports/controls/Menu.qml66
-rw-r--r--src/imports/controls/MenuItem.qml93
-rw-r--r--src/imports/controls/controls.pri2
-rw-r--r--src/imports/controls/doc/images/qtlabscontrols-menu-contentItem.pngbin0 -> 2639 bytes
-rw-r--r--src/imports/controls/doc/images/qtlabscontrols-menu.pngbin0 -> 2680 bytes
-rw-r--r--src/imports/controls/doc/snippets/qtlabscontrols-menu-contentItem.qml58
-rw-r--r--src/imports/controls/doc/snippets/qtlabscontrols-menu.qml51
-rw-r--r--src/imports/controls/doc/src/qtlabscontrols-customize.qdoc17
-rw-r--r--src/imports/controls/doc/src/qtlabscontrols-index.qdoc3
-rw-r--r--src/imports/controls/doc/src/qtlabscontrols-menus.qdoc43
-rw-r--r--src/imports/controls/qtlabscontrolsplugin.cpp2
11 files changed, 335 insertions, 0 deletions
diff --git a/src/imports/controls/Menu.qml b/src/imports/controls/Menu.qml
new file mode 100644
index 00000000..f4a4243e
--- /dev/null
+++ b/src/imports/controls/Menu.qml
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.controls 1.0
+import Qt.labs.templates 1.0 as T
+
+T.Menu {
+ id: control
+
+ //! [contentItem]
+ contentItem: ListView {
+ implicitWidth: 200
+ implicitHeight: Math.min(contentHeight, 200)
+ model: control.contentModel
+ // TODO: improve this?
+ interactive: ApplicationWindow.window ? contentHeight > ApplicationWindow.window.height : false
+ clip: true
+ keyNavigationWraps: false
+ currentIndex: -1
+
+ ScrollIndicator.vertical: ScrollIndicator {}
+
+ Rectangle {
+ width: parent.width
+ height: parent.height
+ color: "#ffffff"
+ border.color: "#353637"
+ z: -1
+ }
+ }
+ //! [contentItem]
+}
diff --git a/src/imports/controls/MenuItem.qml b/src/imports/controls/MenuItem.qml
new file mode 100644
index 00000000..df51fc72
--- /dev/null
+++ b/src/imports/controls/MenuItem.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+
+T.MenuItem {
+ id: control
+
+ implicitWidth: background ? background.implicitWidth
+ : (label ? label.implicitWidth : 0) + (indicator ? indicator.implicitWidth : 0)
+ + (label && indicator ? spacing : 0) + leftPadding + rightPadding
+ implicitHeight: background ? background.implicitHeight
+ : (label ? label.implicitHeight : 0) + (indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding
+
+ padding: 12
+ spacing: 12
+
+ //! [label]
+ label: Text {
+ x: control.mirrored ? control.width - width - control.rightPadding : control.leftPadding
+ y: control.topPadding
+ width: control.availableWidth - (control.checkable ? indicator.width + control.spacing : 0)
+ height: control.availableHeight
+
+ text: control.text
+ font: control.font
+ color: control.enabled ? "#26282a" : "#bdbebf"
+ elide: Text.ElideRight
+ visible: control.text
+ horizontalAlignment: Text.AlignLeft
+ verticalAlignment: Text.AlignVCenter
+ }
+ //! [label]
+
+ //! [indicator]
+ indicator: Image {
+ x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding
+ y: control.topPadding + (control.availableHeight - height) / 2
+
+ visible: control.checked
+ source: control.checkable ? "qrc:/images/check.png" : ""
+ }
+ //! [indicator]
+
+ //! [background]
+ background: Item {
+ implicitWidth: 200
+ implicitHeight: 40
+
+ Rectangle {
+ x: 1
+ y: 1
+ width: parent.width - 2
+ height: parent.height - 2
+ color: control.activeFocus || control.pressed ? "#eeeeee" : "transparent"
+ }
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri
index d0cf0550..78c9a1d0 100644
--- a/src/imports/controls/controls.pri
+++ b/src/imports/controls/controls.pri
@@ -9,6 +9,8 @@ QML_FILES = \
GroupBox.qml \
ItemDelegate.qml \
Label.qml \
+ Menu.qml \
+ MenuItem.qml \
PageIndicator.qml \
ProgressBar.qml \
RadioButton.qml \
diff --git a/src/imports/controls/doc/images/qtlabscontrols-menu-contentItem.png b/src/imports/controls/doc/images/qtlabscontrols-menu-contentItem.png
new file mode 100644
index 00000000..e16e196e
--- /dev/null
+++ b/src/imports/controls/doc/images/qtlabscontrols-menu-contentItem.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtlabscontrols-menu.png b/src/imports/controls/doc/images/qtlabscontrols-menu.png
new file mode 100644
index 00000000..b782b9fe
--- /dev/null
+++ b/src/imports/controls/doc/images/qtlabscontrols-menu.png
Binary files differ
diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-menu-contentItem.qml b/src/imports/controls/doc/snippets/qtlabscontrols-menu-contentItem.qml
new file mode 100644
index 00000000..0c270d34
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtlabscontrols-menu-contentItem.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+Item {
+ id: window
+ width: menu.contentItem.width
+ height: menu.contentItem.height
+ visible: true
+
+ Menu {
+ id: menu
+ contentItem.parent: window
+
+ MenuItem {
+ text: "New..."
+ }
+ MenuItem {
+ text: "Open..."
+ }
+ MenuItem {
+ text: "Save"
+ }
+ }
+
+ Rectangle {
+ parent: menu.contentItem
+ anchors.fill: parent
+ color: 'transparent'
+ border.color: 'red'
+ }
+}
diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-menu.qml b/src/imports/controls/doc/snippets/qtlabscontrols-menu.qml
new file mode 100644
index 00000000..b0f32203
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtlabscontrols-menu.qml
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+Item {
+ id: window
+ width: menu.contentItem.width
+ height: menu.contentItem.height
+ visible: true
+
+ Menu {
+ id: menu
+ contentItem.parent: window
+
+ MenuItem {
+ text: "New..."
+ }
+ MenuItem {
+ text: "Open..."
+ }
+ MenuItem {
+ text: "Save"
+ }
+ }
+}
diff --git a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
index dddb3a8a..a7bd7d8b 100644
--- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
+++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
@@ -206,6 +206,23 @@
Label has no background item by default.
+ \section1 Customizing Menu
+
+ Menu consists of a \l {Panel::}{contentItem}.
+
+ \section3 Content item
+
+ \image qtlabscontrols-menu-contentItem.png
+
+ \snippet Menu.qml contentItem
+
+
+ \section1 Customizing MenuItem
+
+ MenuItem can be customized in the same manner as
+ \l {Customizing Button}{Button}.
+
+
\section1 Customizing PageIndicator
TODO
diff --git a/src/imports/controls/doc/src/qtlabscontrols-index.qdoc b/src/imports/controls/doc/src/qtlabscontrols-index.qdoc
index 55d89344..936e65e8 100644
--- a/src/imports/controls/doc/src/qtlabscontrols-index.qdoc
+++ b/src/imports/controls/doc/src/qtlabscontrols-index.qdoc
@@ -231,6 +231,9 @@
\li \l [QtQuickControls] {Label}
\li \l [QtLabsControls] {Label}
\row
+ \li \l [QtQuickControls] {Menu}
+ \li \l [QtLabsControls] {Menu}
+ \row
\li \l [QtQuickControls] {ProgressBar}
\li \l [QtLabsControls] {ProgressBar}
\row
diff --git a/src/imports/controls/doc/src/qtlabscontrols-menus.qdoc b/src/imports/controls/doc/src/qtlabscontrols-menus.qdoc
new file mode 100644
index 00000000..65b4f04c
--- /dev/null
+++ b/src/imports/controls/doc/src/qtlabscontrols-menus.qdoc
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \page qtlabscontrols-menus.html
+ \title Menu Controls
+
+ \annotatedlist qtlabscontrols-menus
+
+ Each type of menu control has its own specific target use case. The
+ following sections offer guidelines for choosing the appropriate type
+ of menu control, depending on the use case.
+
+ \section1 Menu Control
+
+ \image qtlabscontrols-menu.png
+
+ \l Menu is a traditional menu.
+*/
diff --git a/src/imports/controls/qtlabscontrolsplugin.cpp b/src/imports/controls/qtlabscontrolsplugin.cpp
index cf6ad6de..39525ee6 100644
--- a/src/imports/controls/qtlabscontrolsplugin.cpp
+++ b/src/imports/controls/qtlabscontrolsplugin.cpp
@@ -77,6 +77,8 @@ void QtLabsControlsPlugin::registerTypes(const char *uri)
qmlRegisterType(selector->select(QStringLiteral("/GroupBox.qml")), uri, 1, 0, "GroupBox");
qmlRegisterType(selector->select(QStringLiteral("/ItemDelegate.qml")), uri, 1, 0, "ItemDelegate");
qmlRegisterType(selector->select(QStringLiteral("/Label.qml")), uri, 1, 0, "Label");
+ qmlRegisterType(selector->select(QStringLiteral("/Menu.qml")), uri, 1, 0, "Menu");
+ qmlRegisterType(selector->select(QStringLiteral("/MenuItem.qml")), uri, 1, 0, "MenuItem");
qmlRegisterType(selector->select(QStringLiteral("/PageIndicator.qml")), uri, 1, 0, "PageIndicator");
qmlRegisterType(selector->select(QStringLiteral("/ProgressBar.qml")), uri, 1, 0, "ProgressBar");
qmlRegisterType(selector->select(QStringLiteral("/RadioButton.qml")), uri, 1, 0, "RadioButton");