2 * \file qt4/alert_pimpl.cpp
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_AskForTextUi.h"
18 #include "qt_helpers.h"
20 #include "frontends/Application.h"
24 #include <QApplication>
25 #include <QMessageBox>
29 #include <QInputDialog>
35 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);
90 QApplication app(argc, argv);
91 QMessageBox::warning(0,
93 toqstr(formatted(message)));
97 mb.warning(qApp->focusWidget(),
99 toqstr(formatted(message)));
103 void error_pimpl(docstring const & tit, docstring const & message)
105 docstring const title = bformat(_("LyX: %1$s"), tit);
109 QApplication app(argc, argv);
110 QMessageBox::critical(0,
112 toqstr(formatted(message)));
116 mb.critical(qApp->focusWidget(),
118 toqstr(formatted(message)));
122 void information_pimpl(docstring const & tit, docstring const & message)
124 docstring const title = bformat(_("LyX: %1$s"), tit);
126 mb.information(qApp->focusWidget(),
128 toqstr(formatted(message)));
132 pair<bool, docstring> const
133 askForText_pimpl(docstring const & msg, docstring const & dflt)
135 docstring const title = bformat(_("LyX: %1$s"), msg);
138 QString text = QInputDialog::getText(qApp->focusWidget(),
140 toqstr(char_type('&') + msg),
144 if (ok && !text.isEmpty())
145 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
147 return make_pair<bool, docstring>(false, docstring());