File: JS8MessageBox.cpp

package info (click to toggle)
js8call 2.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,655; sh: 898; python: 132; ansic: 102; makefile: 4
file content (101 lines) | stat: -rw-r--r-- 4,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "JS8MessageBox.h"

#include <QCoreApplication>
#include <QDialogButtonBox>
#include <QPushButton>

#include "revision_utils.h"

JS8MessageBox::JS8MessageBox(QWidget *parent) : QMessageBox{parent} {
    setWindowTitle(program_title());
}

JS8MessageBox::JS8MessageBox(Icon icon, QString const &text,
                             StandardButtons buttons, QWidget *parent,
                             Qt::WindowFlags flags)
    : QMessageBox{icon,   QCoreApplication::applicationName(),
                  text,   buttons,
                  parent, flags} {}

void JS8MessageBox::about_message(QWidget *parent, QString const &text) {
    QMessageBox::about(parent, program_title(), text);
}

void JS8MessageBox::about_Qt_message(QWidget *parent) {
    QMessageBox::aboutQt(parent, program_title());
}

namespace {
QMessageBox::StandardButton
show_it(QWidget *parent, JS8MessageBox::Icon icon, QString const &text,
        QString const &informative, QString const &detail,
        JS8MessageBox::StandardButtons buttons,
        JS8MessageBox::StandardButton default_button) {
    JS8MessageBox mb{icon, text, JS8MessageBox::NoButton, parent};
    QDialogButtonBox *button_box = mb.findChild<QDialogButtonBox *>();
    Q_ASSERT(button_box);

    uint mask = JS8MessageBox::FirstButton;
    while (mask <= JS8MessageBox::LastButton) {
        uint sb = buttons & mask;
        mask <<= 1;
        if (!sb)
            continue;
        QPushButton *button =
            mb.addButton(static_cast<JS8MessageBox::StandardButton>(sb));
        // Choose the first accept role as the default
        if (mb.defaultButton())
            continue;
        if ((default_button == JS8MessageBox::NoButton &&
             button_box->buttonRole(button) == QDialogButtonBox::AcceptRole) ||
            (default_button != JS8MessageBox::NoButton &&
             sb == static_cast<uint>(default_button)))
            mb.setDefaultButton(button);
    }
    mb.setInformativeText(informative);
    mb.setDetailedText(detail);
    if (mb.exec() == -1)
        return JS8MessageBox::Cancel;
    return mb.standardButton(mb.clickedButton());
}
} // namespace

auto JS8MessageBox::information_message(QWidget *parent, QString const &text,
                                        QString const &informative,
                                        QString const &detail,
                                        StandardButtons buttons,
                                        StandardButton default_button)
    -> StandardButton {
    return show_it(parent, Information, text, informative, detail, buttons,
                   default_button);
}

auto JS8MessageBox::query_message(QWidget *parent, QString const &text,
                                  QString const &informative,
                                  QString const &detail,
                                  StandardButtons buttons,
                                  StandardButton default_button)
    -> StandardButton {
    return show_it(parent, Question, text, informative, detail, buttons,
                   default_button);
}

auto JS8MessageBox::warning_message(QWidget *parent, QString const &text,
                                    QString const &informative,
                                    QString const &detail,
                                    StandardButtons buttons,
                                    StandardButton default_button)
    -> StandardButton {
    return show_it(parent, Warning, text, informative, detail, buttons,
                   default_button);
}

auto JS8MessageBox::critical_message(QWidget *parent, QString const &text,
                                     QString const &informative,
                                     QString const &detail,
                                     StandardButtons buttons,
                                     StandardButton default_button)
    -> StandardButton {
    return show_it(parent, Critical, text, informative, detail, buttons,
                   default_button);
}