X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiAlert.cpp;h=2a8affa33a6cfc1b2927bf28d23695d49487892c;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=b53f20f738524fdf452db0b8a7ae58c0918e4788;hpb=03fb3b0aece698bb2319f9f86dfb93c58924ae09;p=lyx.git diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index b53f20f738..2a8affa33a 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Jürgen Spitzmüller * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. @@ -13,21 +14,24 @@ #include "alert.h" + #include "frontends/Application.h" #include "qt_helpers.h" -#include "support/debug.h" #include "LyX.h" // for lyx::use_gui -#include "ui_AskForTextUi.h" #include "support/gettext.h" +#include "support/debug.h" #include "support/docstring.h" #include "support/lstrings.h" +#include "support/ProgressInterface.h" #include +#include #include #include #include +#include #include #include @@ -39,6 +43,8 @@ namespace lyx { namespace frontend { + + static docstring const formatted(docstring const & text) { const int w = 80; @@ -99,13 +105,28 @@ static docstring const formatted(docstring const & text) } +void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode) +{ + int argc = 1; + char * argv[1]; + QApplication app(argc, argv); + switch (mode) + { + case QMessageBox::Information: QMessageBox::information(0, title, msg); break; + case QMessageBox::Warning: QMessageBox::warning(0, title, msg); break; + case QMessageBox::Critical: QMessageBox::critical(0, title, msg); break; + default: break; + } +} + + namespace Alert { int prompt(docstring const & title0, docstring const & question, int default_button, int cancel_button, docstring const & b1, docstring const & b2, docstring const & b3) { - lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl; + //lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl; if (!use_gui || lyxerr.debugging()) { lyxerr << title0 << '\n' << "----------------------------------------\n" @@ -123,13 +144,12 @@ int prompt(docstring const & title0, docstring const & question, docstring const title = bformat(_("LyX: %1$s"), title0); - // For some reason, sometimes Qt uses an hourglass or watch cursor when + // For some reason, sometimes Qt uses a 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); + qApp->setOverrideCursor(Qt::ArrowCursor); // FIXME replace that with guiApp->currentView() - LYXERR0("FOCUS: " << qApp->focusWidget()); + //LYXERR0("FOCUS: " << qApp->focusWidget()); int res = QMessageBox::information(qApp->focusWidget(), toqstr(title), toqstr(formatted(question)), @@ -138,6 +158,8 @@ int prompt(docstring const & title0, docstring const & question, b3.empty() ? QString::null : toqstr(b3), default_button, cancel_button); + qApp->restoreOverrideCursor(); + // Qt bug: can return -1 on cancel or WM close, despite the docs. if (res == -1) res = cancel_button; @@ -145,7 +167,8 @@ int prompt(docstring const & title0, docstring const & question, } -void warning(docstring const & title0, docstring const & message) +void warning(docstring const & title0, docstring const & message, + bool const & askshowagain) { lyxerr << "Warning: " << title0 << '\n' << "----------------------------------------\n" @@ -157,17 +180,25 @@ void warning(docstring const & title0, docstring const & message) docstring const title = bformat(_("LyX: %1$s"), title0); if (theApp() == 0) { - int argc = 1; - char * argv[1]; - QApplication app(argc, argv); - QMessageBox::warning(0, - toqstr(title), - toqstr(formatted(message))); + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Warning); return; } - QMessageBox::warning(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + + // Don't use a hourglass cursor while displaying the alert + qApp->setOverrideCursor(Qt::ArrowCursor); + + if (!askshowagain) { + ProgressInterface::instance()->warning( + toqstr(title), + toqstr(formatted(message))); + } else { + ProgressInterface::instance()->toggleWarning( + toqstr(title), + toqstr(message), + toqstr(formatted(message))); + } + + qApp->restoreOverrideCursor(); } @@ -181,18 +212,20 @@ void error(docstring const & title0, docstring const & message) return; docstring const title = bformat(_("LyX: %1$s"), title0); + if (theApp() == 0) { - int argc = 1; - char * argv[1]; - QApplication app(argc, argv); - QMessageBox::critical(0, - toqstr(title), - toqstr(formatted(message))); + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Critical); return; } - QMessageBox::critical(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + + // Don't use a hourglass cursor while displaying the alert + qApp->setOverrideCursor(Qt::ArrowCursor); + + ProgressInterface::instance()->error( + toqstr(title), + toqstr(formatted(message))); + + qApp->restoreOverrideCursor(); } @@ -207,9 +240,20 @@ void information(docstring const & title0, docstring const & message) return; docstring const title = bformat(_("LyX: %1$s"), title0); - QMessageBox::information(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + + if (theApp() == 0) { + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Information); + return; + } + + // Don't use a hourglass cursor while displaying the alert + qApp->setOverrideCursor(Qt::ArrowCursor); + + ProgressInterface::instance()->information( + toqstr(title), + toqstr(formatted(message))); + + qApp->restoreOverrideCursor(); } @@ -236,7 +280,7 @@ bool askForText(docstring & response, docstring const & msg, QLineEdit::Normal, toqstr(dflt), &ok); - if (ok && !text.isEmpty()) { + if (ok) { response = qstring_to_ucs4(text); return true; }