summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-01-31 11:22:08 +1000
committerMartin Jones <martin.jones@nokia.com>2012-01-31 06:33:34 +0100
commitdbf35e498db723ae9850686e462ec4f45bc7b67c (patch)
treecf1f98717e131f26e5a6d63f6693935b2fbdb76f /tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
parent12a5ddf456ba8549645a8cb28a8b4ed6197a14da (diff)
Modify QtQuick1 to build in Qt5
Change-Id: I1c5ccaef420e8f119e761f50b969127f430df7ba Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp355
1 files changed, 133 insertions, 222 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 31da8323..c165e624 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -40,26 +40,26 @@
****************************************************************************/
#include <qtest.h>
#include <QtTest/QSignalSpy>
-#include "../../../shared/util.h"
#include "../shared/testhttpserver.h"
#include <math.h>
#include <QFile>
#include <QTextDocument>
-#include <QtDeclarative/qdeclarativeengine.h>
-#include <QtDeclarative/qdeclarativecontext.h>
-#include <QtDeclarative/qdeclarativeexpression.h>
-#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtQuick1/qdeclarativeengine.h>
+#include <QtQuick1/qdeclarativecontext.h>
+#include <QtQuick1/qdeclarativeexpression.h>
+#include <QtQuick1/qdeclarativecomponent.h>
#include <private/qdeclarativetextedit_p.h>
#include <private/qdeclarativetextedit_p_p.h>
#include <QFontMetrics>
-#include <QDeclarativeView>
+#include <QtQuick1/QDeclarativeView>
#include <QDir>
#include <QStyle>
-#include <QInputContext>
#include <QClipboard>
#include <QMimeData>
#include <private/qapplication_p.h>
+#include <private/qinputpanel_p.h>
#include <private/qtextcontrol_p.h>
+#include "../shared/platforminputcontext.h"
#ifdef Q_OS_SYMBIAN
// In Symbian OS test data is located in applications private dir
@@ -84,6 +84,15 @@ QString createExpectedFileIfNotFound(const QString& filebasename, const QImage&
return expectfile;
}
+void sendPreeditText(const QString &text, int cursor)
+{
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor,
+ text.length(), QVariant()));
+ QInputMethodEvent event(text, attributes);
+ QApplication::sendEvent(qApp->inputPanel()->inputItem(), &event);
+}
+
class tst_qdeclarativetextedit : public QObject
@@ -93,6 +102,8 @@ public:
tst_qdeclarativetextedit();
private slots:
+ void cleanup();
+
void text();
void width();
void wrap();
@@ -221,6 +232,13 @@ tst_qdeclarativetextedit::tst_qdeclarativetextedit()
//
}
+void tst_qdeclarativetextedit::cleanup()
+{
+ // ensure not even skipped tests with custom input context leave it dangling
+ QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel());
+ inputPanelPrivate->testContext = 0;
+}
+
void tst_qdeclarativetextedit::text()
{
{
@@ -547,11 +565,11 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft()
#ifndef Q_OS_MAC // QTBUG-18040
// empty text with implicit alignment follows the system locale-based
- // keyboard input direction from QApplication::keyboardInputDirection
+ // keyboard input direction from QInputPanel::inputDirection
textEdit->setText("");
- QCOMPARE(textEdit->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+ QCOMPARE(textEdit->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
QDeclarativeTextEdit::AlignLeft : QDeclarativeTextEdit::AlignRight);
- if (QApplication::keyboardInputDirection() == Qt::LeftToRight)
+ if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight)
QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2);
else
QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
@@ -568,7 +586,7 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft()
QDeclarativeComponent textComponent(&engine);
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeTextEdit *textObject = qobject_cast<QDeclarativeTextEdit*>(textComponent.create());
- QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+ QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
QDeclarativeTextEdit::AlignLeft : QDeclarativeTextEdit::AlignRight);
delete textObject;
#endif
@@ -1632,6 +1650,7 @@ void tst_qdeclarativetextedit::positionAt()
QDeclarativeTextEdit *texteditObject = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject());
QVERIFY(texteditObject != 0);
+ /*
QFontMetrics fm(texteditObject->font());
const int y0 = fm.height() / 2;
const int y1 = fm.height() * 3 / 2;
@@ -1645,6 +1664,24 @@ void tst_qdeclarativetextedit::positionAt()
#else
QVERIFY(diff < 5);
#endif
+ */
+ QTextLayout layout(texteditObject->text());
+ layout.setFont(texteditObject->font());
+
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ layout.endLayout();
+
+ const int y0 = line.height() / 2;
+ const int y1 = line.height() * 3 / 2;
+
+ int pos = texteditObject->positionAt(texteditObject->width()/2, y0);
+
+ int widthBegin = floor(line.cursorToX(pos - 1));
+ int widthEnd = ceil(line.cursorToX(pos + 1));
+
+ QVERIFY(widthBegin <= texteditObject->width() / 2);
+ QVERIFY(widthEnd >= texteditObject->width() / 2);
const qreal x0 = texteditObject->positionToRectangle(pos).x();
const qreal x1 = texteditObject->positionToRectangle(pos + 1).x();
@@ -1923,7 +1960,7 @@ void tst_qdeclarativetextedit::copyAndPaste() {
if (status == noErr)
CFRelease(pasteboard);
else
- QSKIP("This machine doesn't support the clipboard", SkipAll);
+ QSKIP("This machine doesn't support the clipboard");
}
#endif
@@ -2050,63 +2087,6 @@ QDeclarativeView *tst_qdeclarativetextedit::createView(const QString &filename)
return canvas;
}
-class MyInputContext : public QInputContext
-{
-public:
- MyInputContext() : openInputPanelReceived(false), closeInputPanelReceived(false), updateReceived(false), eventType(QEvent::None) {}
- ~MyInputContext() {}
-
- QString identifierName() { return QString(); }
- QString language() { return QString(); }
-
- void reset() {}
-
- bool isComposing() const { return false; }
-
- bool filterEvent( const QEvent *event )
- {
- if (event->type() == QEvent::RequestSoftwareInputPanel)
- openInputPanelReceived = true;
- if (event->type() == QEvent::CloseSoftwareInputPanel)
- closeInputPanelReceived = true;
- return QInputContext::filterEvent(event);
- }
-
- void update() { updateReceived = true; }
-
- void sendPreeditText(const QString &text, int cursor)
- {
- QList<QInputMethodEvent::Attribute> attributes;
- attributes.append(QInputMethodEvent::Attribute(
- QInputMethodEvent::Cursor, cursor, text.length(), QVariant()));
-
- QInputMethodEvent event(text, attributes);
- sendEvent(event);
- }
-
- void mouseHandler(int x, QMouseEvent *event)
- {
- cursor = x;
- eventType = event->type();
- eventPosition = event->pos();
- eventGlobalPosition = event->globalPos();
- eventButton = event->button();
- eventButtons = event->buttons();
- eventModifiers = event->modifiers();
- }
-
- bool openInputPanelReceived;
- bool closeInputPanelReceived;
- bool updateReceived;
- int cursor;
- QEvent::Type eventType;
- QPoint eventPosition;
- QPoint eventGlobalPosition;
- Qt::MouseButton eventButton;
- Qt::MouseButtons eventButtons;
- Qt::KeyboardModifiers eventModifiers;
-};
-
void tst_qdeclarativetextedit::textInput()
{
QGraphicsScene scene;
@@ -2136,10 +2116,12 @@ void tst_qdeclarativetextedit::textInput()
void tst_qdeclarativetextedit::openInputPanelOnClick()
{
+ PlatformInputContext ic;
+ QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel());
+ inputPanelPrivate->testContext = &ic;
+
QGraphicsScene scene;
QGraphicsView view(&scene);
- MyInputContext ic;
- view.setInputContext(&ic);
QDeclarativeTextEdit edit;
QSignalSpy focusOnPressSpy(&edit, SIGNAL(activeFocusOnPressChanged(bool)));
edit.setText("Hello world");
@@ -2162,14 +2144,14 @@ void tst_qdeclarativetextedit::openInputPanelOnClick()
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QApplication::processEvents();
if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) {
- QCOMPARE(ic.openInputPanelReceived, false);
+ QCOMPARE(ic.isInputPanelVisible(), false);
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, true);
+ QCOMPARE(ic.isInputPanelVisible(), true);
} else if (behavior == QStyle::RSIP_OnMouseClick) {
- QCOMPARE(ic.openInputPanelReceived, true);
+ QCOMPARE(ic.isInputPanelVisible(), true);
}
- ic.openInputPanelReceived = false;
+ ic.clear();
// focus should not cause input panels to open or close
edit.setFocus(false);
@@ -2178,16 +2160,18 @@ void tst_qdeclarativetextedit::openInputPanelOnClick()
edit.setFocus(true);
edit.setFocus(false);
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, false);
- QCOMPARE(ic.closeInputPanelReceived, false);
+ QCOMPARE(ic.m_showInputPanelCallCount, 0);
+ QCOMPARE(ic.m_hideInputPanelCallCount, 0);
}
void tst_qdeclarativetextedit::openInputPanelOnFocus()
{
+ PlatformInputContext ic;
+ QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel());
+ inputPanelPrivate->testContext = &ic;
+
QGraphicsScene scene;
QGraphicsView view(&scene);
- MyInputContext ic;
- view.setInputContext(&ic);
QDeclarativeTextEdit edit;
QSignalSpy focusOnPressSpy(&edit, SIGNAL(activeFocusOnPressChanged(bool)));
edit.setText("Hello world");
@@ -2205,27 +2189,27 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus()
// test default values
QVERIFY(edit.focusOnPress());
- QCOMPARE(ic.openInputPanelReceived, false);
- QCOMPARE(ic.closeInputPanelReceived, false);
+ QCOMPARE(ic.m_showInputPanelCallCount, 0);
+ QCOMPARE(ic.m_hideInputPanelCallCount, 0);
// focus on press, input panel on focus
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QApplication::processEvents();
QVERIFY(edit.hasActiveFocus());
- QCOMPARE(ic.openInputPanelReceived, true);
- ic.openInputPanelReceived = false;
+ QCOMPARE(ic.isInputPanelVisible(), true);
+ ic.clear();
// no events on release
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
- QCOMPARE(ic.openInputPanelReceived, false);
- ic.openInputPanelReceived = false;
+ QCOMPARE(ic.isInputPanelVisible(), false);
+ ic.clear();
// if already focused, input panel can be opened on press
QVERIFY(edit.hasActiveFocus());
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, true);
- ic.openInputPanelReceived = false;
+ QCOMPARE(ic.isInputPanelVisible(), true);
+ ic.clear();
// input method should stay enabled if focus
// is lost to an item that also accepts inputs
@@ -2233,9 +2217,8 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus()
scene.addItem(&anotherEdit);
anotherEdit.setFocus(true);
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, true);
- ic.openInputPanelReceived = false;
- QCOMPARE(view.inputContext(), (QInputContext*)&ic);
+ QCOMPARE(ic.isInputPanelVisible(), true);
+ ic.clear();
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled));
// input method should be disabled if focus
@@ -2244,8 +2227,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus()
scene.addItem(&item);
item.setFocus(true);
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, false);
- QVERIFY(view.inputContext() == 0);
+ QCOMPARE(ic.isInputPanelVisible(), false);
QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled));
// no automatic input panel events should
@@ -2259,22 +2241,22 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus()
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, false);
- QCOMPARE(ic.closeInputPanelReceived, false);
+ QCOMPARE(ic.m_showInputPanelCallCount, 0);
+ QCOMPARE(ic.m_hideInputPanelCallCount, 0);
// one show input panel event should
// be set when openSoftwareInputPanel is called
edit.openSoftwareInputPanel();
- QCOMPARE(ic.openInputPanelReceived, true);
- QCOMPARE(ic.closeInputPanelReceived, false);
- ic.openInputPanelReceived = false;
+ QCOMPARE(ic.isInputPanelVisible(), true);
+ QCOMPARE(ic.m_hideInputPanelCallCount, 0);
+ ic.clear();
// one close input panel event should
// be sent when closeSoftwareInputPanel is called
edit.closeSoftwareInputPanel();
- QCOMPARE(ic.openInputPanelReceived, false);
- QCOMPARE(ic.closeInputPanelReceived, true);
- ic.closeInputPanelReceived = false;
+ QCOMPARE(ic.m_showInputPanelCallCount, 0);
+ QVERIFY(ic.m_hideInputPanelCallCount > 0);
+ ic.clear();
// set activeFocusOnPress back to true
edit.setFocusOnPress(true);
@@ -2283,33 +2265,31 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus()
QCOMPARE(focusOnPressSpy.count(),2);
edit.setFocus(false);
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, false);
- QCOMPARE(ic.closeInputPanelReceived, false);
- ic.closeInputPanelReceived = false;
+ QCOMPARE(ic.m_showInputPanelCallCount, 0);
+ QCOMPARE(ic.m_hideInputPanelCallCount, 0);
+ ic.clear();
// input panel should not re-open
// if focus has already been set
edit.setFocus(true);
- QCOMPARE(ic.openInputPanelReceived, true);
- ic.openInputPanelReceived = false;
+ QCOMPARE(ic.isInputPanelVisible(), true);
+ ic.clear();
edit.setFocus(true);
- QCOMPARE(ic.openInputPanelReceived, false);
+ QCOMPARE(ic.isInputPanelVisible(), false);
// input method should be disabled
// if TextEdit loses focus
edit.setFocus(false);
QApplication::processEvents();
- QVERIFY(view.inputContext() == 0);
QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled));
// input method should not be enabled
// if TextEdit is read only.
edit.setReadOnly(true);
- ic.openInputPanelReceived = false;
+ ic.clear();
edit.setFocus(true);
QApplication::processEvents();
- QCOMPARE(ic.openInputPanelReceived, false);
- QVERIFY(view.inputContext() == 0);
+ QCOMPARE(ic.isInputPanelVisible(), false);
QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled));
}
@@ -2466,12 +2446,12 @@ void tst_qdeclarativetextedit::testQtQuick11Attributes_data()
void tst_qdeclarativetextedit::preeditMicroFocus()
{
- QString preeditText = "super";
+ PlatformInputContext ic;
+ QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel());
+ inputPanelPrivate->testContext = &ic;
QGraphicsScene scene;
QGraphicsView view(&scene);
- MyInputContext ic;
- view.setInputContext(&ic);
QDeclarativeTextEdit edit;
edit.setFocus(true);
scene.addItem(&edit);
@@ -2485,26 +2465,28 @@ void tst_qdeclarativetextedit::preeditMicroFocus()
QRect currentRect;
QRect previousRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect();
+ QString preeditText = "super";
+
// Verify that the micro focus rect is positioned the same for position 0 as
// it would be if there was no preedit text.
- ic.updateReceived = false;
- ic.sendPreeditText(preeditText, 0);
+ ic.clear();
+ sendPreeditText(preeditText, 0);
currentRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect();
QCOMPARE(currentRect, previousRect);
-#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
- QCOMPARE(ic.updateReceived, false); // The cursor position hasn't changed.
+#if defined(Q_WS_X11) || defined(Q_WS_QWS)
+ QCOMPARE(ic.updateCallCount, 0); // The cursor position hasn't changed.
#endif
QCOMPARE(cursorRectangleSpy.count(), 0);
// Verify that the micro focus rect moves to the left as the cursor position
// is incremented.
for (int i = 1; i <= 5; ++i) {
- ic.updateReceived = false;
- ic.sendPreeditText(preeditText, i);
+ ic.clear();
+ sendPreeditText(preeditText, i);
currentRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect();
QVERIFY(previousRect.left() < currentRect.left());
-#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
- QCOMPARE(ic.updateReceived, true);
+#if defined(Q_WS_X11) || defined(Q_WS_QWS)
+ QVERIFY(ic.updateCallCount > 0);
#endif
QVERIFY(cursorRectangleSpy.count() > 0);
cursorRectangleSpy.clear();
@@ -2513,25 +2495,28 @@ void tst_qdeclarativetextedit::preeditMicroFocus()
// Verify that if there is no preedit cursor then the micro focus rect is the
// same as it would be if it were positioned at the end of the preedit text.
- ic.sendPreeditText(preeditText, 0);
- ic.updateReceived = false;
- ic.sendEvent(QInputMethodEvent(preeditText, QList<QInputMethodEvent::Attribute>()));
+ sendPreeditText(preeditText, 0);
+ ic.clear();
+ QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>());
+ QApplication::sendEvent(qApp->inputPanel()->inputItem(), &imEvent);
currentRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect();
QCOMPARE(currentRect, previousRect);
-#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
- QCOMPARE(ic.updateReceived, true);
+#if defined(Q_WS_X11) || defined(Q_WS_QWS)
+ QVERIFY(ic.updateCallCount > 0);
#endif
QVERIFY(cursorRectangleSpy.count() > 0);
}
void tst_qdeclarativetextedit::inputContextMouseHandler()
{
+ PlatformInputContext ic;
+ QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel());
+ inputPanelPrivate->testContext = &ic;
+
QString text = "supercalifragisiticexpialidocious!";
QGraphicsScene scene;
QGraphicsView view(&scene);
- MyInputContext ic;
- view.setInputContext(&ic);
QDeclarativeTextEdit edit;
edit.setPos(0, 0);
edit.setWidth(200);
@@ -2550,98 +2535,17 @@ void tst_qdeclarativetextedit::inputContextMouseHandler()
const qreal y = fm.height() / 2;
QPoint position2 = view.mapFromScene(edit.mapToScene(QPointF(fm.width(text.mid(0, 2)), y)));
- QPoint position8 = view.mapFromScene(edit.mapToScene(QPointF(fm.width(text.mid(0, 8)), y)));
- QPoint position20 = view.mapFromScene(edit.mapToScene(QPointF(fm.width(text.mid(0, 20)), y)));
- QPoint position27 = view.mapFromScene(edit.mapToScene(QPointF(fm.width(text.mid(0, 27)), y)));
- QPoint globalPosition2 = view.viewport()->mapToGlobal(position2);
- QPoint globalposition8 = view.viewport()->mapToGlobal(position8);
- QPoint globalposition20 = view.viewport()->mapToGlobal(position20);
- QPoint globalposition27 = view.viewport()->mapToGlobal(position27);
-
- ic.sendEvent(QInputMethodEvent(text.mid(12), QList<QInputMethodEvent::Attribute>()));
-
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, position2);
- QCOMPARE(ic.eventType, QEvent::MouseButtonDblClick);
- QCOMPARE(ic.eventPosition, position2);
- QCOMPARE(ic.eventGlobalPosition, globalPosition2);
- QCOMPARE(ic.eventButton, Qt::LeftButton);
- QCOMPARE(ic.eventModifiers, Qt::NoModifier);
- QVERIFY(ic.cursor < 0);
- ic.eventType = QEvent::None;
- QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, position2);
- QCOMPARE(ic.eventType, QEvent::MouseButtonPress);
- QCOMPARE(ic.eventPosition, position2);
- QCOMPARE(ic.eventGlobalPosition, globalPosition2);
- QCOMPARE(ic.eventButton, Qt::LeftButton);
- QCOMPARE(ic.eventModifiers, Qt::NoModifier);
- QVERIFY(ic.cursor < 0);
- ic.eventType = QEvent::None;
-
- { QMouseEvent mv(QEvent::MouseMove, position8, globalposition8, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
- QApplication::sendEvent(view.viewport(), &mv); }
- QCOMPARE(ic.eventType, QEvent::None);
-
- { QMouseEvent mv(QEvent::MouseMove, position27, globalposition27, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
- QApplication::sendEvent(view.viewport(), &mv); }
- QCOMPARE(ic.eventType, QEvent::MouseMove);
- QCOMPARE(ic.eventPosition, position27);
- QCOMPARE(ic.eventGlobalPosition, globalposition27);
- QCOMPARE(ic.eventButton, Qt::LeftButton);
- QCOMPARE(ic.eventModifiers, Qt::NoModifier);
- QVERIFY(ic.cursor >= 14 && ic.cursor <= 16); // 15 is expected but some platforms may be off by one.
- ic.eventType = QEvent::None;
-
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, position27);
- QCOMPARE(ic.eventType, QEvent::MouseButtonRelease);
- QCOMPARE(ic.eventPosition, position27);
- QCOMPARE(ic.eventGlobalPosition, globalposition27);
- QCOMPARE(ic.eventButton, Qt::LeftButton);
- QCOMPARE(ic.eventModifiers, Qt::NoModifier);
- QVERIFY(ic.cursor >= 14 && ic.cursor <= 16);
- ic.eventType = QEvent::None;
-
- // And in the other direction.
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, position27);
- QCOMPARE(ic.eventType, QEvent::MouseButtonDblClick);
- QCOMPARE(ic.eventPosition, position27);
- QCOMPARE(ic.eventGlobalPosition, globalposition27);
- QCOMPARE(ic.eventButton, Qt::LeftButton);
- QCOMPARE(ic.eventModifiers, Qt::ControlModifier);
- QVERIFY(ic.cursor >= 14 && ic.cursor <= 16);
- ic.eventType = QEvent::None;
-
- QTest::mousePress(view.viewport(), Qt::RightButton, Qt::ControlModifier, position27);
- QCOMPARE(ic.eventType, QEvent::MouseButtonPress);
- QCOMPARE(ic.eventPosition, position27);
- QCOMPARE(ic.eventGlobalPosition, globalposition27);
- QCOMPARE(ic.eventButton, Qt::RightButton);
- QCOMPARE(ic.eventModifiers, Qt::ControlModifier);
- QVERIFY(ic.cursor >= 14 && ic.cursor <= 16);
- ic.eventType = QEvent::None;
-
- { QMouseEvent mv(QEvent::MouseMove, position20, globalposition20, Qt::RightButton, Qt::RightButton,Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &mv); }
- QCOMPARE(ic.eventType, QEvent::MouseMove);
- QCOMPARE(ic.eventPosition, position20);
- QCOMPARE(ic.eventGlobalPosition, globalposition20);
- QCOMPARE(ic.eventButton, Qt::RightButton);
- QCOMPARE(ic.eventModifiers, Qt::ControlModifier);
- QVERIFY(ic.cursor >= 7 && ic.cursor <= 9);
- ic.eventType = QEvent::None;
-
- { QMouseEvent mv(QEvent::MouseMove, position2, globalPosition2, Qt::RightButton, Qt::RightButton,Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &mv); }
- QCOMPARE(ic.eventType, QEvent::None);
+ QInputMethodEvent inputEvent(text.mid(0, 12), QList<QInputMethodEvent::Attribute>());
+ QApplication::sendEvent(&view, &inputEvent);
+ QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, position2);
QTest::mouseRelease(view.viewport(), Qt::RightButton, Qt::ControlModifier, position2);
- QCOMPARE(ic.eventType, QEvent::MouseButtonRelease);
- QCOMPARE(ic.eventPosition, position2);
- QCOMPARE(ic.eventGlobalPosition, globalPosition2);
- QCOMPARE(ic.eventButton, Qt::RightButton);
- QCOMPARE(ic.eventModifiers, Qt::ControlModifier);
- QVERIFY(ic.cursor < 0);
- ic.eventType = QEvent::None;
+ QApplication::processEvents();
+
+ QCOMPARE(ic.m_action, QInputPanel::Click);
+ QCOMPARE(ic.m_invokeActionCallCount, 1);
+ QCOMPARE(ic.m_cursorPosition, 2);
}
void tst_qdeclarativetextedit::inputMethodComposing()
@@ -2650,8 +2554,6 @@ void tst_qdeclarativetextedit::inputMethodComposing()
QGraphicsScene scene;
QGraphicsView view(&scene);
- MyInputContext ic;
- view.setInputContext(&ic);
QDeclarativeTextEdit edit;
edit.setWidth(200);
edit.setText(text.mid(0, 12));
@@ -2668,15 +2570,24 @@ void tst_qdeclarativetextedit::inputMethodComposing()
QCOMPARE(edit.isInputMethodComposing(), false);
- ic.sendEvent(QInputMethodEvent(text.mid(3), QList<QInputMethodEvent::Attribute>()));
+ {
+ QInputMethodEvent imEvent(text.mid(3), QList<QInputMethodEvent::Attribute>());
+ QApplication::sendEvent(&view, &imEvent);
+ }
QCOMPARE(edit.isInputMethodComposing(), true);
QCOMPARE(spy.count(), 1);
- ic.sendEvent(QInputMethodEvent(text.mid(12), QList<QInputMethodEvent::Attribute>()));
+ {
+ QInputMethodEvent imEvent(text.mid(12), QList<QInputMethodEvent::Attribute>());
+ QApplication::sendEvent(&view, &imEvent);
+ }
QCOMPARE(edit.isInputMethodComposing(), true);
QCOMPARE(spy.count(), 1);
- ic.sendEvent(QInputMethodEvent());
+ {
+ QInputMethodEvent imEvent;
+ QApplication::sendEvent(&view, &imEvent);
+ }
QCOMPARE(edit.isInputMethodComposing(), false);
QCOMPARE(spy.count(), 2);
}