X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiDialog.cpp;h=7d4bf582116f11ddffcabfd8692db2870270ee27;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=dad989fcae22a044c5723f228b745fd29b944090;hpb=c9ea6e6eef090b863fb54445010f24443b15eb23;p=lyx.git diff --git a/src/frontends/qt4/GuiDialog.cpp b/src/frontends/qt4/GuiDialog.cpp index dad989fcae..7d4bf58211 100644 --- a/src/frontends/qt4/GuiDialog.cpp +++ b/src/frontends/qt4/GuiDialog.cpp @@ -11,159 +11,80 @@ #include #include "GuiDialog.h" -#include "debug.h" + +#include "GuiView.h" #include "qt_helpers.h" +#include "FuncRequest.h" + +#include "support/debug.h" + +#include + +using namespace std; namespace lyx { namespace frontend { -GuiDialog::GuiDialog(LyXView & lv, std::string const & name) - : Dialog(lv, name) +GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title) + : QDialog(&lv), Dialog(lv, name, "LyX: " + title), updating_(false), + is_closing_(false) {} +void GuiDialog::closeEvent(QCloseEvent * ev) +{ + slotClose(); + ev->accept(); +} + + void GuiDialog::setButtonsValid(bool valid) { bc().setValid(valid); } -void GuiDialog::ApplyButton() +void GuiDialog::slotApply() { apply(); bc().apply(); } -void GuiDialog::OKButton() +void GuiDialog::slotAutoApply() +{ + apply(); + bc().autoApply(); +} + + +void GuiDialog::slotOK() { is_closing_ = true; apply(); is_closing_ = false; - QDialog::hide(); + hideView(); bc().ok(); } -void GuiDialog::CancelButton() +void GuiDialog::slotClose() { - QDialog::hide(); + hideView(); bc().cancel(); } -void GuiDialog::RestoreButton() +void GuiDialog::slotRestore() { - // Tell the kernel that a request to refresh the dialog's contents - // has been received. It's up to the kernel to supply the necessary + // 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(). - kernel().updateDialog(name_); + updateDialog(); bc().restore(); } -void GuiDialog::preShow() -{ - bc().setReadOnly(kernel().isBufferReadonly()); -} - - -void GuiDialog::postShow() -{ - // The widgets may not be valid, so refresh the button controller - bc().refresh(); -} - - -void GuiDialog::preUpdate() -{ - bc().setReadOnly(kernel().isBufferReadonly()); -} - - -void GuiDialog::postUpdate() -{ - // The widgets may not be valid, so refresh the button controller - bc().refresh(); -} - - -void GuiDialog::checkStatus() -{ - // buffer independant dialogs are always active. - // This check allows us leave canApply unimplemented for some dialogs. - if (!controller().isBufferDependent()) - return; - - // deactivate the dialog if we have no buffer - if (!kernel().isBufferAvailable()) { - bc().setReadOnly(true); - return; - } - - // check whether this dialog may be active - if (controller().canApply()) { - bool const readonly = kernel().isBufferReadonly(); - bc().setReadOnly(readonly); - // refreshReadOnly() is too generous in _enabling_ widgets - // update dialog to disable disabled widgets again -/* - * FIXME: - if (!readonly || controller().canApplyToReadOnly()) - update(); -*/ - } else { - bc().setReadOnly(true); - } -} - - -bool GuiDialog::isVisibleView() const -{ - return QDialog::isVisible(); -} - - -bool GuiDialog::readOnly() const -{ - return kernel().isBufferReadonly(); -} - - -void GuiDialog::showView() -{ - QSize const hint = sizeHint(); - if (hint.height() >= 0 && hint.width() >= 0) - setMinimumSize(hint); - - updateView(); // make sure its up-to-date - if (controller().exitEarly()) - return; - - setWindowTitle(toqstr("LyX: " + getViewTitle())); - - if (QWidget::isVisible()) { - raise(); - activateWindow(); - } else { - QWidget::show(); - } - setFocus(); -} - - -void GuiDialog::hideView() -{ - QDialog::hide(); -} - - -bool GuiDialog::isValid() -{ - return true; -} - - void GuiDialog::changed() { if (updating_) @@ -172,49 +93,32 @@ void GuiDialog::changed() } -void GuiDialog::slotWMHide() -{ - CancelButton(); -} - - -void GuiDialog::slotApply() -{ - ApplyButton(); -} - - -void GuiDialog::slotOK() -{ - OKButton(); -} - - -void GuiDialog::slotClose() +void GuiDialog::enableView(bool enable) { - CancelButton(); + if (!enable) { + bc().setReadOnly(true); + bc().setValid(false); + } + Dialog::enableView(enable); } -void GuiDialog::slotRestore() -{ - RestoreButton(); -} - void GuiDialog::updateView() { setUpdatesEnabled(false); + bc().setReadOnly(isBufferReadonly()); // protect the BC from unwarranted state transitions updating_ = true; - update_contents(); + updateContents(); updating_ = false; + // The widgets may not be valid, so refresh the button controller + bc().refresh(); setUpdatesEnabled(true); - QDialog::update(); } } // namespace frontend } // namespace lyx -#include "GuiDialog_moc.cpp" +#include "moc_GuiDialog.cpp"