From e1d1b65e63223e8705b8df09645f8740ab7fb80d Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 3 Mar 2011 10:18:21 +1000 Subject: Compensate for horizontal scroll in TextInput micro focus. Return the adjusted cursore rectangle rather than the one returned by QLineControl. Change-Id: I343ecdb47ef2ea59519c8d155bbb9917d9c8ce56 Task-number: QTBUG-17864 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 2 +- .../declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index dc44bfe..f41ab03 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1288,7 +1288,7 @@ QVariant QDeclarativeTextInput::inputMethodQuery(Qt::InputMethodQuery property) Q_D(const QDeclarativeTextInput); switch(property) { case Qt::ImMicroFocus: - return d->control->cursorRect(); + return cursorRectangle(); case Qt::ImFont: return font(); case Qt::ImCursorPosition: diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 24ce0e4..0320ce2 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1451,6 +1451,7 @@ void tst_qdeclarativetextinput::cursorRectangle() QVERIFY(r.left() < textWidth); QVERIFY(r.right() > textWidth); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } // Check the cursor rectangle remains within the input bounding rect when auto scrolling. @@ -1460,11 +1461,14 @@ void tst_qdeclarativetextinput::cursorRectangle() for (int i = 6; i < text.length(); ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } for (int i = text.length() - 2; i >= 0; --i) { input.setCursorPosition(i); + r = input.cursorRectangle(); QVERIFY(r.right() >= 0); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } } -- cgit v0.12 From 9c1549371e86c95e08f7fc2e11242de12fb1e1da Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Wed, 2 Mar 2011 11:19:07 +1000 Subject: QDeclarativePropertyMap::keys() cannot be called from qml Not allow create dynamic properties which are same with existing method (method, signal, slot) names. Change-Id: I0ae64c8a6a89ef4f7614169088f7c005edad40b0 Task-number:QTBUG-17868 Reviewed-by:Martin Jones --- .../util/qdeclarativeopenmetaobject.cpp | 14 +++++---- src/declarative/util/qdeclarativepropertymap.cpp | 15 ++++++++-- .../tst_qdeclarativepropertymap.cpp | 34 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp index 0ceda35..8a8d05e 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject.cpp +++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp @@ -289,17 +289,19 @@ void QDeclarativeOpenMetaObject::setValue(const QByteArray &name, const QVariant int id = -1; if (iter == d->type->d->names.end()) { - id = d->type->createProperty(name.constData()) - d->type->d->propertyOffset; + id = createProperty(name.constData(), "") - d->type->d->propertyOffset; } else { id = *iter; } - QVariant &dataVal = d->getData(id); - if (dataVal == val) - return; + if (id >= 0) { + QVariant &dataVal = d->getData(id); + if (dataVal == val) + return; - dataVal = val; - activate(d->object, id + d->type->d->signalOffset, 0); + dataVal = val; + activate(d->object, id + d->type->d->signalOffset, 0); + } } // returns true if this value has been initialized by a call to either value() or setValue() diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp index 1a3e0be..915f027 100644 --- a/src/declarative/util/qdeclarativepropertymap.cpp +++ b/src/declarative/util/qdeclarativepropertymap.cpp @@ -182,7 +182,18 @@ QVariant QDeclarativePropertyMap::value(const QString &key) const void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value) { Q_D(QDeclarativePropertyMap); - d->mo->setValue(key.toUtf8(), value); + //The following strings shouldn't be used as property names + if (key != QLatin1String("keys") + && key != QLatin1String("valueChanged") + && key != QLatin1String("QObject") + && key != QLatin1String("destroyed") + && key != QLatin1String("deleteLater")) { + d->mo->setValue(key.toUtf8(), value); + } else { + qWarning() << "Creating property with name" + << key + << "is not permitted, conflicts with internal symbols."; + } } /*! @@ -258,7 +269,7 @@ QVariant &QDeclarativePropertyMap::operator[](const QString &key) Q_D(QDeclarativePropertyMap); QByteArray utf8key = key.toUtf8(); if (!d->keys.contains(key)) - d->mo->setValue(utf8key, QVariant()); //force creation -- needed below + insert(key, QVariant());//force creation -- needed below return (*(d->mo))[utf8key]; } diff --git a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp index 7d746a7..e3a4723 100644 --- a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp +++ b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp @@ -76,6 +76,40 @@ void tst_QDeclarativePropertyMap::insert() map.insert(QLatin1String("key1"),"Hello World"); QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); + + //inserting property names same with existing method(signal, slot, method) names is not allowed + //QDeclarativePropertyMap has an invokable keys() method + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("keys"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("keys"))); + QVERIFY(map.value(QLatin1String("keys")).isNull()); + + //QDeclarativePropertyMap has a deleteLater() slot + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("deleteLater"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("deleteLater"))); + QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); + + //QDeclarativePropertyMap has an valueChanged() signal + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("valueChanged"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("valueChanged"))); + QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); + + //but 'valueChange' should be ok + map.insert(QLatin1String("valueChange"), 1); + QVERIFY(map.keys().count() == 3); + QVERIFY(map.contains(QLatin1String("valueChange"))); + QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1)); + + //'valueCHANGED' should be ok, too + map.insert(QLatin1String("valueCHANGED"), 1); + QVERIFY(map.keys().count() == 4); + QVERIFY(map.contains(QLatin1String("valueCHANGED"))); + QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); } void tst_QDeclarativePropertyMap::operatorInsert() -- cgit v0.12 From d893ad027570ae7b3127636a4622f9cb4d5bb7a0 Mon Sep 17 00:00:00 2001 From: Lasse Holmstedt Date: Fri, 4 Mar 2011 10:34:57 +1000 Subject: Fix potential crash in QTextControl. inputContext() is only safe to call if there is a current contextWidget. Change-Id: I6cbccf5f5fbb2d8c9ca6acf5f7e02f680eb84483 Reviewed-by: Andrew den Exter --- src/gui/text/qtextcontrol.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index b25588d..f4054d3 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -1649,8 +1649,10 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons emit q->cursorPositionChanged(); _q_updateCurrentCharFormatAndSelection(); #ifndef QT_NO_IM - if (QInputContext *ic = inputContext()) { - ic->update(); + if (contextWidget) { + if (QInputContext *ic = inputContext()) { + ic->update(); + } } #endif //QT_NO_IM } else { -- cgit v0.12 From 7d22f04a0d2af6752fbbcaa970808a6e8d33399b Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 3 Mar 2011 15:26:57 +1000 Subject: Fix word selection locking on string boundaries. QTextBoundaryFinder will return the position -1 if it reaches the end of a string without finding a boundary, reset the cursor and anchor to 0 or the string length as appropriate in those cases. Also allow selection to lock onto the string limits as if they were words. Change-Id: Ie9d233967c73eb6a61f19c76494f04bca18612f8 Task-number: QTBUG-17860 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 25 ++++---- .../tst_qdeclarativetextinput.cpp | 73 +++++++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index f41ab03..8b21008 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1570,38 +1570,41 @@ void QDeclarativeTextInput::moveCursorSelection(int pos, SelectionMode mode) anchor = d->control->selectionStart(); if (anchor < pos || (anchor == pos && cursor < pos)) { - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, d->control->text()); + const QString text = d->control->text(); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text); finder.setPosition(anchor); const QTextBoundaryFinder::BoundaryReasons reasons = finder.boundaryReasons(); - if (!(reasons & QTextBoundaryFinder::StartWord) + if (anchor < text.length() && !(reasons & QTextBoundaryFinder::StartWord) || ((reasons & QTextBoundaryFinder::EndWord) && anchor > cursor)) { finder.toPreviousBoundary(); } - anchor = finder.position(); + anchor = finder.position() != -1 ? finder.position() : 0; finder.setPosition(pos); - if (!finder.isAtBoundary()) + if (pos > 0 && !finder.boundaryReasons()) finder.toNextBoundary(); + const int cursor = finder.position() != -1 ? finder.position() : text.length(); - d->control->setSelection(anchor, finder.position() - anchor); + d->control->setSelection(anchor, cursor - anchor); } else if (anchor > pos || (anchor == pos && cursor > pos)) { - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, d->control->text()); + const QString text = d->control->text(); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text); finder.setPosition(anchor); const QTextBoundaryFinder::BoundaryReasons reasons = finder.boundaryReasons(); - if (!(reasons & QTextBoundaryFinder::EndWord) + if (anchor > 0 && !(reasons & QTextBoundaryFinder::EndWord) || ((reasons & QTextBoundaryFinder::StartWord) && anchor < cursor)) { finder.toNextBoundary(); } - - anchor = finder.position(); + anchor = finder.position() != -1 ? finder.position() : text.length(); finder.setPosition(pos); - if (!finder.isAtBoundary()) + if (pos < text.length() && !finder.boundaryReasons()) finder.toPreviousBoundary(); + const int cursor = finder.position() != -1 ? finder.position() : 0; - d->control->setSelection(anchor, finder.position() - anchor); + d->control->setSelection(anchor, cursor - anchor); } } } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 0320ce2..e7235f7 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -145,7 +145,8 @@ tst_qdeclarativetextinput::tst_qdeclarativetextinput() standard << "the quick brown fox jumped over the lazy dog" << "It's supercalifragisiticexpialidocious!" << "Hello, world!" - << "!dlrow ,olleH"; + << "!dlrow ,olleH" + << " spacey text "; colorStrings << "aliceblue" << "antiquewhite" @@ -446,6 +447,9 @@ void tst_qdeclarativetextinput::moveCursorSelection_data() QTest::addColumn("selectionEnd"); QTest::addColumn("reversible"); + // () contains the text selected by the cursor. + // <> contains the actual selection. + QTest::newRow("(t)he|characters") << standard[0] << 0 << 1 << QDeclarativeTextInput::SelectCharacters << 0 << 1 << true; QTest::newRow("do(g)|characters") @@ -583,6 +587,24 @@ void tst_qdeclarativetextinput::moveCursorSelection_data() << standard[3] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << true; QTest::newRow("!<()>dlrow|words") << standard[3] << 1 << 1 << QDeclarativeTextInput::SelectWords << 1 << 1 << true; + + QTest::newRow(" text |words") + << standard[4] << 1 << 4 << QDeclarativeTextInput::SelectWords << 1 << 7 << true; + QTest::newRow(" spacey |words") + << standard[4] << 11 << 13 << QDeclarativeTextInput::SelectWords << 10 << 14 << false; // Should be reversible. QTBUG-11365 + QTest::newRow("<( )>spacey text |words|ltr") + << standard[4] << 0 << 1 << QDeclarativeTextInput::SelectWords << 0 << 1 << false; + QTest::newRow("<( )spacey> text |words|rtl") + << standard[4] << 1 << 0 << QDeclarativeTextInput::SelectWords << 0 << 7 << false; + QTest::newRow("spacey |words|ltr") + << standard[4] << 14 << 15 << QDeclarativeTextInput::SelectWords << 10 << 15 << false; +// QTBUG-11365 +// QTest::newRow("spacey text<( )>|words|rtl") +// << standard[4] << 15 << 14 << QDeclarativeTextInput::SelectWords << 14 << 15 << false; + QTest::newRow("<()> spacey text |words") + << standard[4] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << false; + QTest::newRow(" spacey text <()>|words") + << standard[4] << 15 << 15 << QDeclarativeTextInput::SelectWords << 15 << 15 << false; } void tst_qdeclarativetextinput::moveCursorSelection() @@ -629,6 +651,11 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence_data() QTest::addColumn("selection2Start"); QTest::addColumn("selection2End"); + // () contains the text selected by the cursor. + // <> contains the actual selection. + // ^ is the revised cursor position. + // {} contains the revised selection. + QTest::newRow("the { f^ox} jumped|ltr") << standard[0] << 9 << 13 << 17 @@ -741,6 +768,50 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence_data() << 11 << 9 << 5 << 8 << 13 << 1 << 13; + + QTest::newRow("{<(^} sp)acey> text |ltr") + << standard[4] + << 0 << 3 << 0 + << 0 << 7 + << 0 << 0; + QTest::newRow("{<( ^}sp)acey> text |ltr") + << standard[4] + << 0 << 3 << 1 + << 0 << 7 + << 0 << 1; + QTest::newRow("<( {s^p)acey>} text |rtl") + << standard[4] + << 3 << 0 << 2 + << 0 << 7 + << 1 << 7; + QTest::newRow("<( {^sp)acey>} text |rtl") + << standard[4] + << 3 << 0 << 1 + << 0 << 7 + << 1 << 7; + + QTest::newRow(" spacey }|rtl") + << standard[4] + << 15 << 12 << 15 + << 10 << 15 + << 15 << 15; +// QTBUG-11365 +// QTest::newRow(" spacey }|rtl") +// << standard[4] +// << 15 << 12 << 14 +// << 10 << 15 +// << 14 << 15; + QTest::newRow(" spacey {|ltr") + << standard[4] + << 12 << 15 << 13 + << 10 << 15 + << 10 << 14; +// QTBUG-11365 +// QTest::newRow(" spacey {|ltr") +// << standard[4] +// << 12 << 15 << 14 +// << 10 << 15 +// << 10 << 14; } void tst_qdeclarativetextinput::moveCursorSelectionSequence() -- cgit v0.12 From 818d3e56bda4829398ceb633a7271c5c99fcdbda Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 4 Mar 2011 10:52:13 +1000 Subject: Fix TextInput auto test failure on mac. Disable auto scroll so the relative position of the text isn't changed when inserting text and changing the cursor position. Change-Id: I6a18e91e98014f1e94216bc85241ebb0d604dd84 Reviewed-by: Bea Lam --- .../auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index e7235f7..ef64dd9 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -2066,6 +2066,7 @@ void tst_qdeclarativetextinput::preeditMicroFocus() view.setInputContext(&ic); QDeclarativeTextInput input; input.setPos(0, 0); + input.setAutoScroll(false); input.setFocus(true); scene.addItem(&input); view.show(); -- cgit v0.12 From 7b4e032559c7b226280e5c9229cd685e73d1e707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 28 Feb 2011 17:12:45 +0100 Subject: Added image conversion flag to prevent conversions. This is needed in the meego graphics system to support the shared image fallback path (when using the raster graphicssystem). The flag is internal. Reviewed-by: Gunnar Sletta --- src/corelib/global/qnamespace.h | 3 ++- src/corelib/global/qnamespace.qdoc | 4 ++++ src/gui/image/qpixmap_raster.cpp | 3 +++ src/plugins/graphicssystems/meego/qmeegographicssystem.cpp | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index e492345..6fa3360 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -574,7 +574,8 @@ public: PreferDither = 0x00000040, AvoidDither = 0x00000080, - NoOpaqueDetection = 0x00000100 + NoOpaqueDetection = 0x00000100, + NoFormatConversion = 0x00000200 }; Q_DECLARE_FLAGS(ImageConversionFlags, ImageConversionFlag) diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 8440542..89e6f55 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -732,6 +732,10 @@ until a non-opaque pixel is found, or if you want the pixmap to retain an alpha channel for some other reason. If the image has no alpha channel this flag has no effect. + + \omitvalue NoFormatConversion Don't do any format conversions on the image. + Can be useful when converting a QImage to a QPixmap for a one-time + rendering operation for example. */ /*! \enum Qt::GUIStyle diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 368600f..5e0ffa8 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -380,6 +380,9 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const void QRasterPixmapData::createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace) { QImage::Format format; + if (flags & Qt::NoFormatConversion) + format = sourceImage.format(); + else #ifdef Q_WS_QWS if (pixelType() == BitmapType) { format = QImage::Format_Mono; diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp index a70d232..6b8d2b3 100644 --- a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp +++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp @@ -171,7 +171,7 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(Qt::HANDLE handl return QMeeGoGraphicsSystem::wrapPixmapData(pmd); } else { QRasterPixmapData *pmd = new QRasterPixmapData(QPixmapData::PixmapType); - pmd->fromImage(softImage, Qt::NoOpaqueDetection); + pmd->fromImage(softImage, Qt::NoFormatConversion); // Make sure that the image was not converted in any way if (pmd->buffer()->data_ptr()->data != -- cgit v0.12