]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDialog.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiDialog.cpp
index a46c9ce1eaded75f3b491b79fea5914093a39429..4fcff16a2379f3689b3a61d539375e1f667f7bb8 100644 (file)
 #include <config.h>
 
 #include "GuiDialog.h"
-#include "debug.h"
 
+#include "GuiView.h"
+#include "qt_helpers.h"
+
+#include "support/debug.h"
+
+#include <QCloseEvent>
+#include <QDialogButtonBox>
+
+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)
+{
+       connect(&lv, SIGNAL(bufferViewChanged()),
+               this, SLOT(onBufferViewChanged()));
+
+       // remove question marks from Windows dialogs
+       setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+}
+
+
+void GuiDialog::closeEvent(QCloseEvent * ev)
+{
+       slotClose();
+       ev->accept();
+}
 
 
 void GuiDialog::setButtonsValid(bool valid)
@@ -28,94 +50,105 @@ void GuiDialog::setButtonsValid(bool 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;
-       hide();
+       hideView();
        bc().ok();
 }
 
 
-void GuiDialog::CancelButton()
+void GuiDialog::slotClose()
 {
-       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()
+void GuiDialog::slotButtonBox(QAbstractButton * button)
 {
-       bc().setReadOnly(kernel().isBufferReadonly());
+       QDialogButtonBox * bbox = qobject_cast<QDialogButtonBox*>(sender());
+       switch (bbox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Apply:
+               slotApply();
+               break;
+       case QDialogButtonBox::Cancel:
+       case QDialogButtonBox::Close:
+               slotClose();
+               break;
+       case QDialogButtonBox::Reset:
+       case QDialogButtonBox::RestoreDefaults:
+               slotRestore();
+               break;
+       default:
+               break;
+       }
 }
 
 
-void GuiDialog::postShow()
+void GuiDialog::changed()
 {
-       // The widgets may not be valid, so refresh the button controller
-       bc().refresh();
+       if (updating_)
+               return;
+       bc().setValid(isValid());
 }
 
 
-void GuiDialog::preUpdate()
+void GuiDialog::enableView(bool enable)
 {
-       bc().setReadOnly(kernel().isBufferReadonly());
+       if (!enable) {
+               bc().setReadOnly(true);
+               bc().setValid(false);
+       }
+       Dialog::enableView(enable);
 }
 
 
-void GuiDialog::postUpdate()
+void GuiDialog::updateView()
 {
+       setUpdatesEnabled(false);
+
+       bc().setReadOnly(isBufferReadonly());
+       // protect the BC from unwarranted state transitions
+       updating_ = true;
+       updateContents();
+       updating_ = false;
        // 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);
-       }       
+       setUpdatesEnabled(true);
 }
 
 } // namespace frontend
 } // namespace lyx
+
+#include "moc_GuiDialog.cpp"