diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml index 9ebf64e9f43fdef7d5a9734f5900207a30059d43..430c862d498aa7c7b485c787ae41c28a88710ac9 100644 --- a/src/controls/TableView.qml +++ b/src/controls/TableView.qml @@ -41,6 +41,7 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Private 1.0 +import QtQuick.Controls.Styles 1.0 /*! \qmltype TableView @@ -221,7 +222,8 @@ ScrollView { property alias currentRow: listView.currentIndex /*! \qmlsignal TableView::activated() - Emitted when a new row is selected by the user. */ + Emitted when the user activates an item by single or double-clicking (depending on the platform). + */ signal activated @@ -237,6 +239,9 @@ ScrollView { __scrollBarTopMargin: Qt.platform.os === "mac" ? headerrow.height : 0 __viewTopMargin: headerrow.height + /*! \internal */ + property bool __activateItemOnSingleClick: __style ? __style.activateItemOnSingleClick : false + /*! \internal */ function __decrementCurrentIndex() { __scroller.blockUpdates = true; @@ -277,6 +282,7 @@ ScrollView { id: mousearea anchors.fill: listView + propagateComposedEvents: true property bool autoincrement: false property bool autodecrement: false @@ -309,19 +315,28 @@ ScrollView { listView.currentIndex = listView.indexAt(0, y); } - onPressed: { + onClicked: { + if (root.__activateItemOnSingleClick) + root.activated() + mouse.accepted = false + } + + onPressed: { listView.forceActiveFocus() var x = Math.min(flickableItem.contentWidth - 5, Math.max(mouseX + flickableItem.contentX, 0)) var y = Math.min(flickableItem.contentHeight - 5, Math.max(mouseY + flickableItem.contentY, 0)) listView.currentIndex = listView.indexAt(x, y) - mouse.accepted = false } - onDoubleClicked: { root.activated() } + onDoubleClicked: { + if (!root.__activateItemOnSingleClick) + root.activated() + } // Note: with boolean preventStealing we are keeping the flickable from // eating our mouse press events preventStealing: true + } // Fills extra rows with alternate color diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp index 59c9eaac105ffbd76dd5ca066e61cdd52f1cb100..bde25409e70fb93bae99421dfcca1b4385edbd2b 100644 --- a/src/private/qquickstyleitem.cpp +++ b/src/private/qquickstyleitem.cpp @@ -946,6 +946,8 @@ QVariant QQuickStyleItem::styleHint(const QString &metric) return qApp->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); } else if (metric == "scrollToClickPosition") return qApp->style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition); + else if (metric == "activateItemOnSingleClick") + return qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick); else if (metric == "transientScrollBars") return qApp->style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption); return 0; diff --git a/src/styles/Desktop/TableViewStyle.qml b/src/styles/Desktop/TableViewStyle.qml index 266992703a1e29610e4fe4174feaa34fd9ac59de..716afa6183c2730c6d12509c3aa8ce704054a973 100644 --- a/src/styles/Desktop/TableViewStyle.qml +++ b/src/styles/Desktop/TableViewStyle.qml @@ -44,6 +44,7 @@ import QtQuick.Controls.Private 1.0 ScrollViewStyle { id: root + property bool activateItemOnSingleClick: __styleitem.styleHint("activateItemOnSingleClick") property color textColor: __styleitem.styleHint("textColor") property color highlightedTextColor: __styleitem.styleHint("highlightedTextColor") diff --git a/src/styles/TableViewStyle.qml b/src/styles/TableViewStyle.qml index 88fc3743f00e35c12e18355149ba81262a8d09e8..86678f978199bc867d9b3670e97ebd72599993c3 100644 --- a/src/styles/TableViewStyle.qml +++ b/src/styles/TableViewStyle.qml @@ -44,6 +44,7 @@ import QtQuick.Controls.Private 1.0 ScrollViewStyle { id: root + property bool activateItemOnSingleClick: false property color textColor: __syspal.text property color highlightedTextColor: "white" diff --git a/tests/auto/controls/data/tableview/table_activated.qml b/tests/auto/controls/data/tableview/table_activated.qml new file mode 100644 index 0000000000000000000000000000000000000000..52d420c499da83511c1b6c0bdc272493ee549ca4 --- /dev/null +++ b/tests/auto/controls/data/tableview/table_activated.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tasuku Suzuki <stasuku@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $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 Digia Plc 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 2.1 +import QtQuick.Controls 1.0 + +TableView { + height: 70 + model: 10 + + property bool test: false + onActivated: test = true + + TableViewColumn { + width: 100 + } +} diff --git a/tests/auto/controls/data/tableview/table_delegate.qml b/tests/auto/controls/data/tableview/table_delegate.qml index 38f4c1ce41717b4ab495cccdd8de6640c120985a..a3ab621d956cc91f01235eaae5e1cc5da40b2bcc 100644 --- a/tests/auto/controls/data/tableview/table_delegate.qml +++ b/tests/auto/controls/data/tableview/table_delegate.qml @@ -46,6 +46,9 @@ TableView { model: [{"text": "text1"}, {"text": "text2"}, {"text": "text3"}] property var test: 0 + property bool activatedTest: false + onActivated: activatedTest = true + TableViewColumn { title: "Text" role: "text" diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml index 65d7c72cd47ea081ff77ff325d392c6e8108b45b..bc38ad46f5ef8cc008993c10126d7189821507af 100644 --- a/tests/auto/controls/data/tst_tableview.qml +++ b/tests/auto/controls/data/tst_tableview.qml @@ -180,6 +180,36 @@ TestCase { table.destroy() } + function test_activated() { + var component = Qt.createComponent("tableview/table_activated.qml") + compare(component.status, Component.Ready) + var table = component.createObject(container); + verify(table !== null, "table created is null") + table.forceActiveFocus(); + compare(table.test, false) + if (!table.__activateItemOnSingleClick) + mouseDoubleClick(table, 15 , 15, Qt.LeftButton) + else + mouseClick(table, 15, 15, Qt.LeftButton) + compare(table.test, true) + table.destroy() + } + + function test_activated_withItemDelegate() { + var component = Qt.createComponent("tableview/table_delegate.qml") + compare(component.status, Component.Ready) + var table = component.createObject(container); + verify(table !== null, "table created is null") + table.forceActiveFocus(); + compare(table.activatedTest, false) + if (!table.__activateItemOnSingleClick) + mouseDoubleClick(table, 15 , 50, Qt.LeftButton) + else + mouseClick(table, 15, 50, Qt.LeftButton) + compare(table.activatedTest, true) + table.destroy() + } + function test_columnCount() { var component = Qt.createComponent("tableview/table_multicolumns.qml") compare(component.status, Component.Ready)