summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetextinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetextinput.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp136
1 files changed, 84 insertions, 52 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 7b96c0c..1202101 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -891,6 +891,22 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev)
QDeclarativePaintedItem::keyPressEvent(ev);
}
+/*!
+\overload
+Handles the given mouse \a event.
+*/
+void QDeclarativeTextInput::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ Q_D(QDeclarativeTextInput);
+ if (d->selectByMouse) {
+ int cursor = d->xToPos(event->pos().x());
+ d->control->selectWordAtPos(cursor);
+ event->setAccepted(true);
+ } else {
+ QDeclarativePaintedItem::mouseDoubleClickEvent(event);
+ }
+}
+
void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
@@ -903,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);
@@ -933,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);
@@ -949,10 +980,9 @@ bool QDeclarativeTextInput::event(QEvent* ev)
case QEvent::GraphicsSceneMousePress:
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
+ case QEvent::GraphicsSceneMouseDoubleClick:
break;
default:
- if (ev->type() == QEvent::GraphicsSceneMouseDoubleClick && !d->selectByMouse)
- break;
handled = d->control->processEvent(ev);
if (ev->type() == QEvent::InputMethod)
updateSize();
@@ -1203,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()
{
@@ -1243,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()
{
@@ -1277,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);
}
@@ -1313,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);
}