15 #include <QAbstractButton>
17 #include <QDialogButtonBox>
18 #include <QMessageBox>
20 #include <QPushButton>
22 #include "../util/btassert.h"
29 void replaceText(QDialogButtonBox *box, QDialogButtonBox::StandardButton flag,
30 const QString &text) {
31 QPushButton *button(box->button(flag));
32 if (button !=
nullptr) {
33 button->setText(text);
41 QMessageBox::StandardButtons buttons,
42 QMessageBox::StandardButton defaultButton)
44 QMessageBox messageBox(icon, title, text, QMessageBox::Ok, parent);
45 messageBox.setTextFormat(Qt::RichText);
47 QDialogButtonBox* box =
dynamic_cast<QDialogButtonBox*
>(messageBox.button(QMessageBox::Ok)->parent());
49 messageBox.setStandardButtons(buttons);
50 messageBox.setDefaultButton(defaultButton);
52 return static_cast<QMessageBox::StandardButton
>(messageBox.exec());
59 const bool signalsWereBlocked = action->blockSignals(
true);
60 action->setChecked(checked);
61 action->blockSignals(signalsWereBlocked);
65 replaceText(box, QDialogButtonBox::Ok , QPushButton::tr(
"OK" ,
"Dialog Button"));
66 replaceText(box, QDialogButtonBox::Open , QPushButton::tr(
"Open" ,
"Dialog Button"));
67 replaceText(box, QDialogButtonBox::Save , QPushButton::tr(
"Save" ,
"Dialog Button"));
68 replaceText(box, QDialogButtonBox::Cancel , QPushButton::tr(
"Cancel" ,
"Dialog Button"));
69 replaceText(box, QDialogButtonBox::Close , QPushButton::tr(
"Close" ,
"Dialog Button"));
70 replaceText(box, QDialogButtonBox::Discard , QPushButton::tr(
"Discard" ,
"Dialog Button"));
71 replaceText(box, QDialogButtonBox::Apply , QPushButton::tr(
"Apply" ,
"Dialog Button"));
72 replaceText(box, QDialogButtonBox::Reset , QPushButton::tr(
"Reset" ,
"Dialog Button"));
73 replaceText(box, QDialogButtonBox::RestoreDefaults, QPushButton::tr(
"Restore defaults",
"Dialog Button"));
74 replaceText(box, QDialogButtonBox::Help , QPushButton::tr(
"Help" ,
"Dialog Button"));
75 replaceText(box, QDialogButtonBox::SaveAll , QPushButton::tr(
"Save All" ,
"Dialog Button"));
76 replaceText(box, QDialogButtonBox::Yes , QPushButton::tr(
"Yes" ,
"Dialog Button"));
77 replaceText(box, QDialogButtonBox::YesToAll, QPushButton::tr(
"Yes to all",
"Dialog Button"));
78 replaceText(box, QDialogButtonBox::No , QPushButton::tr(
"No" ,
"Dialog Button"));
79 replaceText(box, QDialogButtonBox::NoToAll , QPushButton::tr(
"No to all" ,
"Dialog Button"));
82 QMessageBox::StandardButton
showWarning(
QWidget * parent,
const QString & title,
const QString & text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
83 return bt_messageBox(QMessageBox::Warning, parent, title, text, buttons, defaultButton);
86 QMessageBox::StandardButton
showInformation(
QWidget * parent,
const QString & title,
const QString & text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
87 return bt_messageBox(QMessageBox::Information, parent, title, text, buttons, defaultButton);
90 QMessageBox::StandardButton
showCritical(
QWidget * parent,
const QString & title,
const QString & text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
91 return bt_messageBox(QMessageBox::Critical, parent, title, text, buttons, defaultButton);
94 QMessageBox::StandardButton
showQuestion(
QWidget * parent,
const QString & title,
const QString & text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
95 return bt_messageBox(QMessageBox::Question, parent, title, text, buttons, defaultButton);
QMessageBox::StandardButton bt_messageBox(QMessageBox::Icon icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
void replaceText(QDialogButtonBox *box, QDialogButtonBox::StandardButton flag, const QString &text)
void prepareDialogBox(QDialogButtonBox *box)
void setQActionCheckedNoTrigger(QAction *const action, const bool checked)
QMessageBox::StandardButton showQuestion(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton showInformation(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton showCritical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton showWarning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)