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