Add QGuiApp::topLevelAt and fix visibility flag

Add and remove windows to the list of top level windows.
Correctly set the visibility flag for windows and implement
a QGuiApplication::topLevelAt() method that uses the
QPlatformScreen.
This commit is contained in:
Lars Knoll 2011-05-21 21:31:46 +02:00
parent 121cc4d955
commit fd7bfc6184
3 changed files with 30 additions and 2 deletions

View File

@ -183,6 +183,27 @@ QWindowList QGuiApplication::topLevelWindows()
return QGuiApplicationPrivate::window_list;
}
QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
{
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
QList<QPlatformScreen *> screens = pi->screens();
QList<QPlatformScreen *>::const_iterator screen = screens.constBegin();
QList<QPlatformScreen *>::const_iterator end = screens.constEnd();
// The first screen in a virtual environment should know about all top levels
if (pi->isVirtualDesktop())
return (*screen)->topLevelAt(pos);
while (screen != end) {
if ((*screen)->geometry().contains(pos))
return (*screen)->topLevelAt(pos);
++screen;
}
return 0;
}
static void init_platform(const QString &name, const QString &platformPluginPath)
{
QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, platformPluginPath);

View File

@ -80,6 +80,7 @@ public:
virtual ~QGuiApplication();
static QWindowList topLevelWindows();
static QWindow *topLevelAt(const QPoint &pos);
static QWindow *activeWindow();

View File

@ -58,21 +58,27 @@ QWindow::QWindow(QWindow *parent)
{
Q_D(QWindow);
d->parentWindow = parent;
QGuiApplicationPrivate::window_list.prepend(this);
}
QWindow::~QWindow()
{
if (QGuiApplicationPrivate::active_window == this)
QGuiApplicationPrivate::active_window = 0;
QGuiApplicationPrivate::window_list.removeAll(this);
destroy();
}
void QWindow::setVisible(bool visible)
{
Q_D(QWindow);
if (!d->platformWindow) {
if (d->visible == visible)
return;
d->visible = visible;
if (!d->platformWindow)
create();
}
d->platformWindow->setVisible(visible);
}