]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Alert_pimpl.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / Alert_pimpl.C
1 /**
2  * \file qt4/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  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "Alert_pimpl.h"
15 #include "Alert.h"
16
17 #include "ui/QAskForTextUi.h"
18 #include "qt_helpers.h"
19
20 #include "gettext.h"
21
22 #include <QApplication>
23 #include <QMessageBox>
24 #include <QLabel>
25 #include <QLineEdit>
26 #include <QDialog>
27 #include <QInputDialog>
28
29 #include <algorithm>
30
31 using lyx::support::bformat;
32
33 using std::pair;
34 using std::make_pair;
35 using std::string;
36
37
38 int prompt_pimpl(string const & tit, string const & question,
39                  int default_button, int cancel_button,
40                  string const & b1, string const & b2, string const & b3)
41 {
42         string const title = bformat(_("LyX: %1$s"), tit);
43
44         QWidget * const parent = qApp->focusWidget() ?
45                 qApp->focusWidget() : qApp->mainWidget();
46
47         int res = QMessageBox::information(parent,
48                                            toqstr(title),
49                                            toqstr(formatted(question)),
50                                            toqstr(b1),
51                                            toqstr(b2),
52                                            b3.empty() ? QString::null : toqstr(b3),
53                                            default_button, cancel_button);
54
55         // Qt bug: can return -1 on cancel or WM close, despite the docs.
56         if (res == -1)
57                 res = cancel_button;
58         return res;
59 }
60
61
62 void warning_pimpl(string const & tit, string const & message)
63 {
64         QWidget * const parent = qApp->focusWidget() ?
65                 qApp->focusWidget() : qApp->mainWidget();
66
67         string const title = bformat(_("LyX: %1$s"), tit);
68         QMessageBox::warning(parent,
69                              toqstr(title),
70                              toqstr(formatted(message)));
71 }
72
73
74 void error_pimpl(string const & tit, string const & message)
75 {
76         QWidget * const parent = qApp->focusWidget() ?
77                 qApp->focusWidget() : qApp->mainWidget();
78
79         string const title = bformat(_("LyX: %1$s"), tit);
80         QMessageBox::critical(parent,
81                               toqstr(title),
82                               toqstr(formatted(message)));
83 }
84
85
86 void information_pimpl(string const & tit, string const & message)
87 {
88         QWidget * const parent = qApp->focusWidget() ?
89                 qApp->focusWidget() : qApp->mainWidget();
90
91         string const title = bformat(_("LyX: %1$s"), tit);
92         QMessageBox::information(parent,
93                                  toqstr(title),
94                                  toqstr(formatted(message)));
95 }
96
97
98 pair<bool, string> const
99 askForText_pimpl(string const & msg, string const & dflt)
100 {
101         QWidget * const parent = qApp->focusWidget() ?
102                 qApp->focusWidget() : qApp->mainWidget();
103
104         string const title = bformat(_("LyX: %1$s"), msg);
105
106         bool ok;
107         QString text = QInputDialog::getText(parent,
108                 toqstr(title),
109                 toqstr('&' + msg),
110                 QLineEdit::Normal,
111                 toqstr(dflt), &ok);
112
113         if (ok && !text.isEmpty())
114                 return make_pair<bool, string>(true, fromqstr(text));
115         else
116                 return make_pair<bool, string>(false, string());
117 }