2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2006-04-24 13:25:50 +00:00
|
|
|
* \file qt4/Alert_pimpl.C
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Alert_pimpl.h"
|
|
|
|
#include "Alert.h"
|
|
|
|
|
2007-04-24 08:56:28 +00:00
|
|
|
#include "ui/AskForTextUi.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-01-23 12:38:20 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using lyx::support::bformat;
|
2006-09-11 08:54:10 +00:00
|
|
|
using lyx::docstring;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MessageBox: public QMessageBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MessageBox(QWidget * parent = 0): QMessageBox(parent)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
int prompt_pimpl(docstring const & tit, docstring const & question,
|
2006-03-05 17:24:44 +00:00
|
|
|
int default_button, int cancel_button,
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const & b1, docstring const & b2, docstring const & b3)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const title = bformat(_("LyX: %1$s"), tit);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
MessageBox mb;
|
|
|
|
|
2006-12-21 20:29:15 +00:00
|
|
|
// For some reason, sometimes Qt uses an hourglass or watch cursor when
|
|
|
|
// displaying the alert. Hence, we ask for the standard cursor shape.
|
|
|
|
// This call has no effect if the cursor has not been overridden.
|
|
|
|
qApp->changeOverrideCursor(Qt::ArrowCursor);
|
|
|
|
|
2006-08-17 08:37:26 +00:00
|
|
|
// FIXME replace that with theApp->gui()->currentView()
|
2006-10-24 15:01:07 +00:00
|
|
|
int res = mb.information(qApp->focusWidget(),
|
2006-03-05 17:24:44 +00:00
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(question)),
|
|
|
|
toqstr(b1),
|
|
|
|
toqstr(b2),
|
|
|
|
b3.empty() ? QString::null : toqstr(b3),
|
|
|
|
default_button, cancel_button);
|
|
|
|
|
|
|
|
// Qt bug: can return -1 on cancel or WM close, despite the docs.
|
|
|
|
if (res == -1)
|
|
|
|
res = cancel_button;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
void warning_pimpl(docstring const & tit, docstring const & message)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const title = bformat(_("LyX: %1$s"), tit);
|
2006-10-24 15:01:07 +00:00
|
|
|
|
2007-01-23 12:38:20 +00:00
|
|
|
if (theApp() == 0) {
|
|
|
|
int argc = 1;
|
|
|
|
char * argv[1];
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
QMessageBox::warning(0,
|
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(message)));
|
|
|
|
return;
|
|
|
|
}
|
2006-10-24 15:01:07 +00:00
|
|
|
MessageBox mb;
|
|
|
|
mb.warning(qApp->focusWidget(),
|
2006-03-05 17:24:44 +00:00
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
void error_pimpl(docstring const & tit, docstring const & message)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const title = bformat(_("LyX: %1$s"), tit);
|
2007-01-23 12:38:20 +00:00
|
|
|
if (theApp() == 0) {
|
|
|
|
int argc = 1;
|
|
|
|
char * argv[1];
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
QMessageBox::critical(0,
|
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(message)));
|
|
|
|
return;
|
|
|
|
}
|
2006-10-24 15:01:07 +00:00
|
|
|
MessageBox mb;
|
|
|
|
mb.critical(qApp->focusWidget(),
|
2006-03-05 17:24:44 +00:00
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
void information_pimpl(docstring const & tit, docstring const & message)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const title = bformat(_("LyX: %1$s"), tit);
|
2006-10-24 15:01:07 +00:00
|
|
|
MessageBox mb;
|
|
|
|
mb.information(qApp->focusWidget(),
|
2006-03-05 17:24:44 +00:00
|
|
|
toqstr(title),
|
|
|
|
toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
pair<bool, docstring> const
|
|
|
|
askForText_pimpl(docstring const & msg, docstring const & dflt)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const title = bformat(_("LyX: %1$s"), msg);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
bool ok;
|
2006-08-17 08:37:26 +00:00
|
|
|
QString text = QInputDialog::getText(qApp->focusWidget(),
|
2006-03-05 17:24:44 +00:00
|
|
|
toqstr(title),
|
2006-09-11 08:54:10 +00:00
|
|
|
toqstr(lyx::char_type('&') + msg),
|
2006-03-05 17:24:44 +00:00
|
|
|
QLineEdit::Normal,
|
|
|
|
toqstr(dflt), &ok);
|
|
|
|
|
|
|
|
if (ok && !text.isEmpty())
|
2006-09-11 08:54:10 +00:00
|
|
|
return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2006-09-11 08:54:10 +00:00
|
|
|
return make_pair<bool, docstring>(false, docstring());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|