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"
18 #include <QCloseEvent>
27 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
28 : is_closing_(false), name_(name), controller_(0)
34 GuiDialog::~GuiDialog()
40 void GuiDialog::setViewTitle(docstring const & title)
42 setWindowTitle("LyX: " + toqstr(title));
46 void GuiDialog::setButtonsValid(bool valid)
52 void GuiDialog::slotApply()
59 void GuiDialog::slotOK()
69 void GuiDialog::slotClose()
76 void GuiDialog::slotRestore()
78 // Tell the controller that a request to refresh the dialog's contents
79 // has been received. It's up to the controller to supply the necessary
80 // info by calling GuiDialog::updateView().
81 controller().updateDialog(name_);
85 void GuiDialog::checkStatus()
87 // buffer independant dialogs are always active.
88 // This check allows us leave canApply unimplemented for some dialogs.
89 if (!controller().isBufferDependent())
92 // deactivate the dialog if we have no buffer
93 if (!controller().isBufferAvailable()) {
94 bc().setReadOnly(true);
98 // check whether this dialog may be active
99 if (controller().canApply()) {
100 bool const readonly = controller().isBufferReadonly();
101 bc().setReadOnly(readonly);
102 // refreshReadOnly() is too generous in _enabling_ widgets
103 // update dialog to disable disabled widgets again
105 if (!readonly || controller().canApplyToReadOnly())
109 bc().setReadOnly(true);
114 bool GuiDialog::isVisibleView() const
116 return QDialog::isVisible();
120 void GuiDialog::showView()
122 QSize const hint = sizeHint();
123 if (hint.height() >= 0 && hint.width() >= 0)
124 setMinimumSize(hint);
126 updateView(); // make sure its up-to-date
127 if (controller().exitEarly())
130 if (QWidget::isVisible()) {
140 void GuiDialog::hideView()
146 void GuiDialog::changed()
150 bc().setValid(isValid());
154 void GuiDialog::updateView()
156 setUpdatesEnabled(false);
158 // protect the BC from unwarranted state transitions
163 setUpdatesEnabled(true);
168 void GuiDialog::showData(string const & data)
170 if (controller().isBufferDependent() && !controller().isBufferAvailable())
173 if (!controller().initialiseParams(data)) {
174 lyxerr << "Dialog \"" << name_
175 << "\" failed to translate the data "
176 "string passed to show()" << std::endl;
180 bc().setReadOnly(controller().isBufferReadonly());
182 // The widgets may not be valid, so refresh the button controller
187 void GuiDialog::updateData(string const & data)
189 if (controller().isBufferDependent() && !controller().isBufferAvailable())
192 if (!controller().initialiseParams(data)) {
193 lyxerr << "Dialog \"" << name_
194 << "\" could not be initialized" << std::endl;
198 bc().setReadOnly(controller().isBufferReadonly());
200 // The widgets may not be valid, so refresh the button controller
205 void GuiDialog::hide()
207 if (!isVisibleView())
210 controller().clearParams();
212 controller().disconnect(name_);
216 void GuiDialog::apply()
218 if (controller().isBufferDependent()) {
219 if (!controller().isBufferAvailable() ||
220 (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
225 controller().dispatchParams();
227 if (controller().disconnectOnApply() && !is_closing_) {
228 controller().disconnect(name_);
229 controller().initialiseParams(string());
235 void GuiDialog::setController(Controller * controller)
237 BOOST_ASSERT(controller);
238 BOOST_ASSERT(!controller_);
239 controller_ = controller;
240 controller_->setLyXView(*lyxview_);
244 void GuiDialog::showEvent(QShowEvent * e)
246 #if (QT_VERSION >= 0x040200)
248 string key = name_ + "/geometry";
249 restoreGeometry(settings.value(key.c_str()).toByteArray());
251 QDialog::showEvent(e);
255 void GuiDialog::closeEvent(QCloseEvent * e)
257 #if (QT_VERSION >= 0x040200)
259 string key = name_ + "/geometry";
260 settings.setValue(key.c_str(), saveGeometry());
262 QDialog::closeEvent(e);
265 } // namespace frontend
268 #include "GuiDialog_moc.cpp"