]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Alert_pimpl.C
remove qPixmapFromMimeSource. This caused the inclusion of Qt3 support headers which...
[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         // FIXME replace that with theApp->gui()->currentView()
45         int res = QMessageBox::information(qApp->focusWidget(),
46                                            toqstr(title),
47                                            toqstr(formatted(question)),
48                                            toqstr(b1),
49                                            toqstr(b2),
50                                            b3.empty() ? QString::null : toqstr(b3),
51                                            default_button, cancel_button);
52
53         // Qt bug: can return -1 on cancel or WM close, despite the docs.
54         if (res == -1)
55                 res = cancel_button;
56         return res;
57 }
58
59
60 void warning_pimpl(string const & tit, string const & message)
61 {
62         string const title = bformat(_("LyX: %1$s"), tit);
63         QMessageBox::warning(qApp->focusWidget(),
64                              toqstr(title),
65                              toqstr(formatted(message)));
66 }
67
68
69 void error_pimpl(string const & tit, string const & message)
70 {
71         string const title = bformat(_("LyX: %1$s"), tit);
72         QMessageBox::critical(qApp->focusWidget(),
73                               toqstr(title),
74                               toqstr(formatted(message)));
75 }
76
77
78 void information_pimpl(string const & tit, string const & message)
79 {
80         string const title = bformat(_("LyX: %1$s"), tit);
81         QMessageBox::information(qApp->focusWidget(),
82                                  toqstr(title),
83                                  toqstr(formatted(message)));
84 }
85
86
87 pair<bool, string> const
88 askForText_pimpl(string const & msg, string const & dflt)
89 {
90         string const title = bformat(_("LyX: %1$s"), msg);
91
92         bool ok;
93         QString text = QInputDialog::getText(qApp->focusWidget(),
94                 toqstr(title),
95                 toqstr('&' + msg),
96                 QLineEdit::Normal,
97                 toqstr(dflt), &ok);
98
99         if (ok && !text.isEmpty())
100                 return make_pair<bool, string>(true, fromqstr(text));
101         else
102                 return make_pair<bool, string>(false, string());
103 }