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"
32 class GuiCommandBuffer;
38 class MenuButtonBase : public QToolButton
43 MenuButtonBase(GuiToolbar * bar, ToolbarItem const & item);
47 virtual void initialize() = 0;
51 ToolbarItem const & tbitem_;
55 void actionTriggered(QAction * action);
57 virtual void updateTriggered() = 0;
61 class StaticMenuButton : public MenuButtonBase
66 StaticMenuButton(GuiToolbar * bar, ToolbarItem const & item,
67 bool const sticky = false);
71 void initialize() override;
75 void updateTriggered() override;
79 /// A menu which can be populated on the fly.
80 /// The 'type' of menu must be given in the toolbar file
81 /// (stdtoolbars.inc, usually) and must be one of:
82 /// dynamic-custom-insets
83 /// dynamic-char-styles
86 /// To add a new one of these, you must add a routine, like
87 /// loadFlexInsets, that will populate the menu, and call it from
88 /// updateTriggered. Make sure to add the new type to isMenuType().
89 class DynamicMenuButton : public MenuButtonBase
94 DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item);
98 static bool isMenuType(std::string const & s);
101 void initialize() override;
103 void loadFlexInsets();
104 /// pimpl so we don't have to include big files
109 void updateTriggered() override;
113 class GuiToolbar : public QToolBar
118 GuiToolbar(ToolbarInfo const &, GuiView &);
120 /// Reimplemented from QToolbar to detect whether the
121 /// toolbar is restored with MainWindow::restoreState().
122 void setVisible(bool visible) override;
125 void setVisibility(int visibility);
127 /// Add a button to the bar.
128 void add(ToolbarItem const & item);
132 * This key must be used for any session setting.
134 QString sessionKey() const;
135 /// Save session settings.
136 void saveSession(QSettings & settings) const;
137 /// Restore session settings.
138 void restoreSession();
141 bool isRestored() const;
144 bool isVisibiltyOn() const;
145 int visibility() const { return visibility_; }
147 /// Refresh the contents of the bar.
148 void update(int context = 0);
153 /// toggles movability
154 void movable(bool silent = false);
157 GuiCommandBuffer * commandBuffer() { return command_buffer_; }
160 Action * addItem(ToolbarItem const & item);
162 GuiView const & owner() { return owner_; }
169 // load flags with saved values
174 void showEvent(QShowEvent *) override;
177 QList<Action *> actions_;
178 /// initial visibility flags
183 GuiCommandBuffer * command_buffer_;
185 ToolbarInfo const & tbinfo_;
192 } // namespace frontend
195 #endif // GUITOOLBAR_H