]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/Toolbars.h
e6989b183d4398639035f8e07d28d56ff7183a9f
[lyx.git] / src / frontends / qt / Toolbars.h
1 // -*- C++ -*-
2 /**
3  * \file Toolbars.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef TOOLBAR_BACKEND_H
14 #define TOOLBAR_BACKEND_H
15
16 #include "support/docstring.h"
17
18 #include <vector>
19 #include <map>
20 #include <memory>
21
22
23 namespace lyx {
24
25 class FuncRequest;
26
27 namespace support { class Lexer; }
28
29 namespace frontend {
30
31 class ToolbarItem {
32 public:
33         enum Type {
34                 /// command/action with rtl version
35                 BIDICOMMAND,
36                 /// command/action
37                 COMMAND,
38                 /// the command buffer
39                 MINIBUFFER,
40                 /// adds space between buttons in the toolbar
41                 SEPARATOR,
42                 /// a special combox insead of a button
43                 LAYOUTS,
44                 /// a special widget to insert tabulars
45                 TABLEINSERT,
46                 /// a button that expands a menu
47                 POPUPMENU,
48                 /// a button that expands a menu but remembers the last choice
49                 STICKYPOPUPMENU,
50                 ///
51                 ICONPALETTE,
52                 ///
53                 DYNAMICMENU
54         };
55
56         ToolbarItem(Type type,
57                  FuncRequest const & func,
58                  docstring const & label = docstring());
59
60         ToolbarItem(Type type,
61                  std::string const & name = std::string(),
62                  docstring const & label = docstring());
63
64         /// item type
65         Type type;
66         /// action
67         std::shared_ptr<FuncRequest> func; // non-null
68         /// label/tooltip
69         docstring label;
70         /// name
71         std::string name;
72 };
73
74
75 ///
76 class ToolbarInfo {
77 public:
78         /// the toolbar items
79         typedef std::vector<ToolbarItem> Items;
80
81         typedef Items::const_iterator item_iterator;
82
83         explicit ToolbarInfo(std::string const & name = std::string())
84                 : name(name), allow_auto(false) {}
85
86         /// toolbar name
87         std::string name;
88         /// toolbar GUI name
89         docstring gui_name;
90         /// allows auto visibility
91         bool allow_auto;
92         /// toolbar contents
93         Items items;
94
95         /// read a toolbar from the file
96         ToolbarInfo & read(support::Lexer &);
97
98 private:
99         /// add toolbar item
100         void add(ToolbarItem const &);
101 };
102
103
104 ///
105 class Toolbars {
106 public:
107         /// toolbar visibility flags
108         enum Visibility {
109                 ON = 1, //< show
110                 OFF = 2, //< do not show
111                 TOP = 4, //< show at top
112                 BOTTOM = 8, //< show at bottom
113                 LEFT = 16, //< show at left
114                 RIGHT = 32, //< show at right
115                 AUTO = 64,  //< only if AUTO is set, when MATH, TABLE and REVIEW is used
116                 MATH = 128, //< show when in math
117                 TABLE = 256, //< show when in table
118                 REVIEW = 512, //< show when change tracking is enabled
119                 MATHMACROTEMPLATE = 1024, //< show in math macro template
120                 SAMEROW = 2048, //< place to the current row, no new line
121                 IPA = 4096, //< show when in IPA inset
122                 MINIBUFFER = 8192, //< show when command-execute has been invoked
123                 MINIBUFFER_FOCUS = 16384, //< set focus to minibuffer
124                 ALLOWAUTO = MATH | TABLE | REVIEW | MATHMACROTEMPLATE | IPA | MINIBUFFER
125         };
126
127         typedef std::vector<ToolbarInfo> Infos;
128
129         Toolbars() {}
130
131         ///
132         void reset();
133
134         /// iterator for all toolbars
135         Infos::const_iterator begin() const { return toolbar_info_.begin(); }
136
137         Infos::const_iterator end() const { return toolbar_info_.end(); }
138
139         Infos::iterator begin() { return toolbar_info_.begin(); }
140
141         Infos::iterator end() { return toolbar_info_.end(); }
142
143         /// read toolbars from the file
144         void readToolbars(support::Lexer &);
145
146         /// read ui toolbar settings
147         void readToolbarSettings(support::Lexer &);
148
149         ///
150         ToolbarInfo const * info(std::string const & name) const;
151         ///
152         int defaultVisibility(std::string const & name) const;
153         ///
154         bool isMainToolbar(std::string const & name) const;
155
156 private:
157         /// all the defined toolbars
158         Infos toolbar_info_;
159         ///
160         std::map<std::string, int> toolbar_visibility_;
161 };
162
163 } // namespace frontend
164 } // namespace lyx
165
166 #endif // TOOLBAR_BACKEND_H