diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 39 | ||||
-rw-r--r-- | src/gui/kernel/qplatformwindow.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 17 | ||||
-rw-r--r-- | src/gui/kernel/qwindow_p.h | 2 |
5 files changed, 61 insertions, 2 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 7155127f75..7bfc9ccbec 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1591,6 +1591,8 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate } QGuiApplicationPrivate::focus_window = newFocus; + if (!qApp) + return; if (previous) { QFocusEvent focusOut(QEvent::FocusOut); diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 1eec6bfefc..bfb6ab5a68 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 @@ -461,6 +463,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 diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index e3e460b54c..7ade461890 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -128,6 +128,9 @@ public: virtual void setFrameStrutEventsEnabled(bool enabled); virtual bool frameStrutEventsEnabled() const; + static QRect initialGeometry(const QWindow *w, + const QRect &initialGeometry, int defaultWidth, int defaultHeight); + protected: static QString formatWindowTitle(const QString &title, const QString &separator); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 33fd4954eb..99a54dc847 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -129,6 +129,18 @@ QT_BEGIN_NAMESPACE and can keep rendering until it isExposed() returns false. To find out when isExposed() changes, reimplement exposeEvent(). The window will always get a resize event before the first expose event. + + \section1 Initial geometry + + If the window's width and height are left uninitialized, the window will + get a reasonable default geometry from the platform window. If the position + is left uninitialized, then the platform window will allow the windowing + system to position the window. For example on X11, the window manager + usually does some kind of smart positioning to try to avoid having new + windows completely obscure existing windows. However setGeometry() + initializes both the position and the size, so if you want a fixed size but + an automatic position, you should call resize() or setWidth() and + setHeight() instead. */ /*! @@ -1125,7 +1137,7 @@ void QWindow::setY(int arg) void QWindow::setWidth(int arg) { if (width() != arg) - setGeometry(QRect(x(), y(), arg, height())); + resize(arg, height()); } /*! @@ -1135,7 +1147,7 @@ void QWindow::setWidth(int arg) void QWindow::setHeight(int arg) { if (height() != arg) - setGeometry(QRect(x(), y(), width(), arg)); + resize(width(), arg); } /*! @@ -1258,6 +1270,7 @@ void QWindow::setGeometry(int posx, int posy, int w, int h) void QWindow::setGeometry(const QRect &rect) { Q_D(QWindow); + d->positionAutomatic = false; if (rect == geometry()) return; QRect oldRect = geometry(); diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index e92f37c34f..e32d45acca 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -87,6 +87,7 @@ public: , resizeEventPending(true) , receivedExpose(false) , positionPolicy(WindowFrameExclusive) + , positionAutomatic(true) , contentOrientation(Qt::PrimaryOrientation) , opacity(qreal(1.0)) , minimumSize(0, 0) @@ -141,6 +142,7 @@ public: bool resizeEventPending; bool receivedExpose; PositionPolicy positionPolicy; + bool positionAutomatic; Qt::ScreenOrientation contentOrientation; qreal opacity; QRegion mask; |