]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToc.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiToc.cpp
1 /**
2  * \file GuiToc.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiToc.h"
16 #include "GuiView.h"
17 #include "DockView.h"
18 #include "TocWidget.h"
19 #include "qt_helpers.h"
20
21 #include "Buffer.h"
22 #include "BufferView.h"
23 #include "BufferParams.h"
24 #include "FuncRequest.h"
25
26 #include "support/debug.h"
27 #include "support/gettext.h"
28 #include "support/lassert.h"
29
30 using namespace std;
31
32 namespace lyx {
33 namespace frontend {
34
35 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
36         : DockView(parent, "toc", qt_("Outline"), area, flags), is_closing_(false)
37 {
38         widget_ = new TocWidget(parent, this);
39         setWidget(widget_);
40 }
41
42
43 GuiToc::~GuiToc()
44 {
45         delete widget_;
46 }
47
48
49 void GuiToc::updateView()
50 {
51 #ifndef Q_WS_MACX
52         widget_->updateView();
53         return;
54 #endif
55
56         widget_->updateView();
57
58         // For Mac: switch to a docked TOC in fullscreen mode.
59         // We use the features() here instead of WindowFlags because
60         // the latter are not reliable (always returns Qt::Drawer).
61         if (!(features() & DockWidgetClosable) && lyxview().isFullScreen()) {
62                 setWindowFlags(Qt::Widget);
63                 setFeatures(DockWidgetClosable);
64                 // Setting features hides the dialog, see Qt's doc.
65                 show();
66         } else if ((features() & DockWidgetClosable) && !lyxview().isFullScreen()) {
67                 setWindowFlags(Qt::Drawer);
68                 setFeatures(NoDockWidgetFeatures);
69                 // Setting features hides the dialog, see Qt's doc.
70                 show();
71         }
72 }
73
74
75 bool GuiToc::initialiseParams(string const & data)
76 {
77         widget_->init(toqstr(data));
78         return true;
79 }
80
81
82 void GuiToc::dispatchParams()
83 {
84 }
85
86
87 void GuiToc::enableView(bool enable)
88 {
89         if (!enable)
90                 // In the opposite case, updateView() will be called anyway.
91                 widget_->updateView();
92 }
93
94
95 void GuiToc::closeEvent(QCloseEvent * /*event*/)
96 {
97         is_closing_ = true;
98         ((GuiView *)parent())->updateToolbars();
99         is_closing_ = false;
100 }
101
102
103 void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd)
104 {
105         widget_->doDispatch(cur, cmd);
106 }
107
108
109 bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd,
110         FuncStatus & status) const
111 {
112         return widget_->getStatus(cur, cmd, status);
113 }
114
115
116 Dialog * createGuiToc(GuiView & lv)
117 {
118         GuiView & guiview = static_cast<GuiView &>(lv);
119 #ifdef Q_WS_MACX
120         // On Mac show as a drawer at the right
121         return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
122 #else
123         return new GuiToc(guiview);
124 #endif
125 }
126
127
128 } // namespace frontend
129 } // namespace lyx
130
131 #include "moc_GuiToc.cpp"