Make QPen default to 1-width non-cosmetic.
[profile/ivi/qtbase.git] / src / widgets / graphicsview / qgraphicsproxywidget.cpp
index da00e9f..762f93f 100644 (file)
@@ -1,38 +1,38 @@
 /****************************************************************************
 **
-** 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$
+** 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
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to 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.
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** 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.
 **
 ** 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
+** 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$
@@ -71,6 +71,7 @@ QT_BEGIN_NAMESPACE
     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
@@ -83,7 +84,7 @@ QT_BEGIN_NAMESPACE
 
     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
@@ -103,7 +104,7 @@ QT_BEGIN_NAMESPACE
 
     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.
@@ -130,50 +131,50 @@ QT_BEGIN_NAMESPACE
 
     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
@@ -189,7 +190,7 @@ QT_BEGIN_NAMESPACE
 */
 
 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
@@ -274,12 +275,12 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
     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;
 
@@ -287,7 +288,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
     // 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;
@@ -302,8 +303,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
 #endif
     }
 
-    event->setAccepted(mouseEvent->isAccepted());
-    delete mouseEvent;
+    event->setAccepted(mouseEvent.isAccepted());
 }
 
 void QGraphicsProxyWidgetPrivate::sendWidgetKeyEvent(QKeyEvent *event)
@@ -339,42 +339,6 @@ void QGraphicsProxyWidgetPrivate::removeSubFocusHelper(QWidget *widget, Qt::Focu
 
 /*!
     \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
@@ -393,7 +357,7 @@ QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next)
     }
 
     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)
@@ -537,7 +501,7 @@ QPointF QGraphicsProxyWidgetPrivate::mapToReceiver(const QPointF &pos, const QWi
     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();
@@ -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<QInputMethodEvent *>(event));
         break;
     }
     case QEvent::ShortcutOverride: {
@@ -1418,6 +1376,52 @@ bool QGraphicsProxyWidget::focusNextPrevChild(bool 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
+*/
 QSizeF QGraphicsProxyWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
 {
     Q_D(const QGraphicsProxyWidget);
@@ -1481,17 +1485,7 @@ void QGraphicsProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsIt
     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);
 }
 
 /*!