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.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 604f508..afbaaac 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -882,6 +882,7 @@ 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) {
@@ -893,15 +894,20 @@ 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());
d->control->moveCursor(cursor, mark);
+ event->setAccepted(true);
}
void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
d->control->moveCursor(d->xToPos(event->pos().x()), true);
+ event->setAccepted(true);
}
/*!
@@ -913,8 +919,10 @@ 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->focusOnPress);
- d->control->processEvent(event);
+ qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus);
+ d->clickCausedFocus = false;
+ if (!event->isAccepted())
+ QDeclarativePaintedItem::mouseReleaseEvent(event);
}
bool QDeclarativeTextInput::event(QEvent* ev)
@@ -935,8 +943,8 @@ bool QDeclarativeTextInput::event(QEvent* ev)
updateSize();
}
if(!handled)
- return QDeclarativePaintedItem::event(ev);
- return true;
+ handled = QDeclarativePaintedItem::event(ev);
+ return handled;
}
void QDeclarativeTextInput::geometryChanged(const QRectF &newGeometry,
@@ -1018,6 +1026,8 @@ QVariant QDeclarativeTextInput::inputMethodQuery(Qt::InputMethodQuery property)
{
Q_D(const QDeclarativeTextInput);
switch(property) {
+ case Qt::ImMicroFocus:
+ return d->control->cursorRect();
case Qt::ImFont:
return font();
case Qt::ImCursorPosition:
@@ -1233,9 +1243,7 @@ void QDeclarativeTextInput::updateSize(bool needsRedraw)
int cursorWidth = d->control->cursorWidth();
if(d->cursorItem)
cursorWidth = d->cursorItem->width();
- //### Is QFontMetrics too slow?
- QFontMetricsF fm(d->font);
- setImplicitWidth(fm.width(d->control->displayText())+cursorWidth);
+ setImplicitWidth(d->control->naturalTextWidth() + cursorWidth);
setContentsSize(QSize(width(), height()));//Repaints if changed
if(w==width() && h==height() && needsRedraw){
clearCache();