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;
39 static docstring const formatted(docstring const & text)
47 docstring::size_type curpos = 0;
51 docstring::size_type const nxtpos1 = text.find(' ', curpos);
52 docstring::size_type const nxtpos2 = text.find('\n', curpos);
53 docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
55 docstring const word =
56 nxtpos == docstring::npos ?
58 text.substr(curpos, nxtpos - curpos);
60 bool const newline = (nxtpos2 != docstring::npos &&
63 docstring const line_plus_word =
64 line.empty() ? word : line + char_type(' ') + word;
66 // FIXME: make w be size_t
67 if (int(line_plus_word.length()) >= w) {
68 sout += line + char_type('\n');
70 sout += word + char_type('\n');
77 sout += line_plus_word + char_type('\n');
82 line += char_type(' ');
86 if (nxtpos == docstring::npos) {
99 int prompt_pimpl(docstring const & tit, docstring const & question,
100 int default_button, int cancel_button,
101 docstring const & b1, docstring const & b2, docstring const & b3)
103 docstring const title = bformat(_("LyX: %1$s"), tit);
107 // For some reason, sometimes Qt uses an hourglass or watch cursor when
108 // displaying the alert. Hence, we ask for the standard cursor shape.
109 // This call has no effect if the cursor has not been overridden.
110 qApp->changeOverrideCursor(Qt::ArrowCursor);
112 // FIXME replace that with theApp->gui()->currentView()
113 int res = QMessageBox::information(qApp->focusWidget(),
115 toqstr(formatted(question)),
118 b3.empty() ? QString::null : toqstr(b3),
119 default_button, cancel_button);
121 // Qt bug: can return -1 on cancel or WM close, despite the docs.
128 void warning_pimpl(docstring const & tit, docstring const & message)
130 docstring const title = bformat(_("LyX: %1$s"), tit);
135 QApplication app(argc, argv);
136 QMessageBox::warning(0,
138 toqstr(formatted(message)));
141 QMessageBox::warning(qApp->focusWidget(),
143 toqstr(formatted(message)));
147 void error_pimpl(docstring const & tit, docstring const & message)
149 docstring const title = bformat(_("LyX: %1$s"), tit);
153 QApplication app(argc, argv);
154 QMessageBox::critical(0,
156 toqstr(formatted(message)));
159 QMessageBox::critical(qApp->focusWidget(),
161 toqstr(formatted(message)));
165 void information_pimpl(docstring const & tit, docstring const & message)
167 docstring const title = bformat(_("LyX: %1$s"), tit);
168 QMessageBox::information(qApp->focusWidget(),
170 toqstr(formatted(message)));
174 pair<bool, docstring> const
175 askForText_pimpl(docstring const & msg, docstring const & dflt)
177 docstring const title = bformat(_("LyX: %1$s"), msg);
180 QString text = QInputDialog::getText(qApp->focusWidget(),
182 toqstr(char_type('&') + msg),
186 if (ok && !text.isEmpty())
187 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
189 return make_pair<bool, docstring>(false, docstring());