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