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"
23 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
24 : is_closing_(false), name_(name), controller_(0)
30 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().
77 controller().updateDialog(name_);
81 void GuiDialog::checkStatus()
83 // buffer independant dialogs are always active.
84 // This check allows us leave canApply unimplemented for some dialogs.
85 if (!controller().isBufferDependent())
88 // deactivate the dialog if we have no buffer
89 if (!controller().isBufferAvailable()) {
90 bc().setReadOnly(true);
94 // check whether this dialog may be active
95 if (controller().canApply()) {
96 bool const readonly = controller().isBufferReadonly();
97 bc().setReadOnly(readonly);
98 // refreshReadOnly() is too generous in _enabling_ widgets
99 // update dialog to disable disabled widgets again
102 if (!readonly || controller().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
124 if (controller().exitEarly())
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 (controller().isBufferDependent() && !controller().isBufferAvailable())
170 if (!controller().initialiseParams(data)) {
171 lyxerr << "Dialog \"" << name_
172 << "\" failed to translate the data "
173 "string passed to show()" << std::endl;
177 bc().setReadOnly(controller().isBufferReadonly());
179 // The widgets may not be valid, so refresh the button controller
184 void GuiDialog::updateData(string const & data)
186 if (controller().isBufferDependent() && !controller().isBufferAvailable())
189 if (!controller().initialiseParams(data)) {
190 lyxerr << "Dialog \"" << name_
191 << "\" could not be initialized" << std::endl;
195 bc().setReadOnly(controller().isBufferReadonly());
197 // The widgets may not be valid, so refresh the button controller
202 void GuiDialog::hide()
204 if (!isVisibleView())
207 controller().clearParams();
209 controller().disconnect(name_);
213 void GuiDialog::apply()
215 if (controller().isBufferDependent()) {
216 if (!controller().isBufferAvailable() ||
217 (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
222 controller().dispatchParams();
224 if (controller().disconnectOnApply() && !is_closing_) {
225 controller().disconnect(name_);
226 controller().initialiseParams(string());
232 void GuiDialog::setController(Controller * controller)
234 BOOST_ASSERT(controller);
235 BOOST_ASSERT(!controller_);
236 controller_ = controller;
237 controller_->setLyXView(*lyxview_);
241 } // namespace frontend
244 #include "GuiDialog_moc.cpp"