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 "qt_helpers.h"
19 #include "ui_AskForTextUi.h"
21 #include "frontends/Application.h"
25 #include <QApplication>
26 #include <QMessageBox>
30 #include <QInputDialog>
36 using lyx::support::bformat;
40 static docstring const formatted(docstring const & text)
48 docstring::size_type curpos = 0;
52 docstring::size_type const nxtpos1 = text.find(' ', curpos);
53 docstring::size_type const nxtpos2 = text.find('\n', curpos);
54 docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
56 docstring const word =
57 nxtpos == docstring::npos ?
59 text.substr(curpos, nxtpos - curpos);
61 bool const newline = (nxtpos2 != docstring::npos &&
64 docstring const line_plus_word =
65 line.empty() ? word : line + char_type(' ') + word;
67 // FIXME: make w be size_t
68 if (int(line_plus_word.length()) >= w) {
69 sout += line + char_type('\n');
71 sout += word + char_type('\n');
78 sout += line_plus_word + char_type('\n');
83 line += char_type(' ');
87 if (nxtpos == docstring::npos) {
100 int prompt_pimpl(docstring const & tit, docstring const & question,
101 int default_button, int cancel_button,
102 docstring const & b1, docstring const & b2, docstring const & b3)
104 docstring const title = bformat(_("LyX: %1$s"), tit);
108 // For some reason, sometimes Qt uses an hourglass or watch cursor when
109 // displaying the alert. Hence, we ask for the standard cursor shape.
110 // This call has no effect if the cursor has not been overridden.
111 qApp->changeOverrideCursor(Qt::ArrowCursor);
113 // FIXME replace that with theApp->gui()->currentView()
114 int res = QMessageBox::information(qApp->focusWidget(),
116 toqstr(formatted(question)),
119 b3.empty() ? QString::null : toqstr(b3),
120 default_button, cancel_button);
122 // Qt bug: can return -1 on cancel or WM close, despite the docs.
129 void warning_pimpl(docstring const & tit, docstring const & message)
131 docstring const title = bformat(_("LyX: %1$s"), tit);
136 QApplication app(argc, argv);
137 QMessageBox::warning(0,
139 toqstr(formatted(message)));
142 QMessageBox::warning(qApp->focusWidget(),
144 toqstr(formatted(message)));
148 void error_pimpl(docstring const & tit, docstring const & message)
150 docstring const title = bformat(_("LyX: %1$s"), tit);
154 QApplication app(argc, argv);
155 QMessageBox::critical(0,
157 toqstr(formatted(message)));
160 QMessageBox::critical(qApp->focusWidget(),
162 toqstr(formatted(message)));
166 void information_pimpl(docstring const & tit, docstring const & message)
168 docstring const title = bformat(_("LyX: %1$s"), tit);
169 QMessageBox::information(qApp->focusWidget(),
171 toqstr(formatted(message)));
175 pair<bool, docstring> const
176 askForText_pimpl(docstring const & msg, docstring const & dflt)
178 docstring const title = bformat(_("LyX: %1$s"), msg);
181 QString text = QInputDialog::getText(qApp->focusWidget(),
183 toqstr(char_type('&') + msg),
187 if (ok && !text.isEmpty())
188 return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
190 return make_pair<bool, docstring>(false, docstring());