summaryrefslogtreecommitdiff
path: root/src/controls/TableView.qml
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-06-03 12:47:40 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-10 10:56:58 +0200
commit5303f814746606a78198fec5c02746c2f3090460 (patch)
treecfbb07343e0093cb8dd7dbf46fa539e042e965b5 /src/controls/TableView.qml
parentc7df1ebf207f99c7889c8834d16bf62fc99db75e (diff)
downloadqtquickcontrols-5303f814746606a78198fec5c02746c2f3090460.tar.gz
Updated activation signals in TableView
- Added row property to activated() - Added clicked(row) signal - Added doubleClicked(row) signal - We also fixed the behavior so that we do not emit activated if the user clicks outside of the available rows. - We fixed a problem where key events would not be seen outside of the control Change-Id: I13feba26e900daf85be7be88216f1a0a4a446c57 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/TableView.qml')
-rw-r--r--src/controls/TableView.qml76
1 files changed, 59 insertions, 17 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 17b2b186..44aecfc2 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -239,10 +239,30 @@ ScrollView {
/*! \internal */
property alias __currentRowItem: listView.currentItem
- /*! \qmlsignal TableView::activated()
- Emitted when the user activates an item by single or double-clicking (depending on the platform).
+ /*! \qmlsignal TableView::activated(int row)
+
+ Emitted when the user activates an item by mouse or keyboard interaction.
+ Mouse activation is triggered by single- or double-clicking, depending on the platform.
+
+ \a row int provides access to the activated row index.
+ */
+ signal activated(int row)
+
+ /*! \qmlsignal TableView::clicked(int row)
+
+ Emitted when the user clicks a valid row by single clicking
+
+ \a row int provides access to the clicked row index.
+ */
+ signal clicked(int row)
+
+ /*! \qmlsignal TableView::doubleClicked(int row)
+
+ Emitted when the user double clicks a valid row.
+
+ \a row int provides access to the clicked row index.
*/
- signal activated
+ signal doubleClicked(int row)
/*!
\qmlmethod TableView::positionViewAtRow( int row, PositionMode mode )
@@ -447,28 +467,39 @@ ScrollView {
autoincrement = false;
autodecrement = false;
}
- var y = Math.min(listView.contentY + listView.height - 5, Math.max(mouseY + listView.contentY, listView.contentY));
- var newIndex = listView.indexAt(0, y);
- if (newIndex >= 0)
- listView.currentIndex = listView.indexAt(0, y);
+
+ if (pressed) {
+ var newIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (newIndex >= 0)
+ listView.currentIndex = newIndex;
+ }
}
onClicked: {
- if (root.__activateItemOnSingleClick)
- root.activated()
+ var clickIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (clickIndex > -1) {
+ if (root.__activateItemOnSingleClick)
+ root.activated(clickIndex)
+ root.clicked(clickIndex)
+ }
mouse.accepted = false
}
onPressed: {
+ var newIndex = listView.indexAt(0, mouseY + listView.contentY)
listView.forceActiveFocus()
- var x = Math.min(listView.contentWidth - 5, Math.max(mouseX + listView.contentX, 0))
- var y = Math.min(listView.contentHeight - 5, Math.max(mouseY + listView.contentY, 0))
- listView.currentIndex = listView.indexAt(x, y)
+ if (newIndex > -1) {
+ listView.currentIndex = newIndex
+ }
}
onDoubleClicked: {
- if (!root.__activateItemOnSingleClick)
- root.activated()
+ var clickIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (clickIndex > -1) {
+ if (!root.__activateItemOnSingleClick)
+ root.activated(clickIndex)
+ root.doubleClicked(clickIndex)
+ }
}
// Note: with boolean preventStealing we are keeping the flickable from
@@ -511,8 +542,15 @@ ScrollView {
highlightFollowsCurrentItem: true
model: root.model
- Keys.onUpPressed: root.__decrementCurrentIndex()
- Keys.onDownPressed: root.__incrementCurrentIndex()
+ Keys.onUpPressed: {
+ event.accepted = false
+ root.__decrementCurrentIndex()
+ }
+
+ Keys.onDownPressed: {
+ event.accepted = false
+ root.__incrementCurrentIndex()
+ }
Keys.onPressed: {
if (event.key === Qt.Key_PageUp) {
@@ -521,7 +559,11 @@ ScrollView {
verticalScrollBar.value = __verticalScrollBar.value + listView.height
}
- Keys.onReturnPressed: root.activated();
+ Keys.onReturnPressed: {
+ event.accepted = false
+ if (currentRow > -1)
+ root.activated(currentRow);
+ }
delegate: Item {
id: rowitem