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), destroy_controller_(false)
34 GuiDialog::~GuiDialog()
36 if (destroy_controller_)
41 void GuiDialog::setViewTitle(docstring const & title)
43 setWindowTitle("LyX: " + toqstr(title));
47 void GuiDialog::setButtonsValid(bool valid)
53 void GuiDialog::slotApply()
60 void GuiDialog::slotOK()
70 void GuiDialog::slotClose()
77 void GuiDialog::slotRestore()
79 // Tell the controller that a request to refresh the dialog's contents
80 // has been received. It's up to the controller to supply the necessary
81 // info by calling GuiDialog::updateView().
82 controller().updateDialog(name_);
86 void GuiDialog::checkStatus()
88 // buffer independant dialogs are always active.
89 // This check allows us leave canApply unimplemented for some dialogs.
90 if (!controller().isBufferDependent())
93 // deactivate the dialog if we have no buffer
94 if (!controller().isBufferAvailable()) {
95 bc().setReadOnly(true);
99 // check whether this dialog may be active
100 if (controller().canApply()) {
101 bool const readonly = controller().isBufferReadonly();
102 bc().setReadOnly(readonly);
103 // refreshReadOnly() is too generous in _enabling_ widgets
104 // update dialog to disable disabled widgets again
106 if (!readonly || controller().canApplyToReadOnly())
110 bc().setReadOnly(true);
115 bool GuiDialog::isVisibleView() const
117 return QDialog::isVisible();
121 void GuiDialog::showView()
123 QSize const hint = sizeHint();
124 if (hint.height() >= 0 && hint.width() >= 0)
125 setMinimumSize(hint);
127 updateView(); // make sure its up-to-date
128 if (controller().exitEarly())
131 if (QWidget::isVisible()) {
141 void GuiDialog::hideView()
147 void GuiDialog::changed()
151 bc().setValid(isValid());
155 void GuiDialog::updateView()
157 setUpdatesEnabled(false);
159 // protect the BC from unwarranted state transitions
164 setUpdatesEnabled(true);
169 void GuiDialog::showData(string const & data)
171 if (controller().isBufferDependent() && !controller().isBufferAvailable())
174 if (!controller().initialiseParams(data)) {
175 lyxerr << "Dialog \"" << name_
176 << "\" failed to translate the data "
177 "string passed to show()" << std::endl;
181 bc().setReadOnly(controller().isBufferReadonly());
183 // The widgets may not be valid, so refresh the button controller
188 void GuiDialog::updateData(string const & data)
190 if (controller().isBufferDependent() && !controller().isBufferAvailable())
193 if (!controller().initialiseParams(data)) {
194 lyxerr << "Dialog \"" << name_
195 << "\" could not be initialized" << std::endl;
199 bc().setReadOnly(controller().isBufferReadonly());
201 // The widgets may not be valid, so refresh the button controller
206 void GuiDialog::hide()
208 if (!isVisibleView())
211 controller().clearParams();
213 controller().disconnect(name_);
217 void GuiDialog::apply()
219 if (controller().isBufferDependent()) {
220 if (!controller().isBufferAvailable() ||
221 (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
226 controller().dispatchParams();
228 if (controller().disconnectOnApply() && !is_closing_) {
229 controller().disconnect(name_);
230 controller().initialiseParams(string());
236 void GuiDialog::setController(Controller * controller, bool destroy)
238 BOOST_ASSERT(controller);
239 BOOST_ASSERT(!controller_);
240 destroy_controller_ = destroy;
241 controller_ = controller;
242 controller_->setLyXView(*lyxview_);
246 void GuiDialog::showEvent(QShowEvent * e)
248 #if (QT_VERSION >= 0x040200)
250 string key = name_ + "/geometry";
251 restoreGeometry(settings.value(key.c_str()).toByteArray());
253 QDialog::showEvent(e);
257 void GuiDialog::closeEvent(QCloseEvent * e)
259 #if (QT_VERSION >= 0x040200)
261 string key = name_ + "/geometry";
262 settings.setValue(key.c_str(), saveGeometry());
264 QDialog::closeEvent(e);
267 } // namespace frontend
270 #include "GuiDialog_moc.cpp"