]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DockView.h
c1c207468cdfd26c1106336fb84c2f9ca70989d8
[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 #include <boost/scoped_ptr.hpp>
23
24 #include <string>
25
26 namespace lyx {
27 namespace frontend {
28
29 /// Dock Widget container for LyX dialogs.
30 /// This template class that encapsulates a given Widget inside a
31 /// QDockWidget and presents a Dialog interface
32 template<class MyController, class MyWidget>
33 class DockView : public QDockWidget, public Dialog
34 {
35 public:
36         DockView(
37                 GuiViewBase & parent, ///< the main window where to dock.
38                 std::string const & name, ///< dialog identifier.
39                 Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
40                 Qt::WindowFlags flags = 0
41                 )
42                 : QDockWidget(&parent, flags),
43                 Dialog(parent, name)
44         {
45                 if (flags & Qt::Drawer)
46                         setFeatures(QDockWidget::NoDockWidgetFeatures);
47                 MyController * controller = new MyController(*this);
48                 setController(controller);
49                 widget_.reset(new MyWidget(*controller));
50                 setWidget(widget_.get());
51                 setWindowTitle(widget_->windowTitle());
52                 parent.addDockWidget(area, this);
53         }
54
55         /// Dialog inherited methods
56         //@{
57         void applyView() {}
58         void hideView() { QDockWidget::hide(); }
59         void showView() { QDockWidget::show(); }
60         bool isVisibleView() const { return QDockWidget::isVisible(); }
61         void redrawView() {}
62         void updateView()
63         {
64                 widget_->updateView();
65                 QDockWidget::update();
66         }
67         //@}
68 private:
69         /// The encapsulated widget.
70         boost::scoped_ptr<MyWidget> widget_;
71 };
72
73 } // frontend
74 } // lyx
75
76 #endif // DOCK_VIEW_H