From 9b7b90cf550abd107b03ce3d6d8e4ff87401bcd8 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Tue, 22 May 2012 20:08:00 +0200 Subject: Fix Qt 5 to-do's in QGraphicsProxyWidget Task-number: QTBUG-25091 Change-Id: Ic4160f90f69167d40ee1e569562d25eb009615aa Reviewed-by: Bradley T. Hughes Reviewed-by: Lars Knoll --- src/widgets/graphicsview/qgraphicsitem.cpp | 23 ------ src/widgets/graphicsview/qgraphicsitem_p.h | 2 - src/widgets/graphicsview/qgraphicsproxywidget.cpp | 90 ++++++++++++----------- src/widgets/graphicsview/qgraphicsproxywidget.h | 6 +- src/widgets/graphicsview/qgraphicsproxywidget_p.h | 3 - 5 files changed, 50 insertions(+), 74 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 56ea4f986c..d1be832b9a 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1074,22 +1074,6 @@ void QGraphicsItemPrivate::updateSceneTransformFromParent() dirtySceneTransform = 0; } -/*! - \internal - - This helper function helped us add input method query support in - Qt 4.4.1 without having to reimplement the inputMethodQuery() - function in QGraphicsProxyWidget. ### Qt 5: Remove. We cannot - remove it in 4.5+ even if we do reimplement the function properly, - because apps compiled with 4.4 will not be able to call the - reimplementation. -*/ -QVariant QGraphicsItemPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const -{ - Q_UNUSED(query); - return QVariant(); -} - /*! \internal @@ -7331,13 +7315,6 @@ void QGraphicsItem::inputMethodEvent(QInputMethodEvent *event) */ QVariant QGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const { - if (isWidget()) { - // ### Qt 5: Remove. The reimplementation in - // QGraphicsProxyWidget solves this problem (but requires a - // recompile to take effect). - return d_ptr->inputMethodQueryHelper(query); - } - Q_UNUSED(query); return QVariant(); } diff --git a/src/widgets/graphicsview/qgraphicsitem_p.h b/src/widgets/graphicsview/qgraphicsitem_p.h index 1783fdb713..77b54c1325 100644 --- a/src/widgets/graphicsview/qgraphicsitem_p.h +++ b/src/widgets/graphicsview/qgraphicsitem_p.h @@ -273,8 +273,6 @@ public: void combineTransformFromParent(QTransform *x, const QTransform *viewTransform = 0) const; virtual void updateSceneTransformFromParent(); - // ### Qt 5: Remove. Workaround for reimplementation added after Qt 4.4. - virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; static bool movableAncestorIsSelected(const QGraphicsItem *item); virtual void setPosHelper(const QPointF &pos); diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index b09ddbab41..f4d43e4f28 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -337,42 +337,6 @@ void QGraphicsProxyWidgetPrivate::removeSubFocusHelper(QWidget *widget, Qt::Focu QApplication::sendEvent(widget->style(), &event); } -/*! - \internal - - Reimplemented from QGraphicsItemPrivate. ### Qt 5: Move impl to - reimplementation QGraphicsProxyWidget::inputMethodQuery(). -*/ -QVariant QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const -{ - Q_Q(const QGraphicsProxyWidget); - if (!widget || !q->hasFocus()) - return QVariant(); - - QWidget *focusWidget = widget->focusWidget(); - if (!focusWidget) - focusWidget = widget; - QVariant v = focusWidget->inputMethodQuery(query); - QPointF focusWidgetPos = q->subWidgetRect(focusWidget).topLeft(); - switch (v.type()) { - case QVariant::RectF: - v = v.toRectF().translated(focusWidgetPos); - break; - case QVariant::PointF: - v = v.toPointF() + focusWidgetPos; - break; - case QVariant::Rect: - v = v.toRect().translated(focusWidgetPos.toPoint()); - break; - case QVariant::Point: - v = v.toPoint() + focusWidgetPos.toPoint(); - break; - default: - break; - } - return v; -} - /*! \internal Some of the logic is shared with QApplicationPrivate::focusNextPrevChild_helper @@ -860,13 +824,7 @@ bool QGraphicsProxyWidget::event(QEvent *event) break; } case QEvent::InputMethod: { - // Forward input method events if the focus widget enables - // input methods. - // ### Qt 4.5: this code must also go into a reimplementation - // of inputMethodEvent(). - QWidget *focusWidget = d->widget->focusWidget(); - if (focusWidget && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) - QApplication::sendEvent(focusWidget, event); + inputMethodEvent(static_cast(event)); break; } case QEvent::ShortcutOverride: { @@ -1415,6 +1373,52 @@ bool QGraphicsProxyWidget::focusNextPrevChild(bool next) return QGraphicsWidget::focusNextPrevChild(next); } +/*! + \reimp +*/ +QVariant QGraphicsProxyWidget::inputMethodQuery(Qt::InputMethodQuery query) const +{ + Q_D(const QGraphicsProxyWidget); + + if (!d->widget || !hasFocus()) + return QVariant(); + + QWidget *focusWidget = widget()->focusWidget(); + if (!focusWidget) + focusWidget = d->widget; + QVariant v = focusWidget->inputMethodQuery(query); + QPointF focusWidgetPos = subWidgetRect(focusWidget).topLeft(); + switch (v.type()) { + case QVariant::RectF: + v = v.toRectF().translated(focusWidgetPos); + break; + case QVariant::PointF: + v = v.toPointF() + focusWidgetPos; + break; + case QVariant::Rect: + v = v.toRect().translated(focusWidgetPos.toPoint()); + break; + case QVariant::Point: + v = v.toPoint() + focusWidgetPos.toPoint(); + break; + default: + break; + } + return v; +} + +/*! + \reimp +*/ +void QGraphicsProxyWidget::inputMethodEvent(QInputMethodEvent *event) +{ + // Forward input method events if the focus widget enables input methods. + Q_D(const QGraphicsProxyWidget); + QWidget *focusWidget = d->widget->focusWidget(); + if (focusWidget && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) + QApplication::sendEvent(focusWidget, event); +} + /*! \reimp */ diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.h b/src/widgets/graphicsview/qgraphicsproxywidget.h index 90a90e07a6..7bd1cf007d 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.h +++ b/src/widgets/graphicsview/qgraphicsproxywidget.h @@ -116,9 +116,9 @@ protected: void focusInEvent(QFocusEvent *event); void focusOutEvent(QFocusEvent *event); bool focusNextPrevChild(bool next); - // ### Qt 4.5: - // QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - // void inputMethodEvent(QInputMethodEvent *event); + + QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + void inputMethodEvent(QInputMethodEvent *event); QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; void resizeEvent(QGraphicsSceneResizeEvent *event); diff --git a/src/widgets/graphicsview/qgraphicsproxywidget_p.h b/src/widgets/graphicsview/qgraphicsproxywidget_p.h index e7e4139f3f..fd47c8a483 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget_p.h +++ b/src/widgets/graphicsview/qgraphicsproxywidget_p.h @@ -84,9 +84,6 @@ public: QWidget *findFocusChild(QWidget *child, bool next) const; void removeSubFocusHelper(QWidget *widget, Qt::FocusReason reason); - // ### Qt 5: Remove. Workaround for reimplementation added after Qt 4.4. - QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; - void _q_removeWidgetSlot(); void embedSubWindow(QWidget *); -- cgit v1.2.3