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 "support/debug.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 LYXERR0("Dialog \"" << name()
173 << "\" failed to translate the data string passed to show()");
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 LYXERR0("Dialog \"" << name()
191 << "\" could not be initialized");
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();
213 void GuiDialog::apply()
215 if (isBufferDependent()) {
216 if (!isBufferAvailable() ||
217 (isBufferReadonly() && !canApplyToReadOnly()))
224 if (disconnectOnApply() && !is_closing_) {
225 Dialog::disconnect();
226 initialiseParams(string());
232 void GuiDialog::showEvent(QShowEvent * e)
235 string key = name() + "/geometry";
236 restoreGeometry(settings.value(key.c_str()).toByteArray());
237 QDialog::showEvent(e);
241 void GuiDialog::closeEvent(QCloseEvent * e)
244 string key = name() + "/geometry";
245 settings.setValue(key.c_str(), saveGeometry());
246 QDialog::closeEvent(e);
249 } // namespace frontend
253 /////////////////////////////////////////////////////////////////////
255 // Command based dialogs
257 /////////////////////////////////////////////////////////////////////
259 #include "FuncRequest.h"
260 #include "insets/InsetCommand.h"
268 GuiCommand::GuiCommand(GuiView & lv, string const & name)
269 : GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
274 bool GuiCommand::initialiseParams(string const & data)
276 // The name passed with LFUN_INSET_APPLY is also the name
277 // used to identify the mailer.
278 InsetCommandMailer::string2params(lfun_name_, data, params_);
283 void GuiCommand::dispatchParams()
285 if (lfun_name_.empty())
289 InsetCommandMailer::params2string(lfun_name_, params_);
290 dispatch(FuncRequest(getLfun(), lfun));
293 } // namespace frontend
296 #include "GuiDialog_moc.cpp"