Branch data Line data Source code
1 : : #pragma once
2 : :
3 : : #include <QMessageBox>
4 : :
5 : : // QMessageBox's convenience functions leave textFormat at Qt::AutoText.
6 : : // Dynamic server- or DAV-controlled strings can therefore be interpreted as
7 : : // rich text. Keep every dynamic dialog on this small, explicit PlainText
8 : : // path; callers still get the normal native QMessageBox behavior.
9 : : namespace PlainTextMessageBox {
10 : :
11 : 4 : inline QMessageBox::StandardButton question(
12 : : QWidget *parent, const QString &title, const QString &text,
13 : : QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
14 : : QMessageBox::StandardButton defaultButton = QMessageBox::NoButton) {
15 [ + - ]: 4 : QMessageBox box(QMessageBox::Question, title, text, buttons, parent);
16 [ + - ]: 4 : box.setTextFormat(Qt::PlainText);
17 [ + + ]: 4 : if (defaultButton != QMessageBox::NoButton)
18 [ + - ]: 2 : box.setDefaultButton(defaultButton);
19 [ + - ]: 8 : return static_cast<QMessageBox::StandardButton>(box.exec());
20 : 4 : }
21 : :
22 : 2 : inline void warning(QWidget *parent, const QString &title,
23 : : const QString &text) {
24 [ + - ]: 2 : QMessageBox box(QMessageBox::Warning, title, text, QMessageBox::Ok, parent);
25 [ + - ]: 2 : box.setTextFormat(Qt::PlainText);
26 [ + - ]: 2 : box.exec();
27 : 2 : }
28 : :
29 : : } // namespace PlainTextMessageBox
|