summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatformwindow.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2012-12-10 14:48:19 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-24 20:41:05 +0100
commit153d613353863987322db81f3c31e33541ef7226 (patch)
treead2e8a3793641bc10cc8bbae2d0adefb70025b53 /src/gui/kernel/qplatformwindow.cpp
parentd9ff510f02bba63dabe7a081a68296056a89ae4c (diff)
Transient QWindows centered; default-constructed geometry
Default-constructed geometry does not mean put the window at 0,0, and it does not mean center the window on the screen: it means let the window manager position the window. If the window is explicitly positioned at 0,0 though, that is a higher priority than the transient hint; without this change, the transientFor property had no effect. On X11, transient means use center "gravity" to make the transient window exactly centered. But the user can still override the geometry of a transient window, as with any window. On OSX and Windows, neither transient window functionality nor smart initial positioning are provided, so a window with no position set will be centered on the screen, and a transient window will be put at the center of its transientParent. Change-Id: I4f5e37480eef5d105e45ffd60362a57f13ec55f5 Task-number: QTBUG-26903 Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui/kernel/qplatformwindow.cpp')
-rw-r--r--src/gui/kernel/qplatformwindow.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index b710701e7f..79e4cbf674 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -41,11 +41,13 @@
#include "qplatformwindow.h"
#include "qplatformwindow_p.h"
+#include "qplatformscreen.h"
#include <private/qguiapplication_p.h>
#include <qpa/qwindowsysteminterface.h>
#include <QtGui/qwindow.h>
#include <QtGui/qscreen.h>
+#include <private/qwindow_p.h>
QT_BEGIN_NAMESPACE
@@ -449,6 +451,43 @@ QString QPlatformWindow::formatWindowTitle(const QString &title, const QString &
}
/*!
+ Helper function to get initial geometry on windowing systems which do not
+ do smart positioning and also do not provide a means of centering a
+ transient window w.r.t. its parent. For example this is useful on Windows
+ and MacOS but not X11, because an X11 window manager typically tries to
+ layout new windows to optimize usage of the available desktop space.
+ However if the given window already has geometry which the application has
+ initialized, it takes priority.
+*/
+QRect QPlatformWindow::initialGeometry(const QWindow *w,
+ const QRect &initialGeometry, int defaultWidth, int defaultHeight)
+{
+ QRect rect(initialGeometry);
+ if (rect.isNull()) {
+ QSize minimumSize = w->minimumSize();
+ if (minimumSize.width() > 0 || minimumSize.height() > 0) {
+ rect.setSize(minimumSize);
+ } else {
+ rect.setWidth(defaultWidth);
+ rect.setHeight(defaultHeight);
+ }
+ }
+ if (w->isTopLevel() && qt_window_private(const_cast<QWindow*>(w))->positionAutomatic) {
+ const QWindow *tp = w->transientParent();
+ if (tp) {
+ // A transient window should be centered w.r.t. its transient parent.
+ rect.moveCenter(tp->geometry().center());
+ } else {
+ // Center the window on the screen. (Only applicable on platforms
+ // which do not provide a better way.)
+ QPlatformScreen *scr = QPlatformScreen::platformScreenForWindow(w);
+ rect.moveCenter(scr->availableGeometry().center());
+ }
+ }
+ return rect;
+}
+
+/*!
\class QPlatformWindow
\since 4.8
\internal