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
101 if (!readonly || controller().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
123 if (controller().exitEarly())
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 (controller().isBufferDependent() && !controller().isBufferAvailable())
169 if (!controller().initialiseParams(data)) {
170 lyxerr << "Dialog \"" << name_
171 << "\" failed to translate the data "
172 "string passed to show()" << std::endl;
176 bc().setReadOnly(controller().isBufferReadonly());
178 // The widgets may not be valid, so refresh the button controller
183 void GuiDialog::updateData(string const & data)
185 if (controller().isBufferDependent() && !controller().isBufferAvailable())
188 if (!controller().initialiseParams(data)) {
189 lyxerr << "Dialog \"" << name_
190 << "\" could not be initialized" << std::endl;
194 bc().setReadOnly(controller().isBufferReadonly());
196 // The widgets may not be valid, so refresh the button controller
201 void GuiDialog::hide()
203 if (!isVisibleView())
206 controller().clearParams();
208 controller().disconnect(name_);
212 void GuiDialog::apply()
214 if (controller().isBufferDependent()) {
215 if (!controller().isBufferAvailable() ||
216 (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
221 controller().dispatchParams();
223 if (controller().disconnectOnApply() && !is_closing_) {
224 controller().disconnect(name_);
225 controller().initialiseParams(string());
231 void GuiDialog::setController(Controller * controller)
233 BOOST_ASSERT(controller);
234 BOOST_ASSERT(!controller_);
235 controller_ = controller;
236 controller_->setLyXView(*lyxview_);
240 } // namespace frontend
243 #include "GuiDialog_moc.cpp"