Skip to content

Commit f8fea6f

Browse files
author
Qt Continuous Integration System
committed
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Ignore changes to selectByMouse during a selection. PathView offset out of sync with currentIndex when items are removed.
2 parents 4159518 + 47712d1 commit f8fea6f

15 files changed

+314
-14
lines changed

src/declarative/graphicsitems/qdeclarativepathview.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,8 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
15251525
} else {
15261526
d->regenerate();
15271527
d->updateCurrent();
1528+
if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange)
1529+
d->snapToCurrent();
15281530
}
15291531
if (changedOffset)
15301532
emit offsetChanged();

src/declarative/graphicsitems/qdeclarativetextinput.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,10 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
11681168
}
11691169
if (d->selectByMouse) {
11701170
setKeepMouseGrab(false);
1171+
d->selectPressed = true;
11711172
d->pressPos = event->pos();
11721173
}
1173-
bool mark = event->modifiers() & Qt::ShiftModifier;
1174+
bool mark = (event->modifiers() & Qt::ShiftModifier) && d->selectByMouse;
11741175
int cursor = d->xToPos(event->pos().x());
11751176
d->control->moveCursor(cursor, mark);
11761177
event->setAccepted(true);
@@ -1181,7 +1182,7 @@ void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
11811182
Q_D(QDeclarativeTextInput);
11821183
if (d->sendMouseEventToInputContext(event, QEvent::MouseMove))
11831184
return;
1184-
if (d->selectByMouse) {
1185+
if (d->selectPressed) {
11851186
if (qAbs(int(event->pos().x() - d->pressPos.x())) > QApplication::startDragDistance())
11861187
setKeepMouseGrab(true);
11871188
moveCursorSelection(d->xToPos(event->pos().x()), d->mouseSelectionMode);
@@ -1200,8 +1201,10 @@ void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
12001201
Q_D(QDeclarativeTextInput);
12011202
if (d->sendMouseEventToInputContext(event, QEvent::MouseButtonRelease))
12021203
return;
1203-
if (d->selectByMouse)
1204+
if (d->selectPressed) {
1205+
d->selectPressed = false;
12041206
setKeepMouseGrab(false);
1207+
}
12051208
if (!d->showInputPanelOnFocus) { // input panel on click
12061209
if (d->focusOnPress && !isReadOnly() && boundingRect().contains(event->pos())) {
12071210
if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
@@ -1257,8 +1260,10 @@ bool QDeclarativeTextInputPrivate::sendMouseEventToInputContext(
12571260

12581261
bool QDeclarativeTextInput::sceneEvent(QEvent *event)
12591262
{
1263+
Q_D(QDeclarativeTextInput);
12601264
bool rv = QDeclarativeItem::sceneEvent(event);
12611265
if (event->type() == QEvent::UngrabMouse) {
1266+
d->selectPressed = false;
12621267
setKeepMouseGrab(false);
12631268
}
12641269
return rv;

src/declarative/graphicsitems/qdeclarativetextinput_p_p.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplic
7676
mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone),
7777
hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true),
7878
showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
79-
autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true)
79+
autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true),
80+
selectPressed(false)
8081
{
8182
#ifdef Q_OS_SYMBIAN
8283
if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
@@ -142,6 +143,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplic
142143
bool selectByMouse:1;
143144
bool canPaste:1;
144145
bool hAlignImplicit:1;
146+
bool selectPressed:1;
145147

146148
static inline QDeclarativeTextInputPrivate *get(QDeclarativeTextInput *t) {
147149
return t->d_func();

src/gui/text/qtextcontrol.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, con
15181518
const QTextCursor oldSelection = cursor;
15191519
const int oldCursorPos = cursor.position();
15201520

1521-
mousePressed = true;
1521+
mousePressed = (interactionFlags & Qt::TextSelectableByMouse);
15221522
#ifndef QT_NO_DRAGANDDROP
15231523
mightStartDrag = false;
15241524
#endif
@@ -1607,13 +1607,11 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons
16071607
if (!(buttons & Qt::LeftButton))
16081608
return;
16091609

1610-
const bool selectable = interactionFlags & Qt::TextSelectableByMouse;
16111610
const bool editable = interactionFlags & Qt::TextEditable;
16121611

1613-
if (!selectable && !editable)
1614-
return;
1615-
16161612
if (!(mousePressed
1613+
|| editable
1614+
|| mightStartDrag
16171615
|| selectedWordOnDoubleClick.hasSelection()
16181616
|| selectedBlockOnTrippleClick.hasSelection()))
16191617
return;
@@ -1627,7 +1625,7 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons
16271625
return;
16281626
}
16291627

1630-
if (!selectable)
1628+
if (!mousePressed)
16311629
return;
16321630

16331631
const qreal mouseX = qreal(mousePos.x());
@@ -1695,10 +1693,8 @@ void QTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton button, c
16951693
if (mousePressed) {
16961694
mousePressed = false;
16971695
#ifndef QT_NO_CLIPBOARD
1698-
if (interactionFlags & Qt::TextSelectableByMouse) {
1699-
setClipboardSelection();
1700-
selectionChanged(true);
1701-
}
1696+
setClipboardSelection();
1697+
selectionChanged(true);
17021698
} else if (button == Qt::MidButton
17031699
&& (interactionFlags & Qt::TextEditable)
17041700
&& QApplication::clipboard()->supportsSelection()) {

tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ void tst_QDeclarativePathView::dataModel()
458458
model.removeItem(model.count()-1);
459459
QCOMPARE(pathview->currentIndex(), model.count()-1);
460460

461+
// QTBUG-18825
462+
// Confirm that the target offset is adjusted when removing items
463+
pathview->setCurrentIndex(model.count()-1);
464+
QTRY_COMPARE(pathview->offset(), 1.);
465+
pathview->setCurrentIndex(model.count()-5);
466+
model.removeItem(model.count()-1);
467+
model.removeItem(model.count()-1);
468+
model.removeItem(model.count()-1);
469+
QTRY_COMPARE(pathview->offset(), 2.);
470+
461471
delete canvas;
462472
}
463473

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import QtQuick 1.0
2+
3+
TextEdit {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: false
7+
readOnly: true
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import QtQuick 1.0
2+
3+
TextEdit {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: true
7+
readOnly: true
8+
}

tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ private slots:
119119
void moveCursorSelectionSequence();
120120
void mouseSelection_data();
121121
void mouseSelection();
122+
void deferEnableSelectByMouse_data();
123+
void deferEnableSelectByMouse();
124+
void deferDisableSelectByMouse_data();
125+
void deferDisableSelectByMouse();
122126
void mouseSelectionMode_data();
123127
void mouseSelectionMode();
124128
void dragMouseSelection();
@@ -1360,6 +1364,86 @@ void tst_qdeclarativetextedit::mouseSelection()
13601364
delete canvas;
13611365
}
13621366

1367+
void tst_qdeclarativetextedit::deferEnableSelectByMouse_data()
1368+
{
1369+
QTest::addColumn<QString>("qmlfile");
1370+
1371+
QTest::newRow("writable") << SRCDIR "/data/mouseselection_false.qml";
1372+
QTest::newRow("read only") << SRCDIR "/data/mouseselection_false_readonly.qml";
1373+
}
1374+
1375+
void tst_qdeclarativetextedit::deferEnableSelectByMouse()
1376+
{
1377+
// Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed.
1378+
QFETCH(QString, qmlfile);
1379+
1380+
QDeclarativeView *canvas = createView(qmlfile);
1381+
1382+
canvas->show();
1383+
QApplication::setActiveWindow(canvas);
1384+
QTest::qWaitForWindowShown(canvas);
1385+
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas));
1386+
1387+
QVERIFY(canvas->rootObject() != 0);
1388+
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject());
1389+
QVERIFY(textEditObject != 0);
1390+
1391+
// press-and-drag-and-release from x1 to x2
1392+
int x1 = 10;
1393+
int x2 = 70;
1394+
int y = textEditObject->height()/2;
1395+
1396+
QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y)));
1397+
textEditObject->setSelectByMouse(true);
1398+
//QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work
1399+
QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
1400+
QApplication::sendEvent(canvas->viewport(), &mv);
1401+
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y)));
1402+
QVERIFY(textEditObject->selectedText().isEmpty());
1403+
1404+
delete canvas;
1405+
}
1406+
1407+
void tst_qdeclarativetextedit::deferDisableSelectByMouse_data()
1408+
{
1409+
QTest::addColumn<QString>("qmlfile");
1410+
1411+
QTest::newRow("writable") << SRCDIR "/data/mouseselection_true.qml";
1412+
QTest::newRow("read only") << SRCDIR "/data/mouseselection_true_readonly.qml";
1413+
}
1414+
1415+
void tst_qdeclarativetextedit::deferDisableSelectByMouse()
1416+
{
1417+
// Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed.
1418+
QFETCH(QString, qmlfile);
1419+
1420+
QDeclarativeView *canvas = createView(qmlfile);
1421+
1422+
canvas->show();
1423+
QApplication::setActiveWindow(canvas);
1424+
QTest::qWaitForWindowShown(canvas);
1425+
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas));
1426+
1427+
QVERIFY(canvas->rootObject() != 0);
1428+
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject());
1429+
QVERIFY(textEditObject != 0);
1430+
1431+
// press-and-drag-and-release from x1 to x2
1432+
int x1 = 10;
1433+
int x2 = 70;
1434+
int y = textEditObject->height()/2;
1435+
1436+
QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y)));
1437+
textEditObject->setSelectByMouse(false);
1438+
//QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work
1439+
QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
1440+
QApplication::sendEvent(canvas->viewport(), &mv);
1441+
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y)));
1442+
QVERIFY(textEditObject->selectedText().length() > 3);
1443+
1444+
delete canvas;
1445+
}
1446+
13631447
void tst_qdeclarativetextedit::dragMouseSelection()
13641448
{
13651449
QString qmlfile = SRCDIR "/data/mouseselection_true.qml";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: false
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: false
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: false
7+
readOnly: true
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: false
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: true
7+
readOnly: true
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import QtQuick 1.0
2+
3+
TextInput {
4+
focus: true
5+
text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6+
selectByMouse: true
7+
}

0 commit comments

Comments
 (0)