]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/DialogView.h
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / DialogView.h
index e4a2ea97fd6d1190baabf70f5a010c8948ad7222..a95b1a435cd910141d5557a5e5b7ac7c314c7ece 100644 (file)
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef DIALOG_VIEW_H
-#define DIALOG_VIEW_H
+#ifndef DIALOGVIEW_H
+#define DIALOGVIEW_H
 
 #include "Dialog.h"
 #include "GuiView.h"
-#include "qt_helpers.h"
-#include "debug.h"
 
 #include <QCloseEvent>
 #include <QDialog>
-#include <QSettings>
-#include <QShowEvent>
-#include <QGridLayout>
-
-#include <string>
 
 namespace lyx {
 namespace frontend {
 
-/// Window Dialog container for LyX dialogs.
-/// This template class that encapsulates a given Widget inside a
-/// QDialog and presents a Dialog interface
-template<class MyWidget>
 class DialogView : public QDialog, public Dialog
 {
 public:
-       DialogView(
-               GuiView & parent, ///< the main window where to dock.
-               std::string const & name, ///< dialog identifier.
-               bool modal = false, ///< Window modality.
-               Qt::WindowFlags flags = 0
-               )
-               : QDialog(&parent, flags), Dialog(parent, name)
-       {
-               setModal(modal);
-               QGridLayout * gridLayout = new QGridLayout(this);
-               gridLayout->setMargin(0);
-               widget_ = new MyWidget(*this, this);
-               gridLayout->addWidget(widget_);
-               setWindowTitle("LyX: " + widget_->windowTitle());
-       }
+       /// \param lv is the access point for the dialog to the LyX kernel.
+       /// \param name is the identifier given to the dialog by its parent
+       /// container.
+       /// \param title is the window title used for decoration.
+       DialogView(GuiView & lv, QString const & name, QString const & title)
+               : QDialog(&lv), Dialog(lv, name, "LyX: " + title)
+       {}
 
-       /// Dialog inherited methods
+       virtual QWidget * asQWidget() { return this; }
+       virtual QWidget const * asQWidget() const { return this; }
+
+protected:
+       /// \name Dialog inherited methods
        //@{
        void applyView() {}
-       void hideView()
-       {
-               clearParams();
-               QDialog::hide();
-       }
-       void showData(std::string const & data)
-       {
-               initialiseParams(data);
-               showView();
-       }
-       void showView()
-       {
-               widget_->updateView();  // make sure its up-to-date
-               QDialog::show();
-               raise();
-               activateWindow();
-       }
-       bool isVisibleView() const { return QDialog::isVisible(); }
-       void checkStatus() { updateView(); }
-       void updateData(std::string const & data)
-       {
-               initialiseParams(data);
-               updateView();
-       }
-       void updateView()
-       {
-               widget_->updateView();
-       }
+       bool initialiseParams(std::string const & /*data*/) { return true; }
+       void clearParams() {}
        //@}
-private:
-       /// The encapsulated widget.
-       MyWidget * widget_;
-
-       void showEvent(QShowEvent * e)
+       /// Any dialog that overrides this method should make sure to call it.
+       void closeEvent(QCloseEvent * ev)
        {
-               QSettings settings;
-               std::string key = name() + "/geometry";
-               QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
-           QDialog::showEvent(e);
+               clearParams();
+               Dialog::disconnect();
+               ev->accept();
        }
-
-       void closeEvent(QCloseEvent * e)
+       /// Any dialog that overrides this method should make sure to call it.
+       void hideEvent(QHideEvent * ev)
        {
-               QSettings settings;
-               std::string key = name() + "/geometry";
-               settings.setValue(key.c_str(), QDialog::saveGeometry());
-               QDialog::closeEvent(e);
+               if (!ev->spontaneous()) {
+                       clearParams();
+                       Dialog::disconnect();
+                       ev->accept();
+               }
        }
 };
 
-} // frontend
-} // lyx
+} // namespace frontend
+} // namespace lyx
 
-#endif // DIALOG_VIEW_H
+#endif // DIALOGVIEW_H