Android MessageDialog: order buttons according to OS X button layout
At least the dismissive action should be on the left, but we can take the OS X rules as reasonable in cases where a lot of buttons are in use. Task-number: QTBUG-42808 Change-Id: If45f991a068d47009e02d39fbb3886ff4b31c8e1 Reviewed-by: BogDan Vatra <bogdan@kde.org>bb10
parent
06ecfb6fde
commit
eea5a6ea15
|
|
@ -97,11 +97,15 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags
|
|||
if (!str.isEmpty())
|
||||
m_javaMessageDialog.callMethod<void>("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object());
|
||||
|
||||
for (int i = QPlatformDialogHelper::FirstButton; i < QPlatformDialogHelper::LastButton; i<<=1) {
|
||||
if ( opt->standardButtons() & i ) {
|
||||
const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(i);
|
||||
m_javaMessageDialog.callMethod<void>("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(text).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);
|
||||
while (*currentLayout != QPlatformDialogHelper::EOL) {
|
||||
int role = (*currentLayout & ~QPlatformDialogHelper::Reverse);
|
||||
addButtons(opt, static_cast<ButtonRole>(role));
|
||||
++currentLayout;
|
||||
}
|
||||
|
||||
m_javaMessageDialog.callMethod<void>("show", "(J)V", jlong(static_cast<QObject*>(this)));
|
||||
|
|
@ -109,6 +113,17 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags
|
|||
return true;
|
||||
}
|
||||
|
||||
void QAndroidPlatformMessageDialogHelper::addButtons(QSharedPointer<QMessageDialogOptions> opt, ButtonRole role)
|
||||
{
|
||||
for (int i = QPlatformDialogHelper::FirstButton; i < QPlatformDialogHelper::LastButton; i<<=1) {
|
||||
StandardButton b = static_cast<StandardButton>(i);
|
||||
if (buttonRole(b) == role && (opt->standardButtons() & i)) {
|
||||
const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(b);
|
||||
m_javaMessageDialog.callMethod<void>("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(text).object());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidPlatformMessageDialogHelper::hide()
|
||||
{
|
||||
m_javaMessageDialog.callMethod<void>("hide", "()V");
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ public:
|
|||
public slots:
|
||||
void dialogResult(int buttonID);
|
||||
|
||||
private:
|
||||
void addButtons(QSharedPointer<QMessageDialogOptions> opt, ButtonRole role);
|
||||
|
||||
private:
|
||||
int m_buttonId;
|
||||
QEventLoop m_loop;
|
||||
|
|
|
|||
Loading…
Reference in New Issue