Get rid of more QWidget / QApplication dependencies.
authorSamuel Rødal <samuel.rodal@nokia.com>
Wed, 4 May 2011 14:43:45 +0000 (16:43 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Wed, 4 May 2011 14:59:33 +0000 (16:59 +0200)
14 files changed:
src/gui/guikernel/qguiapplication.cpp
src/gui/guikernel/qguiapplication.h
src/gui/guikernel/qguiapplication_p.h
src/gui/guikernel/qkeymapper.cpp
src/gui/guikernel/qplatformcursor_qpa.cpp
src/gui/guikernel/qplatformintegration_qpa.cpp
src/gui/guikernel/qplatformintegration_qpa.h
src/gui/guikernel/qplatformscreen_qpa.cpp
src/gui/guikernel/qplatformscreen_qpa.h
src/gui/guikernel/qplatformwindow_qpa.cpp
src/gui/guikernel/qwindowdefs.h
src/gui/kernel/qapplication_qpa.cpp
src/gui/kernel/qwidget.cpp
src/gui/kernel/qwidget_qpa.cpp

index 0962e62..d7fe145 100644 (file)
@@ -105,6 +105,8 @@ QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0;
 QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
 #endif
 
+QWindowList QGuiApplicationPrivate::window_list;
+
 Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
 QFont *QGuiApplicationPrivate::app_font = 0;
 
@@ -158,6 +160,11 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags
     self = this;
 }
 
+QWindowList QGuiApplication::topLevelWindows()
+{
+    return QGuiApplicationPrivate::window_list;
+}
+
 static void init_platform(const QString &name, const QString &platformPluginPath)
 {
     QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, platformPluginPath);
index 980e275..74c1034 100644 (file)
@@ -78,6 +78,8 @@ public:
     QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
     virtual ~QGuiApplication();
 
+    static QWindowList topLevelWindows();
+
 #ifndef QT_NO_CURSOR
     static QCursor *overrideCursor();
     static void setOverrideCursor(const QCursor &);
index fc6c697..505440b 100644 (file)
@@ -149,6 +149,8 @@ public:
     static QClipboard *qt_clipboard;
 #endif
 
+    static QWindowList window_list;
+
 #ifndef QT_NO_CURSOR
     QList<QCursor> cursor_list;
 #endif
index e6ba3ce..e38a905 100644 (file)
@@ -91,6 +91,8 @@ void QKeyMapper::changeKeyboard()
 {
     instance()->d_func()->clearMappings();
 
+    // ## TODO: Support KeyboardLayoutChange on QPA
+#if 0
     // inform all toplevel widgets of the change
     QEvent e(QEvent::KeyboardLayoutChange);
     QWidgetList list = QApplication::topLevelWidgets();
@@ -98,6 +100,7 @@ void QKeyMapper::changeKeyboard()
         QWidget *w = list.at(i);
         qt_sendSpontaneousEvent(w, &e);
     }
+#endif
 }
 
 Q_GLOBAL_STATIC(QKeyMapper, keymapper)
index 2ea8332..6b4f915 100644 (file)
@@ -43,7 +43,7 @@
 #include <QWidget>
 #include <QPainter>
 #include <QBitmap>
-#include <QApplication>
+#include <QGuiApplication>
 
 #include <QDebug>
 
index 8ff12eb..9967a44 100644 (file)
@@ -145,7 +145,7 @@ QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
 */
 
 /*!
-    \fn QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const
+    \fn QPlatformWindow *createPlatformWindow(QWindow *window, WId winId = 0) const
 
     Factory function for QPlatformWindow. The widget parameter is a pointer to the top level
     widget(tlw) which the QPlatformWindow is suppose to be created for. The WId handle is actually
@@ -158,27 +158,27 @@ QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
     created.
 
     \sa QPlatformWindow, QPlatformWindowFormat
-    \sa createWindowSurface(QWidget *widget, WId winId) const
+    \sa createWindowSurface(QWindow *window, WId winId) const
 */
 
 /*!
-    \fn QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const
+    \fn QWindowSurface *createWindowSurface(QWindow *window, WId winId) const
 
-    Factory function for QWindowSurface. The QWidget parameter is a pointer to the
+    Factory function for QWindowSurface. The QWindow parameter is a pointer to the
     top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
     before the QWindowSurface for tlw where the widget also requires a WindowSurface. It is
-    possible to create top level QWidgets without a QWindowSurface by specifying
+    possible to create top level QWindow without a QWindowSurface by specifying
     QPlatformWindowFormat::setWindowSurface(false) for the tlw QPlatformWindowFormat.
 
     \sa QWindowSurface
-    \sa createPlatformWindow(QWidget *widget, WId winId = 0) const
+    \sa createPlatformWindow(QWindow *window, WId winId = 0) const
 */
 
 /*!
-    \fn void moveToScreen(QWidget *window, int screen)
+    \fn void moveToScreen(QWindow *window, int screen)
 
-    This function is called when a QWidget is displayed on screen, or the QWidget is to be
-    displayed on a new screen. The QWidget parameter is a pointer to the top level widget and
+    This function is called when a QWindow is displayed on screen, or the QWindow is to be
+    displayed on a new screen. The QWindow parameter is a pointer to the top level widget and
     the int parameter is the index to the screen in QList<QPlatformScreen *> screens() const.
 
     Default implementation does nothing.
index 43080d2..eb29a4b 100644 (file)
@@ -56,7 +56,6 @@ QT_MODULE(Gui)
 class QPlatformWindow;
 class QWindow;
 class QBlittable;
-class QWidget;
 class QPlatformEventLoopIntegration;
 class QPlatformFontDatabase;
 class QPlatformClipboard;
@@ -82,7 +81,7 @@ public:
 
 // Window System functions
     virtual QList<QPlatformScreen *> screens() const = 0;
-    virtual void moveToScreen(QWidget *window, int screen) {Q_UNUSED(window); Q_UNUSED(screen);}
+    virtual void moveToScreen(QWindow *window, int screen) {Q_UNUSED(window); Q_UNUSED(screen);}
     virtual bool isVirtualDesktop() { return false; }
     virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const;
 
index 8b68678..8759aa4 100644 (file)
 ****************************************************************************/
 
 #include "qplatformscreen_qpa.h"
-#include <QtGui/qapplication.h>
-#include <QtGui/private/qapplication_p.h>
-#include <QtGui/qdesktopwidget.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/private/qguiapplication_p.h>
 #include <QtGui/qplatformintegration_qpa.h>
-#include <QtGui/qwidget.h>
-#include <QtGui/private/qwidget_p.h>
+#include <QtGui/qwindow.h>
 
 /*!
-    Return the given top level widget for a given position.
+    Return the given top level window for a given position.
 
-    Default implementation retrieves a list of all top level widgets and finds the first widget
+    Default implementation retrieves a list of all top level windows and finds the first window
     which contains point \a pos
 */
-QWidget *QPlatformScreen::topLevelAt(const QPoint & pos) const
+QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
 {
-    QWidgetList list = QApplication::topLevelWidgets();
+    QWindowList list = QGuiApplication::topLevelWindows();
     for (int i = list.size()-1; i >= 0; --i) {
-        QWidget *w = list[i];
-        //### mask is ignored
-        if (w != QApplication::desktop() && w->isVisible() && w->geometry().contains(pos))
+        QWindow *w = list[i];
+        if (w->visible() && w->geometry().contains(pos))
             return w;
     }
 
@@ -81,20 +78,6 @@ QSize QPlatformScreen::physicalSize() const
     return QSize(width,height);
 }
 
-Q_GUI_EXPORT extern QWidgetPrivate *qt_widget_private(QWidget *widget);
-QPlatformScreen * QPlatformScreen::platformScreenForWidget(const QWidget *widget)
-{
-    int screenIndex = 0;
-    QWidget *window = widget->window();
-    QWidgetPrivate *windowPrivate = qt_widget_private(window);
-    QTLWExtra * topData = windowPrivate->maybeTopData();
-    if (topData)
-        screenIndex = topData->screenIndex;
-    QPlatformIntegration *integration =
-            QGuiApplicationPrivate::platformIntegration();
-    return integration->screens()[screenIndex];
-}
-
 QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *)
 {
     return QGuiApplicationPrivate::platformIntegration()->screens().at(0);
index cbaf5b9..9492788 100644 (file)
@@ -51,7 +51,7 @@
 
 #include <QtGui/qcursor.h>
 #include <QtGui/qimage.h>
-#include <QtGui/qwidget.h>
+#include <QtGui/qwindowdefs.h>
 
 QT_BEGIN_HEADER
 
@@ -72,13 +72,10 @@ public:
     virtual QSize physicalSize() const;
     //jl: should setDirty be removed.
     virtual void setDirty(const QRect &) {}
-    virtual QWidget *topLevelAt(const QPoint &point) const;
+    virtual QWindow *topLevelAt(const QPoint &point) const;
 
     //jl: should this function be in QPlatformIntegration
-    //jl: maybe screenForWidget is a better name?
-    static QPlatformScreen *platformScreenForWidget(const QWidget *widget);
-
-    // temporary convenience
+    //jl: maybe screenForWindow is a better name?
     static QPlatformScreen *platformScreenForWindow(const QWindow *window);
 };
 
index 7ec5221..24c337c 100644 (file)
@@ -42,7 +42,7 @@
 #include "qplatformwindow_qpa.h"
 
 #include <QtGui/qwindowsysteminterface_qpa.h>
-#include <QtGui/qwidget.h>
+#include <QtGui/qwindow.h>
 
 class QPlatformWindowPrivate
 {
@@ -52,7 +52,7 @@ class QPlatformWindowPrivate
 };
 
 /*!
-    Constructs a platform window with the given top level widget.
+    Constructs a platform window with the given top level window.
 */
 
 QPlatformWindow::QPlatformWindow(QWindow *window)
@@ -63,14 +63,14 @@ QPlatformWindow::QPlatformWindow(QWindow *window)
 }
 
 /*!
-    Virtual destructor does not delete its top level widget.
+    Virtual destructor does not delete its top level window.
 */
 QPlatformWindow::~QPlatformWindow()
 {
 }
 
 /*!
-    Returnes the widget which belongs to the QPlatformWindow
+    Returnes the window which belongs to the QPlatformWindow
 */
 QWindow *QPlatformWindow::window() const
 {
@@ -82,7 +82,7 @@ QWindow *QPlatformWindow::window() const
     This function is called by Qt whenever a window is moved or the window is resized. The resize
     can happen programatically(from ie. user application) or by the window manager. This means that
     there is no need to call this function specifically from the window manager callback, instead
-    call QWindowSystemInterface::handleGeometryChange(QWidget *w, const QRect &newRect);
+    call QWindowSystemInterface::handleGeometryChange(QWindow *w, const QRect &newRect);
 */
 void QPlatformWindow::setGeometry(const QRect &rect)
 {
@@ -122,7 +122,7 @@ Qt::WindowFlags QPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
 WId QPlatformWindow::winId() const { return WId(0); }
 
 /*!
-    This function is called to enable native child widgets in QPA. It is common not to support this
+    This function is called to enable native child window in QPA. It is common not to support this
     feature in Window systems, but can be faked. When this function is called all geometry of this
     platform window will be relative to the parent.
 */
@@ -162,14 +162,14 @@ void QPlatformWindow::setOpacity(qreal level)
   Reimplement to let Qt be able to request activation/focus for a window
 
   Some window systems will probably not have callbacks for this functionality,
-  and then calling QWindowSystemInterface::handleWindowActivated(QWidget *w)
+  and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w)
   would be sufficient.
 
   If the window system has some event handling/callbacks then call
-  QWindowSystemInterface::handleWindowActivated(QWidget *w) when the window system
+  QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system
   gives the notification.
 
-  Default implementation calls QWindowSystem::handleWindowActivated(QWidget *w)
+  Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w)
 */
 void QPlatformWindow::requestActivateWindow()
 {
@@ -193,16 +193,16 @@ QPlatformGLContext *QPlatformWindow::glContext() const
 
     \brief The QPlatformWindow class provides an abstraction for top-level windows.
 
-    The QPlatformWindow abstraction is used by QWidget for all its top level widgets. It is being
+    The QPlatformWindow abstraction is used by QWindow for all its top level windows. It is being
     created by calling the createPlatformWindow function in the loaded QPlatformIntegration
     instance.
 
     QPlatformWindow is used to signal to the windowing system, how Qt persieves its frame.
     However, it is not concerned with how Qt renders into the window it represents.
 
-    Top level QWidgets(tlw) will always have a QPlatformWindow. However, it is not necessary for
-    all tlw to have a QWindowSurface. This is the case for QGLWidget. And could be the case for
-    widgets where some  3.party renders into it.
+    Visible QWindows will always have a QPlatformWindow. However, it is not necessary for
+    all windows to have a QWindowSurface. This is the case for QGLWidget. And could be the case for
+    windows where some  3.party renders into it.
 
     The platform specific window handle can be retrieved by the winId function.
 
@@ -212,5 +212,5 @@ QPlatformGLContext *QPlatformWindow::glContext() const
     The only way to retrieve a QPlatformGLContext in QPA is by calling the glContext() function
     on QPlatformWindow.
 
-    \sa QWindowSurface, QWidget
+    \sa QWindowSurface, QWindow
 */
index dd6d13a..b9fea38 100644 (file)
@@ -54,6 +54,7 @@ QT_MODULE(Gui)
 
 class QPaintDevice;
 class QWidget;
+class QWindow;
 class QDialog;
 class QColor;
 class QPalette;
@@ -85,6 +86,7 @@ class QApplication;
 
 template<typename T> class QList;
 typedef QList<QWidget *> QWidgetList;
+typedef QList<QWindow *> QWindowList;
 
 QT_END_NAMESPACE
 QT_END_HEADER
index e1876e4..f3e033c 100644 (file)
@@ -65,6 +65,7 @@
 #include <QPlatformIntegration>
 
 #include "qdesktopwidget_qpa_p.h"
+#include "qwidgetwindow_qpa_p.h"
 
 QT_BEGIN_NAMESPACE
 
@@ -343,13 +344,15 @@ QWidget *QApplication::topLevelAt(const QPoint &pos)
 
     // The first screen in a virtual environment should know about all top levels
     if (pi->isVirtualDesktop()) {
-        QWidget *w = (*screen)->topLevelAt(pos);
-        return w;
+        QWidgetWindow *w = qobject_cast<QWidgetWindow *>((*screen)->topLevelAt(pos));
+        return w ? w->widget() : 0;
     }
 
     while (screen != end) {
-        if ((*screen)->geometry().contains(pos))
-            return (*screen)->topLevelAt(pos);
+        if ((*screen)->geometry().contains(pos)) {
+            QWidgetWindow *w = qobject_cast<QWidgetWindow *>((*screen)->topLevelAt(pos));
+            return w ? w->widget() : 0;
+        }
         ++screen;
     }
     return 0;
index 0c9e523..b6e6a56 100644 (file)
@@ -1302,7 +1302,7 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
     if (desktopWidget) {
         int screen = desktopWidget->d_func()->topData()->screenIndex;
         QPlatformIntegration *platform = QGuiApplicationPrivate::platformIntegration();
-        platform->moveToScreen(q, screen);
+        platform->moveToScreen(q->windowHandle(), screen);
     }
 #else
     Q_UNUSED(desktopWidget);
index 5ef3b89..d239e6d 100644 (file)
@@ -119,7 +119,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
 //    first check children. and create them if necessary
 //    q_createNativeChildrenAndSetParent(q->windowHandle(),q);
 
-    QGuiApplicationPrivate::platformIntegration()->moveToScreen(q, topData()->screenIndex);
+    QGuiApplicationPrivate::platformIntegration()->moveToScreen(win, topData()->screenIndex);
 //    qDebug() << "create_sys" << q << q->internalWinId();
 }
 
@@ -216,7 +216,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
         // only if it is already created
         if (q->testAttribute(Qt::WA_WState_Created)) {
             QPlatformIntegration *platform = QGuiApplicationPrivate::platformIntegration();
-            platform->moveToScreen(q, targetScreen);
+            platform->moveToScreen(q->windowHandle(), targetScreen);
         }
     }
 }
@@ -638,7 +638,7 @@ int QWidget::metric(PaintDeviceMetric m) const
 {
     Q_D(const QWidget);
 
-    QPlatformScreen *screen = QPlatformScreen::platformScreenForWidget(this);
+    QPlatformScreen *screen = QPlatformScreen::platformScreenForWindow(windowHandle());
     if (!screen) {
         if (m == PdmDpiX || m == PdmDpiY)
               return 72;