]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToolbars.cpp
Move most of the Gui specific code in Toolbars to its new qt4 specialization GuiToolbars.
[lyx.git] / src / frontends / qt4 / GuiToolbars.cpp
1 /**
2  * \file GuiToolbars.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Angus Leeming
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiToolbars.h"
16
17 #include "GuiToolbar.h"
18 #include "GuiView.h"
19
20 #include "Buffer.h"
21 #include "BufferParams.h"
22 #include "debug.h"
23 #include "FuncRequest.h"
24 #include "FuncStatus.h"
25 #include "gettext.h"
26 #include "Layout.h"
27 #include "LyX.h"
28 #include "LyXFunc.h"
29 #include "TextClass.h"
30
31
32 using std::endl;
33 using std::string;
34
35 namespace lyx {
36 namespace frontend {
37
38 GuiToolbars::GuiToolbars(GuiViewBase & owner)
39         : owner_(owner),
40           layout_(0),
41           last_textclass_(TextClassPtr())
42 {}
43
44
45 bool GuiToolbars::visible(string const & name) const
46 {
47         std::map<string, GuiToolbar *>::const_iterator it =
48                 toolbars_.find(name);
49         if (it == toolbars_.end())
50                 return false;
51         return it->second->isVisible();
52 }
53
54
55 void GuiToolbars::saveToolbarInfo()
56 {
57         ToolbarSection & tb = LyX::ref().session().toolbars();
58
59         for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
60                 cit != toolbarbackend.end(); ++cit) {
61                 ToolbarsMap::iterator it = toolbars_.find(cit->name);
62                 BOOST_ASSERT(it != toolbars_.end());
63                 // get toolbar info from session.
64                 ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
65                 if (cit->flags & ToolbarInfo::ON)
66                         info.state = ToolbarSection::ToolbarInfo::ON;
67                 else if (cit->flags & ToolbarInfo::OFF)
68                         info.state = ToolbarSection::ToolbarInfo::OFF;
69                 else if (cit->flags & ToolbarInfo::AUTO)
70                         info.state = ToolbarSection::ToolbarInfo::AUTO;
71                 // save other information
72                 // if auto, frontend should *not* set on/off
73                 it->second->saveInfo(info);
74                 // maybe it is useful to update flags with real status. I do not know
75                 /*
76                 if (!(cit->flags & ToolbarInfo::AUTO)) {
77                         unsigned int flags = static_cast<unsigned int>(cit->flags);
78                         flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
79                         flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
80                         if (info.state == ToolbarSection::ToolbarInfo::ON)
81                         cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
82                 }
83                 */
84         }
85 }
86
87
88 void GuiToolbars::setLayout(docstring const & layout)
89 {
90         if (layout_)
91                 layout_->set(layout);
92 }
93
94
95 bool GuiToolbars::updateLayoutList(TextClassPtr textclass)
96 {
97         // update the layout display
98         if (last_textclass_ != textclass) {
99                 if (layout_)
100                         layout_->updateContents();
101                 last_textclass_ = textclass;
102                 return true;
103         } else
104                 return false;
105 }
106
107
108 void GuiToolbars::openLayoutList()
109 {
110         if (layout_)
111                 layout_->open();
112 }
113
114
115 void GuiToolbars::clearLayoutList()
116 {
117         last_textclass_ = TextClassPtr();
118         if (layout_)
119                 layout_->clear();
120 }
121
122
123 void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
124 {
125         GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline);
126         toolbars_[tbinfo.name] = tb_ptr;
127
128         if (tbinfo.flags & ToolbarInfo::ON)
129                 tb_ptr->show();
130         else
131                 tb_ptr->hide();
132
133         if (tb_ptr->layout())
134                 layout_ = tb_ptr->layout();
135 }
136
137
138 void GuiToolbars::displayToolbar(ToolbarInfo const & tbinfo,
139                               bool show_it)
140 {
141         ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
142         BOOST_ASSERT(it != toolbars_.end());
143
144         if (show_it) {
145                 if (it->second->isVisible())
146                         return;
147                 it->second->show();
148         }
149         else if (it->second->isVisible())
150                 it->second->hide();
151 }
152
153
154 void GuiToolbars::updateIcons()
155 {
156         ToolbarsMap::const_iterator it = toolbars_.begin();
157         ToolbarsMap::const_iterator const end = toolbars_.end();
158         for (; it != end; ++it)
159                 it->second->updateContents();
160
161         bool const enable =
162                 lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
163
164         if (layout_)
165                 layout_->setEnabled(enable);
166 }
167
168 } // namespace frontend
169 } // namespace lyx