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>
31 using lyx::support::bformat;
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)
42 string const title = bformat(_("LyX: %1$s"), tit);
44 QWidget * const parent = qApp->focusWidget() ?
45 qApp->focusWidget() : qApp->mainWidget();
47 int res = QMessageBox::information(parent,
49 toqstr(formatted(question)),
52 b3.empty() ? QString::null : toqstr(b3),
53 default_button, cancel_button);
55 // Qt bug: can return -1 on cancel or WM close, despite the docs.
62 void warning_pimpl(string const & tit, string const & message)
64 QWidget * const parent = qApp->focusWidget() ?
65 qApp->focusWidget() : qApp->mainWidget();
67 string const title = bformat(_("LyX: %1$s"), tit);
68 QMessageBox::warning(parent,
70 toqstr(formatted(message)));
74 void error_pimpl(string const & tit, string const & message)
76 QWidget * const parent = qApp->focusWidget() ?
77 qApp->focusWidget() : qApp->mainWidget();
79 string const title = bformat(_("LyX: %1$s"), tit);
80 QMessageBox::critical(parent,
82 toqstr(formatted(message)));
86 void information_pimpl(string const & tit, string const & message)
88 QWidget * const parent = qApp->focusWidget() ?
89 qApp->focusWidget() : qApp->mainWidget();
91 string const title = bformat(_("LyX: %1$s"), tit);
92 QMessageBox::information(parent,
94 toqstr(formatted(message)));
98 pair<bool, string> const
99 askForText_pimpl(string const & msg, string const & dflt)
101 QWidget * const parent = qApp->focusWidget() ?
102 qApp->focusWidget() : qApp->mainWidget();
104 string const title = bformat(_("LyX: %1$s"), msg);
107 QString text = QInputDialog::getText(parent,
113 if (ok && !text.isEmpty())
114 return make_pair<bool, string>(true, fromqstr(text));
116 return make_pair<bool, string>(false, string());