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());
        }
    }
}
static QMessageBox::StandardButton
showMessageBox(QWidget *parent,
               QMessageBox::Icon icon,
               QString const &title,
               QString const &text,
               QMessageBox::StandardButtons buttons,
               QMessageBox::StandardButton defaultButton) {
  QMessageBox msgBox{icon, title, text, QMessageBox::NoButton, parent};
  auto buttonBox = msgBox.findChild<QDialogButtonBox *>();
  auto mask      = static_cast<unsigned int>(QMessageBox::FirstButton);

  while (mask <= static_cast<unsigned int>(QMessageBox::LastButton)) {
    auto sb = static_cast<unsigned int>(buttons & mask);
    mask  <<= 1;

    if (!sb)
      continue;

    auto button = msgBox.addButton(static_cast<QMessageBox::StandardButton>(sb));

    if (msgBox.defaultButton())
      continue;

    if (   ((defaultButton == QMessageBox::NoButton) && (buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole))
        || ((defaultButton != QMessageBox::NoButton) && (sb == static_cast<unsigned int>(defaultButton))))
      msgBox.setDefaultButton(button);
  }

  // Force labels the user can select no matter what the current style
  // sheet says.
  msgBox.setTextInteractionFlags(Qt::TextBrowserInteraction);

  if (msgBox.exec() == -1)
    return QMessageBox::Cancel;

  return msgBox.standardButton(msgBox.clickedButton());
}
Exemple #3
0
void ButtonBox::buttonClicked(QAbstractButton* button)
{
    m_clickedButton = buttonRole(button);
}