]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DialogView.h
* DialogView: Initial Window geometry session support.
[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
24 #include <string>
25
26 namespace lyx {
27 namespace frontend {
28
29 /// Window Dialog container for LyX dialogs.
30 /// This template class that encapsulates a given Widget inside a
31 /// QDialog and presents a Dialog interface
32 template<class MyController, class MyWidget>
33 class DialogView : public QDialog, public Dialog
34 {
35 public:
36         DialogView(
37                 GuiViewBase & parent, ///< the main window where to dock.
38                 std::string const & name, ///< dialog identifier.
39                 bool modal = false, ///< Window modality.
40                 Qt::WindowFlags flags = 0
41                 )
42                 : QDialog(&parent, flags), name_(name)
43         {
44                 setModal(modal);
45                 MyController * c = new MyController(*this);
46                 controller_ = c;
47                 controller_->setLyXView(parent);
48                 widget_ = new MyWidget(*c, this);
49                 setWindowTitle("LyX: " + widget_->windowTitle());
50         }
51
52         /// Dialog inherited methods
53         //@{
54         void applyView() {}
55         void hideView()
56         {
57                 controller().clearParams();
58                 QDialog::hide();
59         }
60         void showData(std::string const & data)
61         {
62                 controller_->initialiseParams(data);
63                 showView();
64         }
65         void showView()
66         {
67                 widget_->updateView();  // make sure its up-to-date
68                 QDialog::show();
69                 raise();
70                 activateWindow();
71         }
72         bool isVisibleView() const { return QDialog::isVisible(); }
73         void checkStatus() { updateView(); }
74         void redraw() { redrawView(); }
75         void redrawView() {}
76         void updateData(std::string const & data)
77         {
78                 controller_->initialiseParams(data);
79                 updateView();
80         }
81         void updateView()
82         {
83                 widget_->updateView();
84         }
85         void partialUpdateView(int /*id*/) {}
86         Controller & controller() { return *controller_; }
87         std::string name() const { return name_; }
88         //@}
89 private:
90         /// The encapsulated widget.
91         MyWidget * widget_;
92         Controller * controller_;
93         std::string name_;
94
95         void showEvent(QShowEvent * e)
96         {
97                 QSettings settings;
98                 std::string key = name_ + "/geometry";
99                 restoreGeometry(settings.value(key.c_str()).toByteArray());
100             QDialog::showEvent(e);
101         }
102
103         void closeEvent(QCloseEvent * e)
104         {
105                 QSettings settings;
106                 std::string key = name_ + "/geometry";
107                 settings.setValue(key.c_str(), saveGeometry());
108             QDialog::closeEvent(e);
109         }
110 };
111
112 } // frontend
113 } // lyx
114
115 #endif // DIALOG_VIEW_H