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"
16 #include "qt_helpers.h"
18 #include <QCloseEvent>
19 #include <QMainWindow>
28 GuiDialog::GuiDialog(GuiView & lv, std::string const & name)
29 : QDialog(&lv), Dialog(lv, name), is_closing_(false)
33 GuiDialog::~GuiDialog()
38 void GuiDialog::setViewTitle(docstring const & title)
40 setWindowTitle("LyX: " + toqstr(title));
44 void GuiDialog::setButtonsValid(bool valid)
50 void GuiDialog::slotApply()
57 void GuiDialog::slotOK()
67 void GuiDialog::slotClose()
74 void GuiDialog::slotRestore()
76 // Tell the controller that a request to refresh the dialog's contents
77 // has been received. It's up to the controller to supply the necessary
78 // info by calling GuiDialog::updateView().
83 void GuiDialog::checkStatus()
85 // buffer independant dialogs are always active.
86 // This check allows us leave canApply unimplemented for some dialogs.
87 if (!isBufferDependent())
90 // deactivate the dialog if we have no buffer
91 if (!isBufferAvailable()) {
92 bc().setReadOnly(true);
96 // check whether this dialog may be active
98 bool const readonly = isBufferReadonly();
99 bc().setReadOnly(readonly);
100 // refreshReadOnly() is too generous in _enabling_ widgets
101 // update dialog to disable disabled widgets again
103 if (!readonly || canApplyToReadOnly())
107 bc().setReadOnly(true);
112 bool GuiDialog::isVisibleView() const
114 return QDialog::isVisible();
118 void GuiDialog::showView()
120 QSize const hint = sizeHint();
121 if (hint.height() >= 0 && hint.width() >= 0)
122 setMinimumSize(hint);
124 updateView(); // make sure its up-to-date
128 if (QWidget::isVisible()) {
138 void GuiDialog::hideView()
144 void GuiDialog::changed()
148 bc().setValid(isValid());
152 void GuiDialog::updateView()
154 setUpdatesEnabled(false);
156 // protect the BC from unwarranted state transitions
161 setUpdatesEnabled(true);
166 void GuiDialog::showData(string const & data)
168 if (isBufferDependent() && !isBufferAvailable())
171 if (!initialiseParams(data)) {
172 lyxerr << "Dialog \"" << name()
173 << "\" failed to translate the data "
174 "string passed to show()" << std::endl;
178 bc().setReadOnly(isBufferReadonly());
180 // The widgets may not be valid, so refresh the button controller
185 void GuiDialog::updateData(string const & data)
187 if (isBufferDependent() && !isBufferAvailable())
190 if (!initialiseParams(data)) {
191 lyxerr << "Dialog \"" << name()
192 << "\" could not be initialized" << std::endl;
196 bc().setReadOnly(isBufferReadonly());
198 // The widgets may not be valid, so refresh the button controller
203 void GuiDialog::hide()
205 if (!isVisibleView())
210 Dialog::disconnect();
214 void GuiDialog::apply()
216 if (isBufferDependent()) {
217 if (!isBufferAvailable() ||
218 (isBufferReadonly() && !canApplyToReadOnly()))
225 if (disconnectOnApply() && !is_closing_) {
226 Dialog::disconnect();
227 initialiseParams(string());
233 void GuiDialog::showEvent(QShowEvent * e)
236 string key = name() + "/geometry";
237 restoreGeometry(settings.value(key.c_str()).toByteArray());
238 QDialog::showEvent(e);
242 void GuiDialog::closeEvent(QCloseEvent * e)
245 string key = name() + "/geometry";
246 settings.setValue(key.c_str(), saveGeometry());
247 QDialog::closeEvent(e);
250 } // namespace frontend
254 /////////////////////////////////////////////////////////////////////
256 // Command based dialogs
258 /////////////////////////////////////////////////////////////////////
260 #include "FuncRequest.h"
261 #include "insets/InsetCommand.h"
269 GuiCommand::GuiCommand(GuiView & lv, string const & name)
270 : GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
275 bool GuiCommand::initialiseParams(string const & data)
277 // The name passed with LFUN_INSET_APPLY is also the name
278 // used to identify the mailer.
279 InsetCommandMailer::string2params(lfun_name_, data, params_);
284 void GuiCommand::dispatchParams()
286 if (lfun_name_.empty())
290 InsetCommandMailer::params2string(lfun_name_, params_);
291 dispatch(FuncRequest(getLfun(), lfun));
294 } // namespace frontend
297 #include "GuiDialog_moc.cpp"