]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDialog.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiDialog.cpp
index dad989fcae22a044c5723f228b745fd29b944090..8778886e34138ebc75550e3f3e8f845ab69048af 100644 (file)
 #include <config.h>
 
 #include "GuiDialog.h"
-#include "debug.h"
-#include "qt_helpers.h"
 
-namespace lyx {
-namespace frontend {
+#include "GuiView.h"
+#include "qt_helpers.h"
 
-GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
-       : Dialog(lv, name)
-{}
+#include "support/debug.h"
 
+#include <QCloseEvent>
+#include <QDialogButtonBox>
 
-void GuiDialog::setButtonsValid(bool valid)
-{
-       bc().setValid(valid);
-}
+using namespace std;
 
+namespace lyx {
+namespace frontend {
 
-void GuiDialog::ApplyButton()
+GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
+       : QDialog(&lv), Dialog(lv, name, "LyX: " + title), updating_(false),
+         is_closing_(false)
 {
-       apply();
-       bc().apply();
-}
-
+       connect(&lv, SIGNAL(bufferViewChanged()),
+               this, SLOT(onBufferViewChanged()));
 
-void GuiDialog::OKButton()
-{
-       is_closing_ = true;
-       apply();
-       is_closing_ = false;
-       QDialog::hide();
-       bc().ok();
+       // remove question marks from Windows dialogs
+       setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
 }
 
 
-void GuiDialog::CancelButton()
+void GuiDialog::closeEvent(QCloseEvent * ev)
 {
-       QDialog::hide();
-       bc().cancel();
+       slotClose();
+       ev->accept();
 }
 
 
-void GuiDialog::RestoreButton()
-{
-       // 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
-       // info by calling GuiDialog::updateView().
-       kernel().updateDialog(name_);
-       bc().restore();
-}
-
-
-void GuiDialog::preShow()
-{
-       bc().setReadOnly(kernel().isBufferReadonly());
-}
-
-
-void GuiDialog::postShow()
+void GuiDialog::setButtonsValid(bool valid)
 {
-       // The widgets may not be valid, so refresh the button controller
-       bc().refresh();
+       bc().setValid(valid);
 }
 
 
-void GuiDialog::preUpdate()
+void GuiDialog::slotApply()
 {
-       bc().setReadOnly(kernel().isBufferReadonly());
+       apply();
+       bc().apply();
 }
 
 
-void GuiDialog::postUpdate()
+void GuiDialog::slotAutoApply()
 {
-       // The widgets may not be valid, so refresh the button controller
-       bc().refresh();
+       apply();
+       bc().autoApply();
 }
 
 
-void GuiDialog::checkStatus()
+void GuiDialog::slotOK()
 {
-       // 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);
-       }       
+       is_closing_ = true;
+       apply();
+       is_closing_ = false;
+       hideView();
+       bc().ok();
 }
 
 
-bool GuiDialog::isVisibleView() const
+void GuiDialog::slotClose()
 {
-       return QDialog::isVisible();
+       hideView();
+       bc().cancel();
 }
 
 
-bool GuiDialog::readOnly() const
+void GuiDialog::slotRestore()
 {
-       return kernel().isBufferReadonly();
+       // 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();
+       bc().restore();
 }
 
 
-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();
+void GuiDialog::slotButtonBox(QAbstractButton * button)
+{
+       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:
+               slotRestore();
+               break;
+       case QDialogButtonBox::RestoreDefaults:
+               slotRestoreDefaults();
+               break;
+       default:
+               break;
        }
-       setFocus();
-}
-
-
-void GuiDialog::hideView()
-{
-       QDialog::hide();
-}
-
-
-bool GuiDialog::isValid()
-{
-       return true;
 }
 
 
@@ -172,49 +125,32 @@ void GuiDialog::changed()
 }
 
 
-void GuiDialog::slotWMHide()
+void GuiDialog::enableView(bool enable)
 {
-       CancelButton();
-}
-
-
-void GuiDialog::slotApply()
-{
-       ApplyButton();
-}
-
-
-void GuiDialog::slotOK()
-{
-       OKButton();
-}
-
-
-void GuiDialog::slotClose()
-{
-       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"