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);
100 static void resetIconCache();
103 void initialize() override;
105 void loadFlexInsets();
106 /// pimpl so we don't have to include big files
111 void updateTriggered() override;
113 /// These icons are needed at each updateTriggered() call, and
114 /// therefore we have to cache them.
115 static QIcon icon_textstyle_apply_;
116 static QIcon icon_undo_;
117 static QIcon icon_paste_;
121 class GuiToolbar : public QToolBar
126 GuiToolbar(ToolbarInfo const &, GuiView &);
128 /// Reimplemented from QToolbar to detect whether the
129 /// toolbar is restored with MainWindow::restoreState().
130 void setVisible(bool visible) override;
133 void setVisibility(int visibility);
135 /// Add a button to the bar.
136 void add(ToolbarItem const & item);
140 * This key must be used for any session setting.
142 QString sessionKey() const;
143 /// Save session settings.
144 void saveSession(QSettings & settings) const;
145 /// Restore session settings.
146 void restoreSession();
149 bool isRestored() const;
152 bool isVisibiltyOn() const;
153 int visibility() const { return visibility_; }
155 /// Refresh the contents of the bar.
156 void update(int context = 0);
159 void setState(std::string const state);
166 /// toggles movability
167 void movable(bool silent = false);
170 GuiCommandBuffer * commandBuffer() { return command_buffer_; }
173 Action * addItem(ToolbarItem const & item);
175 GuiView const & owner() { return owner_; }
182 // load flags with saved values
187 void showEvent(QShowEvent *) override;
190 QList<Action *> actions_;
191 /// initial visibility flags
196 GuiCommandBuffer * command_buffer_;
198 ToolbarInfo const & tbinfo_;
205 } // namespace frontend
208 #endif // GUITOOLBAR_H