3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "GuiDialog.h"
15 #include "qt_helpers.h"
16 #include "frontends/LyXView.h"
18 #include <QCloseEvent>
27 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
28 : Dialog(lv), is_closing_(false), name_(name)
32 GuiDialog::~GuiDialog()
37 void GuiDialog::setViewTitle(docstring const & title)
39 setWindowTitle("LyX: " + toqstr(title));
43 void GuiDialog::setButtonsValid(bool valid)
49 void GuiDialog::slotApply()
56 void GuiDialog::slotOK()
66 void GuiDialog::slotClose()
73 void GuiDialog::slotRestore()
75 // Tell the controller that a request to refresh the dialog's contents
76 // has been received. It's up to the controller to supply the necessary
77 // info by calling GuiDialog::updateView().
82 void GuiDialog::checkStatus()
84 // buffer independant dialogs are always active.
85 // This check allows us leave canApply unimplemented for some dialogs.
86 if (!isBufferDependent())
89 // deactivate the dialog if we have no buffer
90 if (!isBufferAvailable()) {
91 bc().setReadOnly(true);
95 // check whether this dialog may be active
97 bool const readonly = isBufferReadonly();
98 bc().setReadOnly(readonly);
99 // refreshReadOnly() is too generous in _enabling_ widgets
100 // update dialog to disable disabled widgets again
102 if (!readonly || canApplyToReadOnly())
106 bc().setReadOnly(true);
111 bool GuiDialog::isVisibleView() const
113 return QDialog::isVisible();
117 void GuiDialog::showView()
119 QSize const hint = sizeHint();
120 if (hint.height() >= 0 && hint.width() >= 0)
121 setMinimumSize(hint);
123 updateView(); // make sure its up-to-date
127 if (QWidget::isVisible()) {
137 void GuiDialog::hideView()
143 void GuiDialog::changed()
147 bc().setValid(isValid());
151 void GuiDialog::updateView()
153 setUpdatesEnabled(false);
155 // protect the BC from unwarranted state transitions
160 setUpdatesEnabled(true);
165 void GuiDialog::showData(string const & data)
167 if (isBufferDependent() && !isBufferAvailable())
170 if (!initialiseParams(data)) {
171 lyxerr << "Dialog \"" << name_
172 << "\" failed to translate the data "
173 "string passed to show()" << std::endl;
177 bc().setReadOnly(isBufferReadonly());
179 // The widgets may not be valid, so refresh the button controller
184 void GuiDialog::updateData(string const & data)
186 if (isBufferDependent() && !isBufferAvailable())
189 if (!initialiseParams(data)) {
190 lyxerr << "Dialog \"" << name_
191 << "\" could not be initialized" << std::endl;
195 bc().setReadOnly(isBufferReadonly());
197 // The widgets may not be valid, so refresh the button controller
202 void GuiDialog::hide()
204 if (!isVisibleView())
209 Dialog::disconnect(name_);
213 void GuiDialog::apply()
215 if (isBufferDependent()) {
216 if (!isBufferAvailable() ||
217 (isBufferReadonly() && !canApplyToReadOnly()))
224 if (disconnectOnApply() && !is_closing_) {
225 Dialog::disconnect(name_);
226 initialiseParams(string());
232 void GuiDialog::showEvent(QShowEvent * e)
234 #if (QT_VERSION >= 0x040200)
236 string key = name_ + "/geometry";
237 restoreGeometry(settings.value(key.c_str()).toByteArray());
239 QDialog::showEvent(e);
243 void GuiDialog::closeEvent(QCloseEvent * e)
245 #if (QT_VERSION >= 0x040200)
247 string key = name_ + "/geometry";
248 settings.setValue(key.c_str(), saveGeometry());
250 QDialog::closeEvent(e);
253 } // namespace frontend
257 /////////////////////////////////////////////////////////////////////
259 // Command based dialogs
261 /////////////////////////////////////////////////////////////////////
263 #include "FuncRequest.h"
264 #include "insets/InsetCommand.h"
272 GuiCommand::GuiCommand(LyXView & lv, string const & name)
273 : GuiDialog(lv, name), params_(name), lfun_name_(name)
278 bool GuiCommand::initialiseParams(string const & data)
280 // The name passed with LFUN_INSET_APPLY is also the name
281 // used to identify the mailer.
282 InsetCommandMailer::string2params(lfun_name_, data, params_);
287 void GuiCommand::dispatchParams()
289 if (lfun_name_.empty())
293 InsetCommandMailer::params2string(lfun_name_, params_);
294 dispatch(FuncRequest(getLfun(), lfun));
297 } // namespace frontend
300 #include "GuiDialog_moc.cpp"