]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToolbar.h
Give textstyle-apply a history
[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 ///             dynamic-freefonts
90 /// To add a new one of these, you must add a routine, like 
91 /// loadFlexInsets, that will populate the menu, and call it from
92 /// updateTriggered. Make sure to add the new type to isMenuType().
93 class DynamicMenuButton : public MenuButtonBase
94 {
95     Q_OBJECT
96 public:
97         ///
98         DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item);
99         ///
100         ~DynamicMenuButton();
101         ///
102         static bool isMenuType(std::string const & s);
103 protected:
104         ///
105         void initialize();
106         ///
107         void loadFlexInsets();
108         /// pimpl so we don't have to include big files
109         class Private;
110         Private * d;
111 protected Q_SLOTS:
112         ///
113         void updateTriggered();
114 };
115
116
117 class GuiToolbar : public QToolBar
118 {
119         Q_OBJECT
120 public:
121         ///
122         GuiToolbar(ToolbarInfo const &, GuiView &);
123
124         /// Reimplemented from QToolbar to detect whether the
125         /// toolbar is restored with MainWindow::restoreState().
126         void setVisible(bool visible);
127
128         ///
129         void setVisibility(int visibility);
130
131         /// Add a button to the bar.
132         void add(ToolbarItem const & item);
133
134         /// Session key.
135         /**
136          * This key must be used for any session setting.
137          **/
138         QString sessionKey() const;
139         /// Save session settings.
140         void saveSession(QSettings & settings) const;
141         /// Restore session settings.
142         void restoreSession();
143
144         ///
145         bool isRestored() const;
146
147         /// Refresh the contents of the bar.
148         void update(int context = 0);
149
150         ///
151         void toggle();
152
153         /// toggles movability
154         void movable(bool silent = false);
155
156         ///
157         GuiCommandBuffer * commandBuffer() { return command_buffer_; }
158
159         ///
160         Action * addItem(ToolbarItem const & item);
161     ///
162     GuiView const & owner() { return owner_; }
163
164 Q_SIGNALS:
165         ///
166         void updated();
167
168 private:
169         // load flags with saved values
170         void initFlags();
171         ///
172         void fill();
173         ///
174         void showEvent(QShowEvent *);
175
176         ///
177         QList<Action *> actions_;
178         /// initial visibility flags
179         int visibility_;
180         ///
181         GuiView & owner_;
182         ///
183         GuiCommandBuffer * command_buffer_;
184         ///
185         ToolbarInfo const & tbinfo_;
186         ///
187         bool filled_;
188         ///
189         bool restored_;
190 };
191
192 } // namespace frontend
193 } // namespace lyx
194
195 #endif // GUITOOLBAR_H