]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Alert_pimpl.C
- LyX is dead slow, so the least we can do is use anti-alised text
[lyx.git] / src / frontends / qt4 / Alert_pimpl.C
1 /**
2  * \file qt4/Alert_pimpl.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "Alert_pimpl.h"
15 #include "Alert.h"
16
17 #include "ui/QAskForTextUi.h"
18 #include "qt_helpers.h"
19
20 #include "gettext.h"
21
22 #include <QApplication>
23 #include <QMessageBox>
24 #include <QLabel>
25 #include <QLineEdit>
26 #include <QDialog>
27 #include <QInputDialog>
28
29 #include <algorithm>
30
31
32 namespace lyx {
33
34 using lyx::support::bformat;
35 using lyx::docstring;
36
37 using std::pair;
38 using std::make_pair;
39
40
41 int prompt_pimpl(docstring const & tit, docstring const & question,
42                  int default_button, int cancel_button,
43                  docstring const & b1, docstring const & b2, docstring const & b3)
44 {
45         docstring const title = bformat(_("LyX: %1$s"), tit);
46
47         // FIXME replace that with theApp->gui()->currentView()
48         int res = QMessageBox::information(qApp->focusWidget(),
49                                            toqstr(title),
50                                            toqstr(formatted(question)),
51                                            toqstr(b1),
52                                            toqstr(b2),
53                                            b3.empty() ? QString::null : toqstr(b3),
54                                            default_button, cancel_button);
55
56         // Qt bug: can return -1 on cancel or WM close, despite the docs.
57         if (res == -1)
58                 res = cancel_button;
59         return res;
60 }
61
62
63 void warning_pimpl(docstring const & tit, docstring const & message)
64 {
65         docstring const title = bformat(_("LyX: %1$s"), tit);
66         QMessageBox::warning(qApp->focusWidget(),
67                              toqstr(title),
68                              toqstr(formatted(message)));
69 }
70
71
72 void error_pimpl(docstring const & tit, docstring const & message)
73 {
74         docstring const title = bformat(_("LyX: %1$s"), tit);
75         QMessageBox::critical(qApp->focusWidget(),
76                               toqstr(title),
77                               toqstr(formatted(message)));
78 }
79
80
81 void information_pimpl(docstring const & tit, docstring const & message)
82 {
83         docstring const title = bformat(_("LyX: %1$s"), tit);
84         QMessageBox::information(qApp->focusWidget(),
85                                  toqstr(title),
86                                  toqstr(formatted(message)));
87 }
88
89
90 pair<bool, docstring> const
91 askForText_pimpl(docstring const & msg, docstring const & dflt)
92 {
93         docstring const title = bformat(_("LyX: %1$s"), msg);
94
95         bool ok;
96         QString text = QInputDialog::getText(qApp->focusWidget(),
97                 toqstr(title),
98                 toqstr(lyx::char_type('&') + msg),
99                 QLineEdit::Normal,
100                 toqstr(dflt), &ok);
101
102         if (ok && !text.isEmpty())
103                 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
104         else
105                 return make_pair<bool, docstring>(false, docstring());
106 }
107
108
109 } // namespace lyx