]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DockView.h
This is the last of a series of patches that merges the layout modules development...
[lyx.git] / src / frontends / qt4 / DockView.h
1 // -*- C++ -*-
2 /**
3  * \file DockView.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 DOCK_VIEW_H
13 #define DOCK_VIEW_H
14
15 #include "controllers/Dialog.h"
16 #include "GuiView.h"
17 #include "qt_helpers.h"
18 #include "debug.h"
19
20 #include <QDockWidget>
21
22 namespace lyx {
23 namespace frontend {
24
25 /// Dock Widget container for LyX dialogs.
26 /// This template class that encapsulates a given Widget inside a
27 /// QDockWidget and presents a Dialog interface
28 template<class MyController, class MyWidget>
29 class DockView : public QDockWidget, public Dialog
30 {
31 public:
32         DockView(
33                 GuiViewBase & parent, ///< the main window where to dock.
34                 std::string const & name, ///< dialog identifier.
35                 Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
36                 Qt::WindowFlags flags = 0
37         )
38                 : QDockWidget(&parent, flags), name_(name)
39         {
40                 if (flags & Qt::Drawer)
41                         setFeatures(QDockWidget::NoDockWidgetFeatures);
42                 MyController * c = new MyController(*this);
43                 controller_ = c;
44                 controller_->setLyXView(parent);
45                 widget_ = new MyWidget(*c);
46                 setWidget(widget_);
47                 setWindowTitle(widget_->windowTitle());
48                 parent.addDockWidget(area, this);
49         }
50         ~DockView() { delete widget_; delete controller_; }
51
52         /// Dialog inherited methods
53         //@{
54         void applyView() {}
55         void hideView() { QDockWidget::hide(); }
56         void showView() { QDockWidget::show(); }
57         bool isVisibleView() const { return QDockWidget::isVisible(); }
58         void checkStatus() {}
59         void redraw() { redrawView(); }
60         void redrawView() {}
61         void updateView()
62         {
63                 widget_->updateView();
64                 QDockWidget::update();
65         }
66         bool isClosing() const { return false; }
67         void partialUpdateView(int /*id*/) {}
68         Controller & controller() { return *controller_; }
69         std::string name() const { return name_; }
70         //@}
71 private:
72         /// The encapsulated widget.
73         MyWidget * widget_;
74         Controller * controller_;
75         std::string name_;
76 };
77
78 } // frontend
79 } // lyx
80
81 #endif // DOCK_VIEW_H