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