/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
a QWidget in a QGraphicsScene.
\since 4.4
\ingroup graphicsview-api
+ \inmodule QtWidgets
QGraphicsProxyWidget embeds QWidget-based widgets, for example, a
QPushButton, QFontComboBox, or even QFileDialog, into
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 0
QGraphicsProxyWidget takes care of automatically embedding popup children
of embedded widgets through creating a child proxy for each popup. This
For example, in the code snippet below, we embed a group box into the proxy:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 1
The image below is the output obtained with its contents margin and
contents rect labeled.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 2
QGraphicsProxyWidget maintains symmetry for the following states:
\table
- \header \o QWidget state \o QGraphicsProxyWidget state \o Notes
- \row \o QWidget::enabled
- \o QGraphicsProxyWidget::enabled
- \o
- \row \o QWidget::visible
- \o QGraphicsProxyWidget::visible
- \o The explicit state is also symmetric.
- \row \o QWidget::geometry
- \o QGraphicsProxyWidget::geometry
- \o Geometry is only guaranteed to be symmetric while
+ \header \li QWidget state \li QGraphicsProxyWidget state \li Notes
+ \row \li QWidget::enabled
+ \li QGraphicsProxyWidget::enabled
+ \li
+ \row \li QWidget::visible
+ \li QGraphicsProxyWidget::visible
+ \li The explicit state is also symmetric.
+ \row \li QWidget::geometry
+ \li QGraphicsProxyWidget::geometry
+ \li Geometry is only guaranteed to be symmetric while
the embedded widget is visible.
- \row \o QWidget::layoutDirection
- \o QGraphicsProxyWidget::layoutDirection
- \o
- \row \o QWidget::style
- \o QGraphicsProxyWidget::style
- \o
- \row \o QWidget::palette
- \o QGraphicsProxyWidget::palette
- \o
- \row \o QWidget::font
- \o QGraphicsProxyWidget::font
- \o
- \row \o QWidget::cursor
- \o QGraphicsProxyWidget::cursor
- \o The embedded widget overrides the proxy widget
+ \row \li QWidget::layoutDirection
+ \li QGraphicsProxyWidget::layoutDirection
+ \li
+ \row \li QWidget::style
+ \li QGraphicsProxyWidget::style
+ \li
+ \row \li QWidget::palette
+ \li QGraphicsProxyWidget::palette
+ \li
+ \row \li QWidget::font
+ \li QGraphicsProxyWidget::font
+ \li
+ \row \li QWidget::cursor
+ \li QGraphicsProxyWidget::cursor
+ \li The embedded widget overrides the proxy widget
cursor. The proxy cursor changes depending on
which embedded subwidget is currently under the
mouse.
- \row \o QWidget::sizeHint()
- \o QGraphicsProxyWidget::sizeHint()
- \o All size hint functionality from the embedded
+ \row \li QWidget::sizeHint()
+ \li QGraphicsProxyWidget::sizeHint()
+ \li All size hint functionality from the embedded
widget is forwarded by the proxy.
- \row \o QWidget::getContentsMargins()
- \o QGraphicsProxyWidget::getContentsMargins()
- \o Updated once by setWidget().
- \row \o QWidget::windowTitle
- \o QGraphicsProxyWidget::windowTitle
- \o Updated once by setWidget().
+ \row \li QWidget::getContentsMargins()
+ \li QGraphicsProxyWidget::getContentsMargins()
+ \li Updated once by setWidget().
+ \row \li QWidget::windowTitle
+ \li QGraphicsProxyWidget::windowTitle
+ \li Updated once by setWidget().
\endtable
\note QGraphicsScene keeps the embedded widget in a special state that
*/
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
-Q_GUI_EXPORT extern bool qt_tab_all_widgets;
+Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();
/*!
\internal
pos = mapToReceiver(pos, receiver);
// Send mouse event.
- QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(type, pos,
- receiver->mapToGlobal(pos.toPoint()), event->button(),
- event->buttons(), event->modifiers());
+ QMouseEvent mouseEvent(type, pos, receiver->mapTo(receiver->topLevelWidget(), pos.toPoint()),
+ receiver->mapToGlobal(pos.toPoint()),
+ event->button(), event->buttons(), event->modifiers());
QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber;
- QApplicationPrivate::sendMouseEvent(receiver, mouseEvent, alienWidget, widget,
+ QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget,
&embeddedMouseGrabberPtr, lastWidgetUnderMouse, event->spontaneous());
embeddedMouseGrabber = embeddedMouseGrabberPtr;
// grabber child widget.
if (embeddedMouseGrabber && type == QEvent::MouseButtonRelease && !event->buttons()) {
Q_Q(QGraphicsProxyWidget);
- if (q->rect().contains(event->pos()) && q->acceptsHoverEvents())
+ if (q->rect().contains(event->pos()) && q->acceptHoverEvents())
lastWidgetUnderMouse = alienWidget ? alienWidget : widget;
else // released on the frame our outside the item, or doesn't accept hover events.
lastWidgetUnderMouse = 0;
#endif
}
- event->setAccepted(mouseEvent->isAccepted());
- delete mouseEvent;
+ event->setAccepted(mouseEvent.isAccepted());
}
void QGraphicsProxyWidgetPrivate::sendWidgetKeyEvent(QKeyEvent *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
*/
QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next) const
}
QWidget *oldChild = child;
- uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
+ uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
do {
if (child->isEnabled()
&& child->isVisibleTo(widget)
to QGraphicsItem's constructor.
*/
QGraphicsProxyWidget::QGraphicsProxyWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsWidget(*new QGraphicsProxyWidgetPrivate, parent, 0, wFlags)
+ : QGraphicsWidget(*new QGraphicsProxyWidgetPrivate, parent, wFlags)
{
Q_D(QGraphicsProxyWidget);
d->init();
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<QInputMethodEvent *>(event));
break;
}
case QEvent::ShortcutOverride: {
/*!
\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
+*/
QSizeF QGraphicsProxyWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
Q_D(const QGraphicsProxyWidget);
if (exposedWidgetRect.isEmpty())
return;
- // Disable QPainter's default pen being cosmetic. This allows widgets and
- // styles to follow Qt's existing defaults without getting ugly cosmetic
- // lines when scaled.
- bool restore = !(painter->renderHints() & QPainter::NonCosmeticDefaultPen);
- painter->setRenderHints(QPainter::NonCosmeticDefaultPen, true);
-
d->widget->render(painter, exposedWidgetRect.topLeft(), exposedWidgetRect);
-
- // Restore the render hints if necessary.
- if (restore)
- painter->setRenderHints(QPainter::NonCosmeticDefaultPen, false);
}
/*!