Allow platform to decide default behavior for show() based on window flags

The ShowIsMaximized and ShowIsFullscreen style hints were not granular
enough to build a default behavior from that would be correct for all
platforms. The recent Android patch that excluded dialogs from being
shown maximized (Ia249e93dbbea1) has now been moved into a platform
override in the Android integration plugin, leaving other platforms
to the default behavior of using the style-hints. We still special
case popup-windows though, as that behavior has been there for a
while.

Task-number: QTBUG-34969
Change-Id: Id36346d71bfc46171383ffe334592ca0b94e456f
Reviewed-by: BogDan Vatra <bogdan@kde.org>
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
bb10
Tor Arne Vestbø 2013-11-20 13:03:14 +01:00 committed by The Qt Project
parent 54b8c27e03
commit f1268d137e
7 changed files with 44 additions and 17 deletions

View File

@ -364,6 +364,20 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return 0;
}
Qt::WindowState QPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const
{
// Leave popup-windows as is
if (flags & Qt::Popup & ~Qt::Window)
return Qt::WindowNoState;
if (styleHint(QPlatformIntegration::ShowIsFullScreen).toBool())
return Qt::WindowFullScreen;
else if (styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
return Qt::WindowMaximized;
return Qt::WindowNoState;
}
Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
{
return QGuiApplication::keyboardModifiers();

View File

@ -152,6 +152,7 @@ public:
};
virtual QVariant styleHint(StyleHint hint) const;
virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const;
virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
virtual QList<int> possibleKeys(const QKeyEvent *) const;

View File

@ -176,6 +176,9 @@ int QStyleHints::cursorFlashTime() const
Returns \c true if the platform defaults to windows being fullscreen,
otherwise \c false.
\note The platform may still choose to show certain windows non-fullscreen,
such as popups or dialogs. This method only returns the default behavior.
\sa QWindow::show()
*/
bool QStyleHints::showIsFullScreen() const

View File

@ -1651,18 +1651,17 @@ QObject *QWindow::focusObject() const
/*!
Shows the window.
This equivalent to calling showFullScreen() or showNormal(), depending
on whether the platform defaults to windows being fullscreen or not, and
whether the window is a popup.
This is equivalent to calling showFullScreen(), showMaximized(), or showNormal(),
depending on the platform's default behavior for the window type and flags.
\sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags()
\sa showFullScreen(), showMaximized(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags()
*/
void QWindow::show()
{
bool isPopup = d_func()->windowFlags & Qt::Popup & ~Qt::Window;
if (!isPopup && qApp->styleHints()->showIsFullScreen())
Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(d_func()->windowFlags);
if (defaultState == Qt::WindowFullScreen)
showFullScreen();
else if (!isPopup && !(d_func()->windowFlags & Qt::Dialog & ~Qt::Window) && QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
else if (defaultState == Qt::WindowMaximized)
showMaximized();
else
showNormal();

View File

@ -242,6 +242,15 @@ QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const
}
}
Qt::WindowState QAndroidPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const
{
// Don't maximize dialogs on Android
if (flags & Qt::Dialog & ~Qt::Window)
return Qt::WindowNoState;
return QPlatformIntegration::defaultWindowState(flags);
}
static const QLatin1String androidThemeName("android");
QStringList QAndroidPlatformIntegration::themeNames() const
{

View File

@ -121,6 +121,7 @@ public:
#endif
QVariant styleHint(StyleHint hint) const;
Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const Q_DECL_OVERRIDE;
QStringList themeNames() const;
QPlatformTheme *createPlatformTheme(const QString &name) const;

View File

@ -6999,23 +6999,23 @@ void QWidget::setUpdatesEnabled(bool enable)
}
/*!
Shows the widget and its child widgets. This function is
equivalent to setVisible(true) in the normal case, and equivalent
to showFullScreen() if the QStyleHints::showIsFullScreen() hint
is true and the window is not a popup.
Shows the widget and its child widgets.
\sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
showNormal(), isVisible(), windowFlags()
This is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true),
depending on the platform's default behavior for the window flags.
\sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
showNormal(), isVisible(), windowFlags(), flags()
*/
void QWidget::show()
{
bool isPopup = data->window_flags & Qt::Popup & ~Qt::Window;
if (isWindow() && !isPopup && qApp->styleHints()->showIsFullScreen())
Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(data->window_flags);
if (defaultState == Qt::WindowFullScreen)
showFullScreen();
else if (isWindow() && !(data->window_flags & Qt::Dialog & ~Qt::Window) && !isPopup && QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
else if (defaultState == Qt::WindowMaximized)
showMaximized();
else
setVisible(true);
setVisible(true); // FIXME: Why not showNormal(), like QWindow::show()?
}
/*! \internal