summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-07-01 20:53:25 +0200
committerJ-P Nurmi <jpnurmi@digia.com>2014-07-11 12:34:10 +0200
commitd767cd8f69c30ab4d426bf7ffbcfb3d43b0e744e (patch)
treedcdcd8bcc0997ffbe6ae54e941f512914a1c1b05
parent223ec0f7827fde5609d7d48237a95e9b7c9563e1 (diff)
TableView: add styleData.pressed for itemDelegate & rowDelegate
Make it possible for the Android style to visualize the pressed state. Task-number: QTBUG-35081 Change-Id: Ida956ef1fbdccd0931c111424788973c29b0a6c3 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
-rw-r--r--src/controls/TableView.qml54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 5feeac014..386edcf8d 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -148,6 +148,7 @@ ScrollView {
\li styleData.column - the index of the column
\li styleData.elideMode - the elide mode of the column
\li styleData.textAlignment - the horizontal text alignment of the column
+ \li styleData.pressed - true when the item is pressed (since QtQuick.Controls 1.3)
\endlist
Example:
@@ -178,6 +179,7 @@ ScrollView {
\li styleData.alternate - true when the row uses the alternate background color
\li styleData.selected - true when the row is currently selected
\li styleData.row - the index of the row
+ \li styleData.pressed - true when the row is pressed (since QtQuick.Controls 1.3)
\endlist
\note For performance reasons, created delegates can be recycled
@@ -592,8 +594,12 @@ ScrollView {
property int clickedRow: -1
property int dragRow: -1
property int firstKeyRow: -1
+ property int pressedRow: -1
+ property int pressedColumn: -1
onReleased: {
+ pressedRow = -1
+ pressedColumn = -1
autoincrement = false
autodecrement = false
var clickIndex = listView.indexAt(0, mouseY + listView.contentY)
@@ -629,14 +635,17 @@ ScrollView {
autodecrement = false;
}
- if (pressed && !Settings.hasTouchScreen) {
- var newIndex = Math.max(0, listView.indexAt(0, mouseY + listView.contentY))
- if (newIndex >= 0 && newIndex !== currentRow) {
- listView.currentIndex = newIndex;
- if (selectionMode === SelectionMode.SingleSelection) {
- selection.__selectOne(newIndex)
- } else if (selectionMode > 1) {
- dragRow = newIndex
+ if (pressed && containsMouse) {
+ pressedRow = Math.max(0, listView.indexAt(0, mouseY + listView.contentY))
+ pressedColumn = headerrow.columnAt(mouseX)
+ if (!Settings.hasTouchScreen) {
+ if (pressedRow >= 0 && pressedRow !== currentRow) {
+ listView.currentIndex = pressedRow;
+ if (selectionMode === SelectionMode.SingleSelection) {
+ selection.__selectOne(pressedRow)
+ } else if (selectionMode > 1) {
+ dragRow = pressedRow
+ }
}
}
}
@@ -653,16 +662,27 @@ ScrollView {
}
onPressed: {
- var newIndex = listView.indexAt(0, mouseY + listView.contentY)
+ pressedRow = listView.indexAt(0, mouseY + listView.contentY)
+ pressedColumn = headerrow.columnAt(mouseX)
listView.forceActiveFocus()
- if (newIndex > -1 && !Settings.hasTouchScreen) {
- listView.currentIndex = newIndex
- mouseSelect(newIndex, mouse.modifiers)
- mousearea.clickedRow = newIndex
+ if (pressedRow > -1 && !Settings.hasTouchScreen) {
+ listView.currentIndex = pressedRow
+ mouseSelect(pressedRow, mouse.modifiers)
+ mousearea.clickedRow = pressedRow
}
mouseModifiers = mouse.modifiers
}
+ onExited: {
+ mousearea.pressedRow = -1
+ mousearea.pressedColumn = -1
+ }
+
+ onCanceled: {
+ mousearea.pressedRow = -1
+ mousearea.pressedColumn = -1
+ }
+
function mouseSelect(index, modifiers) {
if (selectionMode) {
if (modifiers & Qt.ShiftModifier && (selectionMode === SelectionMode.ExtendedSelection)) {
@@ -875,6 +895,7 @@ ScrollView {
readonly property bool alternate: rowitem.alternate
readonly property bool selected: rowitem.itemSelected
readonly property bool hasActiveFocus: root.activeFocus
+ readonly property bool pressed: rowitem.rowIndex === mousearea.pressedRow
}
readonly property var model: listView.model
readonly property var modelData: rowitem.itemModelData
@@ -904,6 +925,7 @@ ScrollView {
readonly property int elideMode: columnItem.elideMode
readonly property int textAlignment: columnItem.horizontalAlignment
readonly property bool selected: rowitem.itemSelected
+ readonly property bool pressed: row === mousearea.pressedRow && column === mousearea.pressedColumn
readonly property color textColor: rowitem.itemTextColor
readonly property string role: columnItem.role
readonly property var value: (itemModel && itemModel.hasOwnProperty(role))
@@ -940,6 +962,11 @@ ScrollView {
id: headerrow
x: -listView.contentX
+ function columnAt(offset) {
+ var item = childAt(offset, 0)
+ return item ? item.column : -1
+ }
+
Repeater {
id: repeater
@@ -950,6 +977,7 @@ ScrollView {
delegate: Item {
id: headerRowDelegate
+ readonly property int column: index
z:-index
width: modelData.width
implicitWidth: columnCount === 1 ? viewport.width + __verticalScrollBar.width : headerStyle.implicitWidth