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.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "Alert_pimpl.h"
17 #include "ui/QAskForTextUi.h"
18 #include "qt_helpers.h"
20 #include "frontends/Application.h"
24 #include <QApplication>
25 #include <QMessageBox>
29 #include <QInputDialog>
38 using lyx::support::bformat;
43 class MessageBox: public QMessageBox
46 MessageBox(QWidget * parent = 0): QMessageBox(parent)
48 setAttribute(Qt::WA_DeleteOnClose, true);
49 setAttribute(Qt::WA_QuitOnClose, false);
53 } // anonymous namespace
56 int prompt_pimpl(docstring const & tit, docstring const & question,
57 int default_button, int cancel_button,
58 docstring const & b1, docstring const & b2, docstring const & b3)
60 docstring const title = bformat(_("LyX: %1$s"), tit);
64 // For some reason, sometimes Qt uses an hourglass or watch cursor when
65 // displaying the alert. Hence, we ask for the standard cursor shape.
66 // This call has no effect if the cursor has not been overridden.
67 qApp->changeOverrideCursor(Qt::ArrowCursor);
69 // FIXME replace that with theApp->gui()->currentView()
70 int res = mb.information(qApp->focusWidget(),
72 toqstr(formatted(question)),
75 b3.empty() ? QString::null : toqstr(b3),
76 default_button, cancel_button);
78 // Qt bug: can return -1 on cancel or WM close, despite the docs.
85 void warning_pimpl(docstring const & tit, docstring const & message)
87 docstring const title = bformat(_("LyX: %1$s"), tit);
92 QApplication app(argc, argv);
93 QMessageBox::warning(0,
95 toqstr(formatted(message)));
99 mb.warning(qApp->focusWidget(),
101 toqstr(formatted(message)));
105 void error_pimpl(docstring const & tit, docstring const & message)
107 docstring const title = bformat(_("LyX: %1$s"), tit);
111 QApplication app(argc, argv);
112 QMessageBox::critical(0,
114 toqstr(formatted(message)));
118 mb.critical(qApp->focusWidget(),
120 toqstr(formatted(message)));
124 void information_pimpl(docstring const & tit, docstring const & message)
126 docstring const title = bformat(_("LyX: %1$s"), tit);
128 mb.information(qApp->focusWidget(),
130 toqstr(formatted(message)));
134 pair<bool, docstring> const
135 askForText_pimpl(docstring const & msg, docstring const & dflt)
137 docstring const title = bformat(_("LyX: %1$s"), msg);
140 QString text = QInputDialog::getText(qApp->focusWidget(),
142 toqstr(lyx::char_type('&') + msg),
146 if (ok && !text.isEmpty())
147 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
149 return make_pair<bool, docstring>(false, docstring());