]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DialogView.h
disable window geometry session handling for Qt < 4.2.
[lyx.git] / src / frontends / qt4 / DialogView.h
1 // -*- C++ -*-
2 /**
3  * \file DialogView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef DIALOG_VIEW_H
13 #define DIALOG_VIEW_H
14
15 #include "controllers/Dialog.h"
16 #include "GuiView.h"
17 #include "qt_helpers.h"
18 #include "debug.h"
19
20 #include <QCloseEvent>
21 #include <QDialog>
22 #include <QSettings>
23 #include <QShowEvent>
24
25 #include <string>
26
27 namespace lyx {
28 namespace frontend {
29
30 /// Window Dialog container for LyX dialogs.
31 /// This template class that encapsulates a given Widget inside a
32 /// QDialog and presents a Dialog interface
33 template<class MyController, class MyWidget>
34 class DialogView : public QDialog, public Dialog
35 {
36 public:
37         DialogView(
38                 GuiViewBase & parent, ///< the main window where to dock.
39                 std::string const & name, ///< dialog identifier.
40                 bool modal = false, ///< Window modality.
41                 Qt::WindowFlags flags = 0
42                 )
43                 : QDialog(&parent, flags), name_(name)
44         {
45                 setModal(modal);
46                 MyController * c = new MyController(*this);
47                 controller_ = c;
48                 controller_->setLyXView(parent);
49                 widget_ = new MyWidget(*c, this);
50                 setWindowTitle("LyX: " + widget_->windowTitle());
51         }
52
53         /// Dialog inherited methods
54         //@{
55         void applyView() {}
56         void hideView()
57         {
58                 controller().clearParams();
59                 QDialog::hide();
60         }
61         void showData(std::string const & data)
62         {
63                 controller_->initialiseParams(data);
64                 showView();
65         }
66         void showView()
67         {
68                 widget_->updateView();  // make sure its up-to-date
69                 QDialog::show();
70                 raise();
71                 activateWindow();
72         }
73         bool isVisibleView() const { return QDialog::isVisible(); }
74         void checkStatus() { updateView(); }
75         void redraw() { redrawView(); }
76         void redrawView() {}
77         void updateData(std::string const & data)
78         {
79                 controller_->initialiseParams(data);
80                 updateView();
81         }
82         void updateView()
83         {
84                 widget_->updateView();
85         }
86         void partialUpdateView(int /*id*/) {}
87         Controller & controller() { return *controller_; }
88         std::string name() const { return name_; }
89         //@}
90 private:
91         /// The encapsulated widget.
92         MyWidget * widget_;
93         Controller * controller_;
94         std::string name_;
95
96         void showEvent(QShowEvent * e)
97         {
98 #if (QT_VERSION >= 0x040200)
99                 QSettings settings;
100                 std::string key = name_ + "/geometry";
101                 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
102 #endif
103             QDialog::showEvent(e);
104         }
105
106         void closeEvent(QCloseEvent * e)
107         {
108 #if (QT_VERSION >= 0x040200)
109                 QSettings settings;
110                 std::string key = name_ + "/geometry";
111                 settings.setValue(key.c_str(), QDialog::saveGeometry());
112 #endif
113             QDialog::closeEvent(e);
114         }
115 };
116
117 } // frontend
118 } // lyx
119
120 #endif // DIALOG_VIEW_H