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"
22 #include <QApplication>
23 #include <QMessageBox>
27 #include <QInputDialog>
36 using lyx::support::bformat;
41 class MessageBox: public QMessageBox
44 MessageBox(QWidget * parent = 0): QMessageBox(parent)
46 setAttribute(Qt::WA_DeleteOnClose, true);
47 setAttribute(Qt::WA_QuitOnClose, false);
51 } // anonymous namespace
54 int prompt_pimpl(docstring const & tit, docstring const & question,
55 int default_button, int cancel_button,
56 docstring const & b1, docstring const & b2, docstring const & b3)
58 docstring const title = bformat(_("LyX: %1$s"), tit);
62 // For some reason, sometimes Qt uses an hourglass or watch cursor when
63 // displaying the alert. Hence, we ask for the standard cursor shape.
64 // This call has no effect if the cursor has not been overridden.
65 qApp->changeOverrideCursor(Qt::ArrowCursor);
67 // FIXME replace that with theApp->gui()->currentView()
68 int res = mb.information(qApp->focusWidget(),
70 toqstr(formatted(question)),
73 b3.empty() ? QString::null : toqstr(b3),
74 default_button, cancel_button);
76 // Qt bug: can return -1 on cancel or WM close, despite the docs.
83 void warning_pimpl(docstring const & tit, docstring const & message)
85 docstring const title = bformat(_("LyX: %1$s"), tit);
88 mb.warning(qApp->focusWidget(),
90 toqstr(formatted(message)));
94 void error_pimpl(docstring const & tit, docstring const & message)
96 docstring const title = bformat(_("LyX: %1$s"), tit);
98 mb.critical(qApp->focusWidget(),
100 toqstr(formatted(message)));
104 void information_pimpl(docstring const & tit, docstring const & message)
106 docstring const title = bformat(_("LyX: %1$s"), tit);
108 mb.information(qApp->focusWidget(),
110 toqstr(formatted(message)));
114 pair<bool, docstring> const
115 askForText_pimpl(docstring const & msg, docstring const & dflt)
117 docstring const title = bformat(_("LyX: %1$s"), msg);
120 QString text = QInputDialog::getText(qApp->focusWidget(),
122 toqstr(lyx::char_type('&') + msg),
126 if (ok && !text.isEmpty())
127 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
129 return make_pair<bool, docstring>(false, docstring());