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