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.cpp131
1 files changed, 124 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 1ac1b4e..47cd110 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -886,7 +886,6 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev)
void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
- bool hadFocus = hasFocus();
if(d->focusOnPress){
QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope?
while(p) {
@@ -896,8 +895,6 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
setFocus(true);
}
- if (!hadFocus && hasFocus())
- d->clickCausedFocus = true;
bool mark = event->modifiers() & Qt::ShiftModifier;
int cursor = d->xToPos(event->pos().x());
@@ -923,10 +920,7 @@ Handles the given mouse \a event.
void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
- QWidget *widget = event->widget();
- if (widget && !d->control->isReadOnly() && boundingRect().contains(event->pos()))
- qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus);
- d->clickCausedFocus = false;
+ d->control->processEvent(event);
if (!event->isAccepted())
QDeclarativePaintedItem::mouseReleaseEvent(event);
}
@@ -1175,6 +1169,129 @@ void QDeclarativeTextInput::moveCursorSelection(int position)
d->control->moveCursor(position, true);
}
+/*!
+ \qmlmethod void TextInput::openSoftwareInputPanel()
+
+ Opens software input panels like virtual keyboards for typing, useful 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.
+
+ Only relevant on platforms, which provide virtual keyboards.
+
+ \code
+ import Qt 4.7
+ TextInput {
+ id: textInput
+ text: "Hello world!"
+ showInputPanelOnFocus: false
+ MouseArea {
+ anchors.fill: parent
+ onClicked: textInput.openSoftwareInputPanel()
+ }
+ onFocusChanged: if (!focus) closeSoftwareInputPanel()
+ }
+ \endcode
+*/
+void QDeclarativeTextInput::openSoftwareInputPanel()
+{
+ QEvent event(QEvent::RequestSoftwareInputPanel);
+ if (qApp) {
+ if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
+ if (view->scene() && view->scene() == scene()) {
+ QApplication::sendEvent(view, &event);
+ }
+ }
+ }
+}
+
+/*!
+ \qmlmethod void TextInput::closeSoftwareInputPanel()
+
+ Closes a software input panel like a virtual keyboard shown on the screen, useful
+ 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.
+
+ Only relevant on platforms, which provide virtual keyboards.
+
+ \code
+ import Qt 4.7
+ TextInput {
+ id: textInput
+ text: "Hello world!"
+ showInputPanelOnFocus: false
+ MouseArea {
+ anchors.fill: parent
+ onClicked: textInput.openSoftwareInputPanel()
+ }
+ onFocusChanged: if (!focus) closeSoftwareInputPanel()
+ }
+ \endcode
+*/
+void QDeclarativeTextInput::closeSoftwareInputPanel()
+{
+ QEvent event(QEvent::CloseSoftwareInputPanel);
+ if (qApp) {
+ QEvent event(QEvent::CloseSoftwareInputPanel);
+ if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
+ if (view->scene() && view->scene() == scene()) {
+ QApplication::sendEvent(view, &event);
+ }
+ }
+ }
+}
+
+/*!
+ \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()) {
+ openSoftwareInputPanel();
+ }
+ QDeclarativePaintedItem::focusInEvent(event);
+}
+
+void QDeclarativeTextInput::focusOutEvent(QFocusEvent *event)
+{
+ Q_D(const QDeclarativeTextInput);
+ if (d->showInputPanelOnFocus && !isReadOnly()) {
+ closeSoftwareInputPanel();
+ }
+ QDeclarativePaintedItem::focusOutEvent(event);
+}
+
void QDeclarativeTextInputPrivate::init()
{
Q_Q(QDeclarativeTextInput);