]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiToolbar.h
Fix readability
[lyx.git] / src / frontends / qt / GuiToolbar.h
1 // -*- C++ -*-
2 /**
3  * \file GuiToolbar.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author Jean-Marc Lasgouttes
10  * \author Angus Leeming
11  * \author Abdelrazak Younes
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef GUITOOLBAR_H
17 #define GUITOOLBAR_H
18
19 #include <QList>
20 #include <QToolBar>
21 #include <QToolButton>
22
23 #include "support/strfwd.h"
24
25 class QSettings;
26
27 namespace lyx {
28
29 namespace frontend {
30
31 class Action;
32 class GuiCommandBuffer;
33 class GuiToolbar;
34 class GuiView;
35 class ToolbarInfo;
36 class ToolbarItem;
37
38 class MenuButtonBase : public QToolButton
39 {
40         Q_OBJECT
41 public:
42         ///
43         MenuButtonBase(GuiToolbar * bar, ToolbarItem const & item);
44
45 protected:
46         ///
47         virtual void initialize() = 0;
48         ///
49         GuiToolbar * bar_;
50         ///
51         ToolbarItem const & tbitem_;
52
53 protected Q_SLOTS:
54         ///
55         void actionTriggered(QAction * action);
56         ///
57         virtual void updateTriggered() = 0;
58 };
59
60
61 class StaticMenuButton : public MenuButtonBase
62 {
63         Q_OBJECT
64 public:
65         ///
66         StaticMenuButton(GuiToolbar * bar, ToolbarItem const & item,
67                 bool const sticky = false);
68
69 protected:
70         ///
71         void initialize() override;
72
73 protected Q_SLOTS:
74         ///
75         void updateTriggered() override;
76 };
77
78
79 /// A menu which can be populated on the fly.
80 /// The 'type' of menu must be given in the toolbar file
81 /// (stdtoolbars.inc, usually) and must be one of:
82 ///             dynamic-custom-insets
83 ///             dynamic-char-styles
84 ///             textstyle-apply
85 ///             paste
86 /// To add a new one of these, you must add a routine, like 
87 /// loadFlexInsets, that will populate the menu, and call it from
88 /// updateTriggered. Make sure to add the new type to isMenuType().
89 class DynamicMenuButton : public MenuButtonBase
90 {
91     Q_OBJECT
92 public:
93         ///
94         DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item);
95         ///
96         ~DynamicMenuButton();
97         ///
98         static bool isMenuType(std::string const & s);
99         ///
100         static void resetIconCache();
101 protected:
102         ///
103         void initialize() override;
104         ///
105         void loadFlexInsets();
106         /// pimpl so we don't have to include big files
107         class Private;
108         Private * d;
109 protected Q_SLOTS:
110         ///
111         void updateTriggered() override;
112 private:
113         /// These icons are needed at each updateTriggered() call, and
114         /// therefore we have to cache them.
115         static QIcon icon_textstyle_apply_;
116         static QIcon icon_undo_;
117         static QIcon icon_paste_;
118 };
119
120
121 class GuiToolbar : public QToolBar
122 {
123         Q_OBJECT
124 public:
125         ///
126         GuiToolbar(ToolbarInfo const &, GuiView &);
127
128         /// Reimplemented from QToolbar to detect whether the
129         /// toolbar is restored with MainWindow::restoreState().
130         void setVisible(bool visible) override;
131
132         ///
133         void setVisibility(int visibility);
134
135         /// Add a button to the bar.
136         void add(ToolbarItem const & item);
137
138         /// Session key.
139         /**
140          * This key must be used for any session setting.
141          **/
142         QString sessionKey() const;
143         /// Save session settings.
144         void saveSession(QSettings & settings) const;
145         /// Restore session settings.
146         void restoreSession();
147
148         ///
149         bool isRestored() const;
150
151         ///
152         bool isVisibilityOn() const;
153         int visibility() const { return visibility_; }
154
155         /// Refresh the contents of the bar.
156         void update(int context = 0);
157
158         ///
159         void setState(std::string const state);
160         ///
161         void toggle();
162
163         ///
164         void refill();
165
166         /// toggles movability
167         void movable(bool silent = false);
168
169         ///
170         GuiCommandBuffer * commandBuffer() { return command_buffer_; }
171
172         /// add item to toolbar.
173         /// \param menu : when true, the item is for a menu entry, not a button.
174         Action * addItem(ToolbarItem const & item, bool menu = false);
175         ///
176         GuiView const & owner() { return owner_; }
177
178 Q_SIGNALS:
179         ///
180         void updated();
181
182 private Q_SLOTS:
183         void showContextMenu(QPoint pos);
184
185 private:
186         // load flags with saved values
187         void initFlags();
188         ///
189         void fill();
190         ///
191         void showEvent(QShowEvent *) override;
192
193         ///
194         QList<Action *> actions_;
195         /// initial visibility flags
196         int visibility_;
197         ///
198         GuiView & owner_;
199         ///
200         GuiCommandBuffer * command_buffer_;
201         ///
202         ToolbarInfo const & tbinfo_;
203         ///
204         bool filled_;
205         ///
206         bool restored_;
207 };
208
209 } // namespace frontend
210 } // namespace lyx
211
212 #endif // GUITOOLBAR_H