]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Alert_pimpl.C
Get rid of the static_casts.
[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 <qmessagebox.h>
14 #include <qlabel.h>
15 #include <qlineedit.h>
16 #include "ui/QAskForTextDialog.h"
17 #include "qt_helpers.h"
18 #include "gettext.h"
19
20 #include <algorithm>
21
22 #include "Alert.h"
23 #include "Alert_pimpl.h"
24
25 #include "support/BoostFormat.h"
26 #include "gettext.h"
27
28 using std::pair;
29 using std::make_pair;
30
31 int prompt_pimpl(string const & tit, string const & question,
32            int default_button, int cancel_button,
33            string const & b1, string const & b2, string const & b3)
34 {
35 #if USE_BOOST_FORMAT
36         boost::format fmt(_("LyX: %1$s"));
37         fmt % tit;
38         string const title = fmt.str();
39 #else
40         string const title = _("LyX: ") + tit;
41 #endif
42
43         int res = QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
44                 toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
45                 default_button, cancel_button);
46
47         // Qt bug: can return -1 on cancel or WM close, despite the docs.
48         if (res == -1)
49                 res = cancel_button;
50         return res;
51 }
52
53
54 void warning_pimpl(string const & tit, string const & message)
55 {
56 #if USE_BOOST_FORMAT
57         boost::format fmt(_("LyX: %1$s"));
58         fmt % tit;
59         string const title = fmt.str();
60 #else
61         string const title = _("LyX: ") + tit;
62 #endif
63         QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
64 }
65
66
67 void error_pimpl(string const & tit, string const & message)
68 {
69 #if USE_BOOST_FORMAT
70         boost::format fmt(_("LyX: %1$s"));
71         fmt % tit;
72         string const title = fmt.str();
73 #else
74         string const title = _("LyX: ") + tit;
75 #endif
76         QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
77 }
78
79
80 void information_pimpl(string const & tit, string const & message)
81 {
82 #if USE_BOOST_FORMAT
83         boost::format fmt(_("LyX: %1$s"));
84         fmt % tit;
85         string const title = fmt.str();
86 #else
87         string const title = _("LyX: ") + tit;
88 #endif
89         QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
90 }
91
92
93 pair<bool, string> const
94 askForText_pimpl(string const & msg, string const & dflt)
95 {
96 #if USE_BOOST_FORMAT
97         boost::format fmt(_("LyX: %1$s"));
98         fmt % msg;
99         string const title = fmt.str();
100 #else
101         string const title = _("LyX: ") + msg;
102 #endif
103         QAskForTextDialog d(0, toqstr(title), true);
104         // less than ideal !
105         d.askLA->setText(toqstr('&' + msg));
106         d.askLE->setText(toqstr(dflt));
107         d.askLE->setFocus();
108         int ret = d.exec();
109
110         d.hide();
111
112         if (ret)
113                 return make_pair<bool, string>(true, fromqstr(d.askLE->text()));
114         else
115                 return make_pair<bool, string>(false, string());
116 }