]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Alert_pimpl.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / qt2 / Alert_pimpl.C
1 /**
2  * \file qt2/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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Alert_pimpl.h"
14 #include "Alert.h"
15
16 #include <qmessagebox.h>
17 #include <qlabel.h>
18 #include <qlineedit.h>
19 #include "ui/QAskForTextDialog.h"
20 #include "qt_helpers.h"
21 #include "gettext.h"
22
23 #include <algorithm>
24
25 using lyx::support::bformat;
26
27 using std::pair;
28 using std::make_pair;
29 using std::string;
30
31
32 int prompt_pimpl(string const & tit, string const & question,
33            int default_button, int cancel_button,
34            string const & b1, string const & b2, string const & b3)
35 {
36         string const title = bformat(_("LyX: %1$s"), tit);
37
38         int res = QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
39                 toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
40                 default_button, cancel_button);
41
42         // Qt bug: can return -1 on cancel or WM close, despite the docs.
43         if (res == -1)
44                 res = cancel_button;
45         return res;
46 }
47
48
49 void warning_pimpl(string const & tit, string const & message)
50 {
51         string const title = bformat(_("LyX: %1$s"), tit);
52         QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
53 }
54
55
56 void error_pimpl(string const & tit, string const & message)
57 {
58         string const title = bformat(_("LyX: %1$s"), tit);
59         QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
60 }
61
62
63 void information_pimpl(string const & tit, string const & message)
64 {
65         string const title = bformat(_("LyX: %1$s"), tit);
66         QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
67 }
68
69
70 pair<bool, string> const
71 askForText_pimpl(string const & msg, string const & dflt)
72 {
73         string const title = bformat(_("LyX: %1$s"), msg);
74         QAskForTextDialog d(0, toqstr(title), true);
75         // less than ideal !
76         d.askLA->setText(toqstr('&' + msg));
77         d.askLE->setText(toqstr(dflt));
78         d.askLE->setFocus();
79         int ret = d.exec();
80
81         d.hide();
82
83         if (ret)
84                 return make_pair<bool, string>(true, fromqstr(d.askLE->text()));
85         else
86                 return make_pair<bool, string>(false, string());
87 }