]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DockView.h
8ae303ce34e30f1d26e7e99b72d7ca3a7f11e1b8
[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 "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 showData(std::string const & data)
57         {
58                 controller_->initialiseParams(data);
59                 showView();
60         }
61         void showView()
62         {
63                 widget_->updateView();  // make sure its up-to-date
64                 QDockWidget::show();
65         }
66         bool isVisibleView() const { return QDockWidget::isVisible(); }
67         void checkStatus() { updateView(); }
68         void redraw() { redrawView(); }
69         void redrawView() {}
70         void updateData(std::string const & data)
71         {
72                 controller_->initialiseParams(data);
73                 updateView();
74         }
75         void updateView()
76         {
77                 widget_->updateView();
78                 QDockWidget::update();
79         }
80         bool isClosing() const { return false; }
81         void partialUpdateView(int /*id*/) {}
82         Controller & controller() { return *controller_; }
83         std::string name() const { return name_; }
84         //@}
85 private:
86         /// The encapsulated widget.
87         MyWidget * widget_;
88         Controller * controller_;
89         std::string name_;
90 };
91
92 } // frontend
93 } // lyx
94
95 #endif // DOCK_VIEW_H