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"
17 #include <QCloseEvent>
26 GuiDialog::GuiDialog(GuiView & lv, std::string const & name)
27 : Dialog(lv), is_closing_(false), name_(name)
31 GuiDialog::~GuiDialog()
36 void GuiDialog::setViewTitle(docstring const & title)
38 setWindowTitle("LyX: " + toqstr(title));
42 void GuiDialog::setButtonsValid(bool valid)
48 void GuiDialog::slotApply()
55 void GuiDialog::slotOK()
65 void GuiDialog::slotClose()
72 void GuiDialog::slotRestore()
74 // Tell the controller that a request to refresh the dialog's contents
75 // has been received. It's up to the controller to supply the necessary
76 // info by calling GuiDialog::updateView().
81 void GuiDialog::checkStatus()
83 // buffer independant dialogs are always active.
84 // This check allows us leave canApply unimplemented for some dialogs.
85 if (!isBufferDependent())
88 // deactivate the dialog if we have no buffer
89 if (!isBufferAvailable()) {
90 bc().setReadOnly(true);
94 // check whether this dialog may be active
96 bool const readonly = isBufferReadonly();
97 bc().setReadOnly(readonly);
98 // refreshReadOnly() is too generous in _enabling_ widgets
99 // update dialog to disable disabled widgets again
101 if (!readonly || canApplyToReadOnly())
105 bc().setReadOnly(true);
110 bool GuiDialog::isVisibleView() const
112 return QDialog::isVisible();
116 void GuiDialog::showView()
118 QSize const hint = sizeHint();
119 if (hint.height() >= 0 && hint.width() >= 0)
120 setMinimumSize(hint);
122 updateView(); // make sure its up-to-date
126 if (QWidget::isVisible()) {
136 void GuiDialog::hideView()
142 void GuiDialog::changed()
146 bc().setValid(isValid());
150 void GuiDialog::updateView()
152 setUpdatesEnabled(false);
154 // protect the BC from unwarranted state transitions
159 setUpdatesEnabled(true);
164 void GuiDialog::showData(string const & data)
166 if (isBufferDependent() && !isBufferAvailable())
169 if (!initialiseParams(data)) {
170 lyxerr << "Dialog \"" << name_
171 << "\" failed to translate the data "
172 "string passed to show()" << std::endl;
176 bc().setReadOnly(isBufferReadonly());
178 // The widgets may not be valid, so refresh the button controller
183 void GuiDialog::updateData(string const & data)
185 if (isBufferDependent() && !isBufferAvailable())
188 if (!initialiseParams(data)) {
189 lyxerr << "Dialog \"" << name_
190 << "\" could not be initialized" << std::endl;
194 bc().setReadOnly(isBufferReadonly());
196 // The widgets may not be valid, so refresh the button controller
201 void GuiDialog::hide()
203 if (!isVisibleView())
208 Dialog::disconnect(name_);
212 void GuiDialog::apply()
214 if (isBufferDependent()) {
215 if (!isBufferAvailable() ||
216 (isBufferReadonly() && !canApplyToReadOnly()))
223 if (disconnectOnApply() && !is_closing_) {
224 Dialog::disconnect(name_);
225 initialiseParams(string());
231 void GuiDialog::showEvent(QShowEvent * e)
234 string key = name_ + "/geometry";
235 restoreGeometry(settings.value(key.c_str()).toByteArray());
236 QDialog::showEvent(e);
240 void GuiDialog::closeEvent(QCloseEvent * e)
243 string key = name_ + "/geometry";
244 settings.setValue(key.c_str(), saveGeometry());
245 QDialog::closeEvent(e);
248 } // namespace frontend
252 /////////////////////////////////////////////////////////////////////
254 // Command based dialogs
256 /////////////////////////////////////////////////////////////////////
258 #include "FuncRequest.h"
259 #include "insets/InsetCommand.h"
267 GuiCommand::GuiCommand(GuiView & lv, string const & name)
268 : GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
273 bool GuiCommand::initialiseParams(string const & data)
275 // The name passed with LFUN_INSET_APPLY is also the name
276 // used to identify the mailer.
277 InsetCommandMailer::string2params(lfun_name_, data, params_);
282 void GuiCommand::dispatchParams()
284 if (lfun_name_.empty())
288 InsetCommandMailer::params2string(lfun_name_, params_);
289 dispatch(FuncRequest(getLfun(), lfun));
292 } // namespace frontend
295 #include "GuiDialog_moc.cpp"