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