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