Add button layout for dialogs on Android
It used macOS layout before, but it differs from the actual layout in Android/Material Design: affirmative actions are on the right side, dismissive actions are directly to the left of the affirmative actions and neutral actions are on the left side. [ChangeLog][Platform-specific Changes][Android] Android dialogs now have more appropriate button layout, with affirmative actions on the right. Task-number: QTBUG-58060 Change-Id: I0755f80261410c64cf4f854b7f2a72e2d959db28 Reviewed-by: BogDan Vatra <bogdan@kdab.com> Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
parent
b018a5ecef
commit
34f46588aa
@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
*/
|
||||
|
||||
static const int buttonRoleLayouts[2][5][14] =
|
||||
static const int buttonRoleLayouts[2][6][14] =
|
||||
{
|
||||
// Qt::Horizontal
|
||||
{
|
||||
@ -92,7 +92,15 @@ static const int buttonRoleLayouts[2][5][14] =
|
||||
// MacModelessLayout
|
||||
{ QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch,
|
||||
QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
|
||||
QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
|
||||
QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
|
||||
|
||||
// AndroidLayout (neutral, stretch, dismissive, affirmative)
|
||||
// https://material.io/guidelines/components/dialogs.html#dialogs-specs
|
||||
{ QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole,
|
||||
QPlatformDialogHelper::Stretch, QPlatformDialogHelper::RejectRole | QPlatformDialogHelper::Reverse,
|
||||
QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::DestructiveRole | QPlatformDialogHelper::Reverse,
|
||||
QPlatformDialogHelper::AlternateRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse,
|
||||
QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
|
||||
},
|
||||
|
||||
// Qt::Vertical
|
||||
@ -120,10 +128,20 @@ static const int buttonRoleLayouts[2][5][14] =
|
||||
// MacModelessLayout
|
||||
{ QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch,
|
||||
QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
|
||||
QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
|
||||
QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
|
||||
|
||||
// AndroidLayout
|
||||
// (affirmative
|
||||
// dismissive
|
||||
// neutral)
|
||||
// https://material.io/guidelines/components/dialogs.html#dialogs-specs
|
||||
{ QPlatformDialogHelper::YesRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole,
|
||||
QPlatformDialogHelper::NoRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole,
|
||||
QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QPlatformDialogHelper::QPlatformDialogHelper()
|
||||
{
|
||||
qRegisterMetaType<StandardButton>();
|
||||
@ -917,6 +935,8 @@ const int *QPlatformDialogHelper::buttonLayout(Qt::Orientation orientation, Butt
|
||||
policy = MacLayout;
|
||||
#elif defined (Q_OS_LINUX) || defined (Q_OS_UNIX)
|
||||
policy = KdeLayout;
|
||||
#elif defined (Q_OS_ANDROID)
|
||||
policy = AndroidLayout;
|
||||
#else
|
||||
policy = WinLayout;
|
||||
#endif
|
||||
|
@ -141,13 +141,14 @@ public:
|
||||
Q_ENUM(ButtonRole)
|
||||
|
||||
enum ButtonLayout {
|
||||
// keep this in sync with QDialogButtonBox::ButtonLayout and QMessageBox::ButtonLayout
|
||||
// keep this in sync with QDialogButtonBox::ButtonLayout
|
||||
UnknownLayout = -1,
|
||||
WinLayout,
|
||||
MacLayout,
|
||||
KdeLayout,
|
||||
GnomeLayout,
|
||||
MacModelessLayout
|
||||
MacModelessLayout,
|
||||
AndroidLayout
|
||||
};
|
||||
|
||||
QPlatformDialogHelper();
|
||||
|
@ -103,11 +103,7 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags
|
||||
if (!str.isEmpty())
|
||||
m_javaMessageDialog.callMethod<void>("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object());
|
||||
|
||||
// http://developer.android.com/design/building-blocks/dialogs.html
|
||||
// dismissive action on the left, affirmative on the right
|
||||
// There don't seem to be more fine-grained rules, but the OS X layout
|
||||
// at least conforms to this one rule and makes the rest deterministic.
|
||||
const int * currentLayout = buttonLayout(Qt::Horizontal, MacLayout);
|
||||
const int * currentLayout = buttonLayout(Qt::Horizontal, AndroidLayout);
|
||||
while (*currentLayout != QPlatformDialogHelper::EOL) {
|
||||
int role = (*currentLayout & ~QPlatformDialogHelper::Reverse);
|
||||
addButtons(opt, static_cast<ButtonRole>(role));
|
||||
|
@ -1793,8 +1793,9 @@
|
||||
a QMessageBox. The possible values are 0
|
||||
(\l{QDialogButtonBox::}{WinLayout}), 1
|
||||
(\l{QDialogButtonBox::}{MacLayout}), 2
|
||||
(\l{QDialogButtonBox::}{KdeLayout}), and 3
|
||||
(\l{QDialogButtonBox::}{GnomeLayout}).
|
||||
(\l{QDialogButtonBox::}{KdeLayout}), 3
|
||||
(\l{QDialogButtonBox::}{GnomeLayout}) and 5
|
||||
(\l{QDialogButtonBox::}{AndroidLayout}).
|
||||
|
||||
If this property is not specified, it defaults to the
|
||||
value specified by the current style for the
|
||||
|
@ -577,6 +577,8 @@ QDialogButtonBox::~QDialogButtonBox()
|
||||
\value MacLayout Use a policy appropriate for applications on \macos.
|
||||
\value KdeLayout Use a policy appropriate for applications on KDE.
|
||||
\value GnomeLayout Use a policy appropriate for applications on GNOME.
|
||||
\value AndroidLayout Use a policy appropriate for applications on Android.
|
||||
This enum value was added in Qt 5.10.
|
||||
|
||||
The button layout is specified by the \l{style()}{current style}. However,
|
||||
on the X11 platform, it may be influenced by the desktop environment.
|
||||
|
@ -108,11 +108,13 @@ public:
|
||||
Q_FLAG(StandardButtons)
|
||||
|
||||
enum ButtonLayout {
|
||||
// keep this in sync with QMessageBox::ButtonLayout and QPlatformDialogHelper::ButtonLayout
|
||||
// keep this in sync with QPlatformDialogHelper::ButtonLayout
|
||||
WinLayout,
|
||||
MacLayout,
|
||||
KdeLayout,
|
||||
GnomeLayout
|
||||
GnomeLayout,
|
||||
// MacModelessLayout,
|
||||
AndroidLayout = GnomeLayout + 2 // ### Qt 6: reorder
|
||||
};
|
||||
|
||||
QDialogButtonBox(QWidget *parent = Q_NULLPTR);
|
||||
|
Loading…
Reference in New Issue
Block a user