Skip to content

Commit

Permalink
Use QMouseEvent instead of QGraphicsSceneMouseEvent
Browse files Browse the repository at this point in the history
QMouseEvent now supports floating point coordinates, and
the graphics scene event is not be available in QtGui
anymore.

Change-Id: I28ab428a2d00fc1deef55b05c1c545e74838e105
Reviewed-on: http://codereview.qt.nokia.com/3991
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
  • Loading branch information
Lars Knoll committed Sep 1, 2011
1 parent 565a782 commit e4ba808
Show file tree
Hide file tree
Showing 25 changed files with 240 additions and 484 deletions.
81 changes: 1 addition & 80 deletions examples/declarative/text/textselection/textselection.qml
Expand Up @@ -37,7 +37,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 1.0
import QtQuick 2.0

Rectangle {
id: editor
Expand Down Expand Up @@ -105,85 +105,6 @@ Rectangle {
+"<p><b>Click inside the selection</b> to cut/copy/paste/cancel selection."
+"<p>It's too whacky to let you paste if there is no current selection."

MouseArea {
property string drag: ""
property int pressPos

x: -startHandle.width
y: 0
width: parent.width+startHandle.width+endHandle.width
height: parent.height

onPressAndHold: {
if (editor.state == "") {
edit.cursorPosition = edit.positionAt(mouse.x+x,mouse.y+y);
edit.selectWord();
editor.state = "selection"
}
}

onClicked: {
if (editor.state == "") {
edit.cursorPosition = edit.positionAt(mouse.x+x,mouse.y+y);
if (!edit.focus)
edit.focus = true;
edit.openSoftwareInputPanel();
}
}

function hitHandle(h,x,y) {
return x>=h.x+flick.contentX && x<h.x+flick.contentX+h.width && y>=h.y+flick.contentY && y<h.y+flick.contentY+h.height
}

onPressed: {
if (editor.state == "selection") {
if (hitHandle(startHandle,mouse.x+x,mouse.y+y)) {
drag = "start"
flick.interactive = false
} else if (hitHandle(endHandle,mouse.x+x,mouse.y+y)) {
drag = "end"
flick.interactive = false
} else {
var pos = edit.positionAt(mouse.x+x,mouse.y+y);
if (pos >= edit.selectionStart && pos <= edit.selectionEnd) {
drag = "selection"
flick.interactive = false
} else {
drag = ""
flick.interactive = true
}
}
}
}

onReleased: {
if (editor.state == "selection") {
if (drag == "selection") {
editor.state = "menu"
}
drag = ""
}
flick.interactive = true
}

onPositionChanged: {
if (editor.state == "selection" && drag != "") {
if (drag == "start") {
var pos = edit.positionAt(mouse.x+x+startHandle.width/2,mouse.y+y);
var e = edit.selectionEnd;
if (e < pos)
e = pos;
edit.select(pos,e);
} else if (drag == "end") {
var pos = edit.positionAt(mouse.x+x-endHandle.width/2,mouse.y+y);
var s = edit.selectionStart;
if (s > pos)
s = pos;
edit.select(s,pos);
}
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/declarative/declarative.pro
Expand Up @@ -8,7 +8,7 @@ MODULE_PRI += ../../modules/qt_declarative.pri

QT = core-private gui gui-private network widgets-private sql v8-private

DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING
DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES
win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000
solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2

Expand Down

0 comments on commit e4ba808

Please sign in to comment.