summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/QmlChanges.txt1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp109
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p_p.h12
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp117
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h11
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp83
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp83
9 files changed, 285 insertions, 141 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 0df5f10..5735b1e 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -2,7 +2,6 @@
The changes below are pre Qt 4.7.0 RC
TextInput and TextEdit:
- - showInputPanelOnFocus property added
- openSoftwareInputPanel() and closeSoftwareInputPanel() functions added
Flickable:
- overShoot is replaced by boundsBehavior enumeration
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index ffb7dfe..48826ff 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -1106,9 +1106,15 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
p = p->parentItem();
}
setFocus(true);
- if (hasFocus() == hadFocus && d->showInputPanelOnFocus && !isReadOnly()) {
- // re-open input panel on press if already focused
- openSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (hasFocus() && hadFocus && !isReadOnly()) {
+ // re-open input panel on press if already focused
+ openSoftwareInputPanel();
+ }
+ } else { // show input panel on click
+ if (hasFocus() && !hadFocus) {
+ d->clickCausedFocus = true;
+ }
}
}
if (event->type() != QEvent::GraphicsSceneMouseDoubleClick || d->selectByMouse)
@@ -1125,6 +1131,17 @@ void QDeclarativeTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextEdit);
d->control->processEvent(event, QPointF(0, -d->yoff));
+ if (!d->showInputPanelOnFocus) { // input panel on click
+ if (d->focusOnPress && !isReadOnly() && boundingRect().contains(event->pos())) {
+ if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
+ if (view->scene() && view->scene() == scene()) {
+ qt_widget_private(view)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus);
+ }
+ }
+ }
+ }
+ d->clickCausedFocus = false;
+
if (!event->isAccepted())
QDeclarativePaintedItem::mouseReleaseEvent(event);
}
@@ -1372,10 +1389,14 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption()
customizing when you want the input keyboard to be shown and hidden in
your application.
- By default input panels are shown when TextEdit element gains focus and hidden
- when the focus is lost. You can disable the automatic behavior by setting the
- property showInputPanelOnFocus to false and use functions openSoftwareInputPanel()
- and closeSoftwareInputPanel() to implement the behavior you want.
+ By default the opening of input panels follows the platform style. On Symbian^1 and
+ Symbian^3 -based devices the panels are opened by clicking TextEdit and need to be
+ manually closed by the user. On other platforms the panels are automatically opened
+ when TextEdit element gains focus and closed when the focus is lost.
+
+ . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
+ the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
@@ -1384,12 +1405,19 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption()
TextEdit {
id: textEdit
text: "Hello world!"
- showInputPanelOnFocus: false
+ focusOnPress: false
MouseArea {
anchors.fill: parent
- onClicked: textEdit.openSoftwareInputPanel()
+ onClicked: {
+ if (!textEdit.focus) {
+ textEdit.focus = true;
+ textEdit.openSoftwareInputPanel();
+ } else {
+ textEdit.focus = false;
+ textEdit.closeSoftwareInputPanel();
+ }
+ }
}
- onFocusChanged: if (!focus) closeSoftwareInputpanel()
}
\endcode
*/
@@ -1412,10 +1440,14 @@ void QDeclarativeTextEdit::openSoftwareInputPanel()
for customizing when you want the input keyboard to be shown and hidden in
your application.
- By default input panels are shown when TextEdit element gains focus and hidden
- when the focus is lost. You can disable the automatic behavior by setting the
- property showInputPanelOnFocus to false and use functions openSoftwareInputPanel()
- and closeSoftwareInputPanel() to implement the behavior you want.
+ By default the opening of input panels follows the platform style. On Symbian^1 and
+ Symbian^3 -based devices the panels are opened by clicking TextEdit and need to be
+ manually closed by the user. On other platforms the panels are automatically opened
+ when TextEdit element gains focus and closed when the focus is lost.
+
+ . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
+ the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
@@ -1424,12 +1456,19 @@ void QDeclarativeTextEdit::openSoftwareInputPanel()
TextEdit {
id: textEdit
text: "Hello world!"
- showInputPanelOnFocus: false
+ focusOnPress: false
MouseArea {
anchors.fill: parent
- onClicked: textEdit.openSoftwareInputPanel()
+ onClicked: {
+ if (!textEdit.focus) {
+ textEdit.focus = true;
+ textEdit.openSoftwareInputPanel();
+ } else {
+ textEdit.focus = false;
+ textEdit.closeSoftwareInputPanel();
+ }
+ }
}
- onFocusChanged: if (!focus) closeSoftwareInputpanel()
}
\endcode
*/
@@ -1445,35 +1484,13 @@ void QDeclarativeTextEdit::closeSoftwareInputPanel()
}
}
-/*!
- \qmlproperty bool TextEdit::showInputPanelOnFocus
- Whether input panels are automatically shown when TextEdit element gains
- focus and hidden when focus is lost. By default this is set to true.
-
- Only relevant on platforms, which provide virtual keyboards.
-*/
-bool QDeclarativeTextEdit::showInputPanelOnFocus() const
-{
- Q_D(const QDeclarativeTextEdit);
- return d->showInputPanelOnFocus;
-}
-
-void QDeclarativeTextEdit::setShowInputPanelOnFocus(bool showOnFocus)
-{
- Q_D(QDeclarativeTextEdit);
- if (d->showInputPanelOnFocus == showOnFocus)
- return;
-
- d->showInputPanelOnFocus = showOnFocus;
-
- emit showInputPanelOnFocusChanged(d->showInputPanelOnFocus);
-}
-
void QDeclarativeTextEdit::focusInEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextEdit);
- if (d->showInputPanelOnFocus && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
- openSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (d->focusOnPress && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
+ openSoftwareInputPanel();
+ }
}
QDeclarativePaintedItem::focusInEvent(event);
}
@@ -1481,8 +1498,10 @@ void QDeclarativeTextEdit::focusInEvent(QFocusEvent *event)
void QDeclarativeTextEdit::focusOutEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextEdit);
- if (d->showInputPanelOnFocus && !isReadOnly()) {
- closeSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (d->focusOnPress && !isReadOnly()) {
+ closeSoftwareInputPanel();
+ }
}
QDeclarativePaintedItem::focusOutEvent(event);
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index 3abfc35..3846d49 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -86,7 +86,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem
Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged)
- Q_PROPERTY(bool showInputPanelOnFocus READ showInputPanelOnFocus WRITE setShowInputPanelOnFocus NOTIFY showInputPanelOnFocusChanged)
Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
@@ -167,9 +166,6 @@ public:
bool focusOnPress() const;
void setFocusOnPress(bool on);
- bool showInputPanelOnFocus() const;
- void setShowInputPanelOnFocus(bool showOnFocus);
-
bool persistentSelection() const;
void setPersistentSelection(bool on);
@@ -222,7 +218,6 @@ Q_SIGNALS:
void persistentSelectionChanged(bool isPersistentSelection);
void textMarginChanged(qreal textMargin);
void selectByMouseChanged(bool selectByMouse);
- void showInputPanelOnFocusChanged(bool showOnFocus);
public Q_SLOTS:
void selectAll();
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
index 8e1d630..4092e65 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
@@ -70,12 +70,17 @@ public:
QDeclarativeTextEditPrivate()
: color("black"), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop),
imgDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true),
- showInputPanelOnFocus(true), persistentSelection(true), textMargin(0.0), lastSelectionStart(0),
- lastSelectionEnd(0), cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText),
- document(0), wrapMode(QDeclarativeTextEdit::NoWrap),
+ showInputPanelOnFocus(true), clickCausedFocus(false), persistentSelection(true), textMargin(0.0),
+ lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0),
+ format(QDeclarativeTextEdit::AutoText), document(0), wrapMode(QDeclarativeTextEdit::NoWrap),
selectByMouse(false),
yoff(0)
{
+#ifdef Q_OS_SYMBIAN
+ if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
+ showInputPanelOnFocus = false;
+ }
+#endif
}
void init();
@@ -102,6 +107,7 @@ public:
bool cursorVisible : 1;
bool focusOnPress : 1;
bool showInputPanelOnFocus : 1;
+ bool clickCausedFocus : 1;
bool persistentSelection : 1;
qreal textMargin;
int lastSelectionStart;
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 91ef0a2..1202101 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -919,12 +919,17 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
p = p->parentItem();
}
setFocus(true);
- if (hasFocus() == hadFocus && d->showInputPanelOnFocus && !isReadOnly()) {
- // re-open input panel on press w already focused
- openSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (hasFocus() && hadFocus && !isReadOnly()) {
+ // re-open input panel on press if already focused
+ openSoftwareInputPanel();
+ }
+ } else { // show input panel on click
+ if (hasFocus() && !hadFocus) {
+ d->clickCausedFocus = true;
+ }
}
}
-
bool mark = event->modifiers() & Qt::ShiftModifier;
int cursor = d->xToPos(event->pos().x());
d->control->moveCursor(cursor, mark);
@@ -949,6 +954,16 @@ Handles the given mouse \a event.
void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
+ if (!d->showInputPanelOnFocus) { // input panel on click
+ if (d->focusOnPress && !isReadOnly() && boundingRect().contains(event->pos())) {
+ if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
+ if (view->scene() && view->scene() == scene()) {
+ qt_widget_private(view)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus);
+ }
+ }
+ }
+ }
+ d->clickCausedFocus = false;
d->control->processEvent(event);
if (!event->isAccepted())
QDeclarativePaintedItem::mouseReleaseEvent(event);
@@ -1218,26 +1233,37 @@ void QDeclarativeTextInput::moveCursorSelection(int position)
customizing when you want the input keyboard to be shown and hidden in
your application.
- By default input panels are shown when TextInput element gains focus and hidden
- when the focus is lost. You can disable the automatic behavior by setting the
- property showInputPanelOnFocus to false and use functions openSoftwareInputPanel()
- and closeSoftwareInputPanel() to implement the behavior you want.
+ By default the opening of input panels follows the platform style. On Symbian^1 and
+ Symbian^3 -based devices the panels are opened by clicking TextInput and need to be
+ manually closed by the user. On other platforms the panels are automatically opened
+ when TextInput element gains focus and closed when the focus is lost.
+
+ . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
+ the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
- \code
+ \qml
import Qt 4.7
TextInput {
id: textInput
text: "Hello world!"
- showInputPanelOnFocus: false
+ focusOnPress: false
MouseArea {
anchors.fill: parent
- onClicked: textInput.openSoftwareInputPanel()
+ onClicked: {
+ if (!textInput.focus) {
+ textInput.focus = true;
+ textInput.openSoftwareInputPanel();
+ } else {
+ textInput.focus = false;
+ textInput.closeSoftwareInputPanel();
+ }
+ }
}
- onFocusChanged: if (!focus) closeSoftwareInputPanel()
}
- \endcode
+ \endqml
*/
void QDeclarativeTextInput::openSoftwareInputPanel()
{
@@ -1258,26 +1284,37 @@ void QDeclarativeTextInput::openSoftwareInputPanel()
for customizing when you want the input keyboard to be shown and hidden in
your application.
- By default input panels are shown when TextInput element gains focus and hidden
- when the focus is lost. You can disable the automatic behavior by setting the
- property showInputPanelOnFocus to false and use functions openSoftwareInputPanel()
- and closeSoftwareInputPanel() to implement the behavior you want.
+ By default the opening of input panels follows the platform style. On Symbian^1 and
+ Symbian^3 -based devices the panels are opened by clicking TextInput and need to be
+ manually closed by the user. On other platforms the panels are automatically opened
+ when TextInput element gains focus and closed when the focus is lost.
+
+ . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
+ the behavior you want.
Only relevant on platforms, which provide virtual keyboards.
- \code
+ \qml
import Qt 4.7
TextInput {
id: textInput
text: "Hello world!"
- showInputPanelOnFocus: false
+ focusOnPress: false
MouseArea {
anchors.fill: parent
- onClicked: textInput.openSoftwareInputPanel()
+ onClicked: {
+ if (!textInput.focus) {
+ textInput.focus = true;
+ textInput.openSoftwareInputPanel();
+ } else {
+ textInput.focus = false;
+ textInput.closeSoftwareInputPanel();
+ }
+ }
}
- onFocusChanged: if (!focus) closeSoftwareInputPanel()
}
- \endcode
+ \endqml
*/
void QDeclarativeTextInput::closeSoftwareInputPanel()
{
@@ -1292,35 +1329,13 @@ void QDeclarativeTextInput::closeSoftwareInputPanel()
}
}
-/*!
- \qmlproperty bool TextInput::showInputPanelOnFocus
- Whether input panels are automatically shown when TextInput element gains
- focus and hidden when focus is lost. By default this is set to true.
-
- Only relevant on platforms, which provide virtual keyboards.
-*/
-bool QDeclarativeTextInput::showInputPanelOnFocus() const
-{
- Q_D(const QDeclarativeTextInput);
- return d->showInputPanelOnFocus;
-}
-
-void QDeclarativeTextInput::setShowInputPanelOnFocus(bool showOnFocus)
-{
- Q_D(QDeclarativeTextInput);
- if (d->showInputPanelOnFocus == showOnFocus)
- return;
-
- d->showInputPanelOnFocus = showOnFocus;
-
- emit showInputPanelOnFocusChanged(d->showInputPanelOnFocus);
-}
-
void QDeclarativeTextInput::focusInEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextInput);
- if (d->showInputPanelOnFocus && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
- openSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (d->focusOnPress && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
+ openSoftwareInputPanel();
+ }
}
QDeclarativePaintedItem::focusInEvent(event);
}
@@ -1328,8 +1343,10 @@ void QDeclarativeTextInput::focusInEvent(QFocusEvent *event)
void QDeclarativeTextInput::focusOutEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextInput);
- if (d->showInputPanelOnFocus && !isReadOnly()) {
- closeSoftwareInputPanel();
+ if (d->showInputPanelOnFocus) {
+ if (d->focusOnPress && !isReadOnly()) {
+ closeSoftwareInputPanel();
+ }
}
QDeclarativePaintedItem::focusOutEvent(event);
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 4b857ca..e34634a 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -88,7 +88,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged)
- Q_PROPERTY(bool showInputPanelOnFocus READ showInputPanelOnFocus WRITE setShowInputPanelOnFocus NOTIFY showInputPanelOnFocusChanged)
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
@@ -177,9 +176,6 @@ public:
bool focusOnPress() const;
void setFocusOnPress(bool);
- bool showInputPanelOnFocus() const;
- void setShowInputPanelOnFocus(bool showOnFocus);
-
bool autoScroll() const;
void setAutoScroll(bool);
@@ -216,7 +212,6 @@ Q_SIGNALS:
void focusOnPressChanged(bool focusOnPress);
void autoScrollChanged(bool autoScroll);
void selectByMouseChanged(bool selectByMouse);
- void showInputPanelOnFocusChanged(bool showOnFocus);
protected:
virtual void geometryChanged(const QRectF &newGeometry,
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index f44d014..6865147 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -72,9 +72,15 @@ public:
color((QRgb)0), style(QDeclarativeText::Normal),
styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft),
hscroll(0), oldScroll(0), focused(false), focusOnPress(true),
- showInputPanelOnFocus(true), cursorVisible(false), autoScroll(true),
- selectByMouse(false)
+ showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
+ autoScroll(true), selectByMouse(false)
{
+#ifdef Q_OS_SYMBIAN
+ if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
+ showInputPanelOnFocus = false;
+ }
+#endif
+
}
~QDeclarativeTextInputPrivate()
@@ -116,6 +122,7 @@ public:
bool focused;
bool focusOnPress;
bool showInputPanelOnFocus;
+ bool clickCausedFocus;
bool cursorVisible;
bool autoScroll;
bool selectByMouse;
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 47c5b63..fbab30e 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -50,6 +50,7 @@
#include <QtDeclarative/qdeclarativeexpression.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <private/qdeclarativetextedit_p.h>
+#include <private/qdeclarativetextedit_p_p.h>
#include <QFontMetrics>
#include <QDeclarativeView>
#include <QStyle>
@@ -86,7 +87,8 @@ private slots:
void delegateLoading();
void navigation();
void readOnly();
- void sendRequestSoftwareInputPanelEvent();
+ void openInputPanelOnClick();
+ void openInputPanelOnFocus();
void geometrySignals();
private:
void simulateKey(QDeclarativeView *, int key);
@@ -817,14 +819,14 @@ public:
bool closeInputPanelReceived;
};
-void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
+void tst_qdeclarativetextedit::openInputPanelOnClick()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
MyInputContext ic;
view.setInputContext(&ic);
QDeclarativeTextEdit edit;
- QSignalSpy inputPanelonFocusSpy(&edit, SIGNAL(showInputPanelOnFocusChanged(bool)));
+ QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool)));
edit.setText("Hello world");
edit.setPos(0, 0);
scene.addItem(&edit);
@@ -834,7 +836,58 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
QTest::qWaitForWindowShown(&view);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
- QVERIFY(edit.showInputPanelOnFocus());
+ QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&edit);
+ QDeclarativeTextEditPrivate *editPrivate = static_cast<QDeclarativeTextEditPrivate*>(pri);
+
+ // input panel on click
+ editPrivate->showInputPanelOnFocus = false;
+
+ QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
+ view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
+ QApplication::processEvents();
+ if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) {
+ QCOMPARE(ic.openInputPanelReceived, false);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
+ QApplication::processEvents();
+ QCOMPARE(ic.openInputPanelReceived, true);
+ } else if (behavior == QStyle::RSIP_OnMouseClick) {
+ QCOMPARE(ic.openInputPanelReceived, true);
+ }
+ ic.openInputPanelReceived = false;
+
+ // focus should not cause input panels to open or close
+ edit.setFocus(false);
+ edit.setFocus(true);
+ edit.setFocus(false);
+ edit.setFocus(true);
+ edit.setFocus(false);
+ QCOMPARE(ic.openInputPanelReceived, false);
+ QCOMPARE(ic.closeInputPanelReceived, false);
+}
+
+void tst_qdeclarativetextedit::openInputPanelOnFocus()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ MyInputContext ic;
+ view.setInputContext(&ic);
+ QDeclarativeTextEdit edit;
+ QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool)));
+ edit.setText("Hello world");
+ edit.setPos(0, 0);
+ scene.addItem(&edit);
+ view.show();
+ qApp->setAutoSipEnabled(true);
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
+
+ QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&edit);
+ QDeclarativeTextEditPrivate *editPrivate = static_cast<QDeclarativeTextEditPrivate*>(pri);
+ editPrivate->showInputPanelOnFocus = true;
+
+ QVERIFY(edit.focusOnPress());
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
@@ -867,9 +920,9 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.closeInputPanelReceived, true);
ic.closeInputPanelReceived = false;
- // no input panel events if showInputPanelOnFocus is false
- edit.setShowInputPanelOnFocus(false);
- QCOMPARE(inputPanelonFocusSpy.count(),1);
+ // no automatic input panel events if focusOnPress is false
+ edit.setFocusOnPress(false);
+ QCOMPARE(focusOnPressSpy.count(),1);
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos()));
edit.setFocus(false);
@@ -877,8 +930,8 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
- edit.setShowInputPanelOnFocus(false);
- QCOMPARE(inputPanelonFocusSpy.count(),1);
+ edit.setFocusOnPress(false);
+ QCOMPARE(focusOnPressSpy.count(),1);
// one show input panel event when openSoftwareInputPanel is called
edit.openSoftwareInputPanel();
@@ -892,14 +945,17 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.closeInputPanelReceived, true);
ic.openInputPanelReceived = false;
- // set showInputPanelOnFocus back to true
- edit.setShowInputPanelOnFocus(true);
- QCOMPARE(inputPanelonFocusSpy.count(),2);
+ // set focusOnPress back to true
+ edit.setFocusOnPress(true);
+ QCOMPARE(focusOnPressSpy.count(),2);
edit.setFocus(false);
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, true);
ic.closeInputPanelReceived = false;
+ edit.setFocusOnPress(true);
+ QCOMPARE(focusOnPressSpy.count(),2);
+
// active window focus reason should not cause input panel to open
QGraphicsObject * editObject = qobject_cast<QGraphicsObject*>(&edit);
editObject->setFocus(Qt::ActiveWindowFocusReason);
@@ -910,9 +966,6 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent()
edit.setFocus(true);
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
-
- edit.setShowInputPanelOnFocus(true);
- QCOMPARE(inputPanelonFocusSpy.count(),2);
}
void tst_qdeclarativetextedit::geometrySignals()
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index c943c89..3cb4da0 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -45,6 +45,7 @@
#include <QFile>
#include <QtDeclarative/qdeclarativeview.h>
#include <private/qdeclarativetextinput_p.h>
+#include <private/qdeclarativetextinput_p_p.h>
#include <QDebug>
#include <QStyle>
#include <QInputContext>
@@ -74,7 +75,8 @@ private slots:
void navigation();
void readOnly();
- void sendRequestSoftwareInputPanelEvent();
+ void openInputPanelOnClick();
+ void openInputPanelOnFocus();
void setHAlignClearCache();
void focusOutClearSelection();
@@ -763,14 +765,14 @@ public:
bool closeInputPanelReceived;
};
-void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
+void tst_qdeclarativetextinput::openInputPanelOnClick()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
MyInputContext ic;
view.setInputContext(&ic);
QDeclarativeTextInput input;
- QSignalSpy inputPanelonFocusSpy(&input, SIGNAL(showInputPanelOnFocusChanged(bool)));
+ QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool)));
input.setText("Hello world");
input.setPos(0, 0);
scene.addItem(&input);
@@ -780,7 +782,58 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
QTest::qWaitForWindowShown(&view);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
- QVERIFY(input.showInputPanelOnFocus());
+ QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&input);
+ QDeclarativeTextInputPrivate *inputPrivate = static_cast<QDeclarativeTextInputPrivate*>(pri);
+
+ // input panel on click
+ inputPrivate->showInputPanelOnFocus = false;
+
+ QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
+ view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos()));
+ QApplication::processEvents();
+ if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) {
+ QCOMPARE(ic.openInputPanelReceived, false);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos()));
+ QApplication::processEvents();
+ QCOMPARE(ic.openInputPanelReceived, true);
+ } else if (behavior == QStyle::RSIP_OnMouseClick) {
+ QCOMPARE(ic.openInputPanelReceived, true);
+ }
+ ic.openInputPanelReceived = false;
+
+ // focus should not cause input panels to open or close
+ input.setFocus(false);
+ input.setFocus(true);
+ input.setFocus(false);
+ input.setFocus(true);
+ input.setFocus(false);
+ QCOMPARE(ic.openInputPanelReceived, false);
+ QCOMPARE(ic.closeInputPanelReceived, false);
+}
+
+void tst_qdeclarativetextinput::openInputPanelOnFocus()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ MyInputContext ic;
+ view.setInputContext(&ic);
+ QDeclarativeTextInput input;
+ QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool)));
+ input.setText("Hello world");
+ input.setPos(0, 0);
+ scene.addItem(&input);
+ view.show();
+ qApp->setAutoSipEnabled(true);
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
+
+ QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&input);
+ QDeclarativeTextInputPrivate *inputPrivate = static_cast<QDeclarativeTextInputPrivate*>(pri);
+ inputPrivate->showInputPanelOnFocus = true;
+
+ QVERIFY(input.focusOnPress());
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
@@ -813,9 +866,9 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.closeInputPanelReceived, true);
ic.closeInputPanelReceived = false;
- // no input panel events if showInputPanelOnFocus is false
- input.setShowInputPanelOnFocus(false);
- QCOMPARE(inputPanelonFocusSpy.count(),1);
+ // no automatic input panel events if focusOnPress is false
+ input.setFocusOnPress(false);
+ QCOMPARE(focusOnPressSpy.count(),1);
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos()));
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos()));
input.setFocus(false);
@@ -823,8 +876,8 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
- input.setShowInputPanelOnFocus(false);
- QCOMPARE(inputPanelonFocusSpy.count(),1);
+ input.setFocusOnPress(false);
+ QCOMPARE(focusOnPressSpy.count(),1);
// one show input panel event when openSoftwareInputPanel is called
input.openSoftwareInputPanel();
@@ -838,14 +891,17 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
QCOMPARE(ic.closeInputPanelReceived, true);
ic.openInputPanelReceived = false;
- // set showInputPanelOnFocus back to true
- input.setShowInputPanelOnFocus(true);
- QCOMPARE(inputPanelonFocusSpy.count(),2);
+ // set focusOnPress back to true
+ input.setFocusOnPress(true);
+ QCOMPARE(focusOnPressSpy.count(),2);
input.setFocus(false);
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, true);
ic.closeInputPanelReceived = false;
+ input.setFocusOnPress(true);
+ QCOMPARE(focusOnPressSpy.count(),2);
+
// active window focus reason should not cause input panel to open
QGraphicsObject * inputObject = qobject_cast<QGraphicsObject*>(&input);
inputObject->setFocus(Qt::ActiveWindowFocusReason);
@@ -856,9 +912,6 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent()
input.setFocus(true);
QCOMPARE(ic.openInputPanelReceived, false);
QCOMPARE(ic.closeInputPanelReceived, false);
-
- input.setShowInputPanelOnFocus(true);
- QCOMPARE(inputPanelonFocusSpy.count(),2);
}
class MyTextInput : public QDeclarativeTextInput