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