X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiDialog.cpp;h=7d4bf582116f11ddffcabfd8692db2870270ee27;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=ec4bd1188d7df645b67682ac1a43b445ae26a3b3;hpb=1f4e5c926abdc1e268fd902cfb1efcb2b9a0770a;p=lyx.git diff --git a/src/frontends/qt4/GuiDialog.cpp b/src/frontends/qt4/GuiDialog.cpp index ec4bd1188d..7d4bf58211 100644 --- a/src/frontends/qt4/GuiDialog.cpp +++ b/src/frontends/qt4/GuiDialog.cpp @@ -11,32 +11,30 @@ #include #include "GuiDialog.h" -#include "debug.h" + +#include "GuiView.h" #include "qt_helpers.h" -#include "frontends/LyXView.h" +#include "FuncRequest.h" + +#include "support/debug.h" #include -#include -#include -using std::string; +using namespace std; namespace lyx { namespace frontend { -GuiDialog::GuiDialog(LyXView & lv, std::string const & name) - : Dialog(lv), is_closing_(false), name_(name) +GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title) + : QDialog(&lv), Dialog(lv, name, "LyX: " + title), updating_(false), + is_closing_(false) {} -GuiDialog::~GuiDialog() -{ -} - - -void GuiDialog::setViewTitle(docstring const & title) +void GuiDialog::closeEvent(QCloseEvent * ev) { - setWindowTitle("LyX: " + toqstr(title)); + slotClose(); + ev->accept(); } @@ -53,19 +51,26 @@ void GuiDialog::slotApply() } +void GuiDialog::slotAutoApply() +{ + apply(); + bc().autoApply(); +} + + void GuiDialog::slotOK() { is_closing_ = true; apply(); is_closing_ = false; - QDialog::hide(); + hideView(); bc().ok(); } void GuiDialog::slotClose() { - QDialog::hide(); + hideView(); bc().cancel(); } @@ -75,76 +80,26 @@ void GuiDialog::slotRestore() // Tell the controller that a request to refresh the dialog's contents // has been received. It's up to the controller to supply the necessary // info by calling GuiDialog::updateView(). - updateDialog(name_); + updateDialog(); bc().restore(); } -void GuiDialog::checkStatus() -{ - // buffer independant dialogs are always active. - // This check allows us leave canApply unimplemented for some dialogs. - if (!isBufferDependent()) - return; - - // deactivate the dialog if we have no buffer - if (!isBufferAvailable()) { - bc().setReadOnly(true); - return; - } - - // check whether this dialog may be active - if (canApply()) { - bool const readonly = isBufferReadonly(); - bc().setReadOnly(readonly); - // refreshReadOnly() is too generous in _enabling_ widgets - // update dialog to disable disabled widgets again - - if (!readonly || canApplyToReadOnly()) - updateView(); - - } else { - bc().setReadOnly(true); - } -} - - -bool GuiDialog::isVisibleView() const -{ - return QDialog::isVisible(); -} - -void GuiDialog::showView() +void GuiDialog::changed() { - QSize const hint = sizeHint(); - if (hint.height() >= 0 && hint.width() >= 0) - setMinimumSize(hint); - - updateView(); // make sure its up-to-date - if (exitEarly()) + if (updating_) return; - - if (QWidget::isVisible()) { - raise(); - activateWindow(); - } else { - QWidget::show(); - } - setFocus(); -} - - -void GuiDialog::hideView() -{ - QDialog::hide(); + bc().setValid(isValid()); } -void GuiDialog::changed() +void GuiDialog::enableView(bool enable) { - if (updating_) - return; - bc().setValid(isValid()); + if (!enable) { + bc().setReadOnly(true); + bc().setValid(false); + } + Dialog::enableView(enable); } @@ -152,145 +107,18 @@ void GuiDialog::updateView() { setUpdatesEnabled(false); + bc().setReadOnly(isBufferReadonly()); // protect the BC from unwarranted state transitions updating_ = true; updateContents(); updating_ = false; - - setUpdatesEnabled(true); - QDialog::update(); -} - - -void GuiDialog::showData(string const & data) -{ - if (isBufferDependent() && !isBufferAvailable()) - return; - - if (!initialiseParams(data)) { - lyxerr << "Dialog \"" << name_ - << "\" failed to translate the data " - "string passed to show()" << std::endl; - return; - } - - bc().setReadOnly(isBufferReadonly()); - showView(); // The widgets may not be valid, so refresh the button controller bc().refresh(); -} - -void GuiDialog::updateData(string const & data) -{ - if (isBufferDependent() && !isBufferAvailable()) - return; - - if (!initialiseParams(data)) { - lyxerr << "Dialog \"" << name_ - << "\" could not be initialized" << std::endl; - return; - } - - bc().setReadOnly(isBufferReadonly()); - updateView(); - // The widgets may not be valid, so refresh the button controller - bc().refresh(); -} - - -void GuiDialog::hide() -{ - if (!isVisibleView()) - return; - - clearParams(); - hideView(); - Dialog::disconnect(name_); -} - - -void GuiDialog::apply() -{ - if (isBufferDependent()) { - if (!isBufferAvailable() || - (isBufferReadonly() && !canApplyToReadOnly())) - return; - } - - applyView(); - dispatchParams(); - - if (disconnectOnApply() && !is_closing_) { - Dialog::disconnect(name_); - initialiseParams(string()); - updateView(); - } -} - - -void GuiDialog::showEvent(QShowEvent * e) -{ - QSettings settings; - string key = name_ + "/geometry"; - restoreGeometry(settings.value(key.c_str()).toByteArray()); - QDialog::showEvent(e); -} - - -void GuiDialog::closeEvent(QCloseEvent * e) -{ - QSettings settings; - string key = name_ + "/geometry"; - settings.setValue(key.c_str(), saveGeometry()); - QDialog::closeEvent(e); -} - -} // namespace frontend -} // namespace lyx - - -///////////////////////////////////////////////////////////////////// -// -// Command based dialogs -// -///////////////////////////////////////////////////////////////////// - -#include "FuncRequest.h" -#include "insets/InsetCommand.h" - - -using std::string; - -namespace lyx { -namespace frontend { - -GuiCommand::GuiCommand(LyXView & lv, string const & name) - : GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name) -{ -} - - -bool GuiCommand::initialiseParams(string const & data) -{ - // The name passed with LFUN_INSET_APPLY is also the name - // used to identify the mailer. - InsetCommandMailer::string2params(lfun_name_, data, params_); - return true; -} - - -void GuiCommand::dispatchParams() -{ - if (lfun_name_.empty()) - return; - - string const lfun = - InsetCommandMailer::params2string(lfun_name_, params_); - dispatch(FuncRequest(getLfun(), lfun)); + setUpdatesEnabled(true); } } // namespace frontend } // namespace lyx -#include "GuiDialog_moc.cpp" +#include "moc_GuiDialog.cpp"