4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
11 * \author Abdelrazak Younes
13 * Full author contact details are available in file CREDITS.
21 #include <QToolButton>
23 #include "support/strfwd.h"
35 class GuiCommandBuffer;
36 class GuiLayoutFilterModel;
43 class MenuButtonBase : public QToolButton
48 MenuButtonBase(GuiToolbar * bar, ToolbarItem const & item);
52 virtual void initialize() = 0;
56 ToolbarItem const & tbitem_;
60 void actionTriggered(QAction * action);
62 virtual void updateTriggered() = 0;
66 class StaticMenuButton : public MenuButtonBase
71 StaticMenuButton(GuiToolbar * bar, ToolbarItem const & item,
72 bool const sticky = false);
76 void initialize() override;
80 void updateTriggered() override;
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
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
99 DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item);
101 ~DynamicMenuButton();
103 static bool isMenuType(std::string const & s);
106 void initialize() override;
108 void loadFlexInsets();
109 /// pimpl so we don't have to include big files
114 void updateTriggered() override;
118 class GuiToolbar : public QToolBar
123 GuiToolbar(ToolbarInfo const &, GuiView &);
125 /// Reimplemented from QToolbar to detect whether the
126 /// toolbar is restored with MainWindow::restoreState().
127 void setVisible(bool visible) override;
130 void setVisibility(int visibility);
132 /// Add a button to the bar.
133 void add(ToolbarItem const & item);
137 * This key must be used for any session setting.
139 QString sessionKey() const;
140 /// Save session settings.
141 void saveSession(QSettings & settings) const;
142 /// Restore session settings.
143 void restoreSession();
146 bool isRestored() const;
149 bool isVisibiltyOn() const;
150 int visibility() const { return visibility_; }
152 /// Refresh the contents of the bar.
153 void update(int context = 0);
158 /// toggles movability
159 void movable(bool silent = false);
162 GuiCommandBuffer * commandBuffer() { return command_buffer_; }
165 Action * addItem(ToolbarItem const & item);
167 GuiView const & owner() { return owner_; }
174 // load flags with saved values
179 void showEvent(QShowEvent *) override;
182 QList<Action *> actions_;
183 /// initial visibility flags
188 GuiCommandBuffer * command_buffer_;
190 ToolbarInfo const & tbinfo_;
197 } // namespace frontend
200 #endif // GUITOOLBAR_H