Get rid of more QWidget / QApplication dependencies.

This commit is contained in:
Samuel Rødal 2011-05-04 16:43:45 +02:00
parent d7b91f613d
commit 6229ef2dce
14 changed files with 64 additions and 66 deletions

View 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);

View 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 &);

View File

@ -149,6 +149,8 @@ public:
static QClipboard *qt_clipboard;
#endif
static QWindowList window_list;
#ifndef QT_NO_CURSOR
QList<QCursor> cursor_list;
#endif

View 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)

View File

@ -43,7 +43,7 @@
#include <QWidget>
#include <QPainter>
#include <QBitmap>
#include <QApplication>
#include <QGuiApplication>
#include <QDebug>

View 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.

View 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;

View File

@ -40,26 +40,23 @@
****************************************************************************/
#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);

View 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);
};

View 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
*/

View 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

View 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;

View 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);

View 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;