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