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 // FIXME replace that with theApp->gui()->currentView()
63 int res = mb.information(qApp->focusWidget(),
65 toqstr(formatted(question)),
68 b3.empty() ? QString::null : toqstr(b3),
69 default_button, cancel_button);
71 // Qt bug: can return -1 on cancel or WM close, despite the docs.
78 void warning_pimpl(docstring const & tit, docstring const & message)
80 docstring const title = bformat(_("LyX: %1$s"), tit);
83 mb.warning(qApp->focusWidget(),
85 toqstr(formatted(message)));
89 void error_pimpl(docstring const & tit, docstring const & message)
91 docstring const title = bformat(_("LyX: %1$s"), tit);
93 mb.critical(qApp->focusWidget(),
95 toqstr(formatted(message)));
99 void information_pimpl(docstring const & tit, docstring const & message)
101 docstring const title = bformat(_("LyX: %1$s"), tit);
103 mb.information(qApp->focusWidget(),
105 toqstr(formatted(message)));
109 pair<bool, docstring> const
110 askForText_pimpl(docstring const & msg, docstring const & dflt)
112 docstring const title = bformat(_("LyX: %1$s"), msg);
115 QString text = QInputDialog::getText(qApp->focusWidget(),
117 toqstr(lyx::char_type('&') + msg),
121 if (ok && !text.isEmpty())
122 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
124 return make_pair<bool, docstring>(false, docstring());