]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DockView.h
30e336119fc462266f657ffcaa5657591ea7d2ab
[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 & title, ///< Window title (shown in the top title bar).
39                 Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
40                 Qt::WindowFlags flags = 0
41                 )
42                 : QDockWidget(toqstr(title), &parent, flags),
43                 Dialog(parent, title)
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                 parent.addDockWidget(area, this);
52         }
53
54         /// Dialog inherited methods
55         //@{
56         void applyView() {}
57         void hideView() { QDockWidget::hide(); }
58         void showView() { QDockWidget::show(); }
59         bool isVisibleView() const { return QDockWidget::isVisible(); }
60         void redrawView() {}
61         void updateView()
62         {
63                 widget_->updateView();
64                 QDockWidget::update();
65         }
66         //@}
67 private:
68         /// The encapsulated widget.
69         boost::scoped_ptr<MyWidget> widget_;
70 };
71
72 } // frontend
73 } // lyx
74
75 #endif // DOCK_VIEW_H