]> git.lyx.org Git - features.git/blob - src/frontends/qt2/Alert_pimpl.C
4c4b933da84c0f6f5aa4629a13e35542b840b479
[features.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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <qmessagebox.h>
18 #include <qlabel.h>
19 #include <qlineedit.h>
20 #include "ui/QAskForTextDialog.h"
21 #include "qt_helpers.h"
22
23 #include <algorithm>
24
25 #include "Alert.h"
26 #include "Alert_pimpl.h"
27
28 #include "BoostFormat.h"
29 #include "gettext.h"
30
31 using std::pair;
32 using std::make_pair;
33
34
35 void alert_pimpl(string const & s1, string const & s2, string const & s3)
36 {
37         QMessageBox::warning(0, "LyX",
38                              toqstr(s1 + '\n' + '\n' + s2 + '\n' + s3));
39 }
40
41
42 bool askQuestion_pimpl(string const & s1, string const & s2, string const & s3)
43 {
44         return !(QMessageBox::information(0, "LyX", toqstr(s1 + '\n' + s2 + '\n' + s3),
45                 qt_("&Yes"), qt_("&No"), 0, 1));
46 }
47
48
49 int askConfirmation_pimpl(string const & s1, string const & s2, string const & s3)
50 {
51         return (QMessageBox::information(0, "LyX", toqstr(s1 + '\n' + s2 + '\n' + s3),
52                 qt_("&Yes"), qt_("&No"), qt_("&Cancel"), 0, 2)) + 1;
53 }
54
55
56 pair<bool, string> const
57 askForText_pimpl(string const & msg, string const & dflt)
58 {
59 #if USE_BOOST_FORMAT
60         boost::format fmt(qt_("LyX: %1$s"));
61         fmt % msg;
62         string const title = fmt.str();
63 #else
64         string const title = _("LyX: ") + msg;
65 #endif
66         QAskForTextDialog d(0, toqstr(title), true);
67         // less than ideal !
68         d.askLA->setText(toqstr('&' + msg));
69         d.askLE->setText(toqstr(dflt));
70         d.askLE->setFocus();
71         int ret = d.exec();
72
73         d.hide();
74
75         if (ret)
76                 return make_pair<bool, string>(true, fromqstr(d.askLE->text()));
77         else
78                 return make_pair<bool, string>(false, string());
79 }