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>
30 class GuiCommandBuffer;
36 class MenuButtonBase : public QToolButton
41 MenuButtonBase(GuiToolbar * bar, ToolbarItem const & item);
45 virtual void initialize() = 0;
49 ToolbarItem const & tbitem_;
53 void actionTriggered(QAction * action);
55 virtual void updateTriggered() = 0;
59 class StaticMenuButton : public MenuButtonBase
64 StaticMenuButton(GuiToolbar * bar, ToolbarItem const & item,
65 bool const sticky = false);
69 void initialize() override;
73 void updateTriggered() override;
77 /// A menu which can be populated on the fly.
78 /// The 'type' of menu must be given in the toolbar file
79 /// (stdtoolbars.inc, usually) and must be one of:
80 /// dynamic-custom-insets
81 /// dynamic-char-styles
84 /// To add a new one of these, you must add a routine, like
85 /// loadFlexInsets, that will populate the menu, and call it from
86 /// updateTriggered. Make sure to add the new type to isMenuType().
87 class DynamicMenuButton : public MenuButtonBase
92 DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item);
96 static bool isMenuType(std::string const & s);
98 static void resetIconCache();
101 void initialize() override;
103 void loadFlexInsets();
104 /// pimpl so we don't have to include big files
109 void updateTriggered() override;
111 /// These icons are needed at each updateTriggered() call, and
112 /// therefore we have to cache them.
113 static QIcon icon_textstyle_apply_;
114 static QIcon icon_undo_;
115 static QIcon icon_paste_;
119 class GuiToolbar : public QToolBar
124 GuiToolbar(ToolbarInfo const &, GuiView &);
126 /// Reimplemented from QToolbar to detect whether the
127 /// toolbar is restored with MainWindow::restoreState().
128 void setVisible(bool visible) override;
131 void setVisibility(int visibility);
133 /// Add a button to the bar.
134 void add(ToolbarItem const & item);
138 * This key must be used for any session setting.
140 QString sessionKey() const;
141 /// Save session settings.
142 void saveSession(QSettings & settings) const;
143 /// Restore session settings.
144 void restoreSession();
147 bool isRestored() const;
150 bool isVisibilityOn() const;
151 int visibility() const { return visibility_; }
153 /// Refresh the contents of the bar.
154 void update(int context = 0);
157 void setState(std::string const state);
164 /// toggles movability
165 void movable(bool silent = false);
168 GuiCommandBuffer * commandBuffer() { return command_buffer_; }
170 /// add item to toolbar.
171 /// \param menu : when true, the item is for a menu entry, not a button.
172 Action * addItem(ToolbarItem const & item, bool menu = false);
174 GuiView const & owner() { return owner_; }
181 void showContextMenu(QPoint pos);
184 // load flags with saved values
189 void showEvent(QShowEvent *) override;
192 QList<Action *> actions_;
193 /// initial visibility flags
198 GuiCommandBuffer * command_buffer_;
200 ToolbarInfo const & tbinfo_;
207 } // namespace frontend
210 #endif // GUITOOLBAR_H