]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToolbar.h
Next camel
[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 "Session.h"
20
21 #include <QAbstractProxyModel>
22 #include <QComboBox>
23 #include <QList>
24 #include <QToolBar>
25 #include <QToolButton>
26
27 class QSortFilterProxyModel;
28 class QStandardItemModel;
29
30 namespace lyx {
31
32 class DocumentClass;
33 class Inset;
34
35 namespace frontend {
36
37 class Action;
38 class GuiCommandBuffer;
39 class GuiLayoutFilterModel;
40 class GuiToolbar;
41 class GuiView;
42 class LayoutItemDelegate;
43 class ToolbarInfo;
44 class ToolbarItem;
45
46 class GuiLayoutBox : public QComboBox
47 {
48         Q_OBJECT
49 public:
50         GuiLayoutBox(GuiToolbar * bar, GuiView &);
51
52         /// select the right layout in the combobox.
53         void set(docstring const & layout);
54         /// Populate the layout combobox.
55         void updateContents(bool reset);
56         /// Add Item to Layout box according to sorting settings from preferences
57         void addItemSort(docstring const & item, docstring const & category,
58                 bool sorted, bool sortedByCat, bool unknown);
59
60         ///
61         void showPopup();
62         
63         ///
64         bool eventFilter(QObject * o, QEvent * e);
65         ///
66         QString const & filter() { return filter_; }
67
68 private Q_SLOTS:
69         ///
70         void selected(int index);
71         ///
72         void setIconSize(QSize size);
73
74 private:
75         friend class LayoutItemDelegate;
76
77         ///
78         void resetFilter();
79         ///
80         void setFilter(QString const & s);
81         ///
82         QString charFilterRegExp(QString const & filter);
83         ///
84         void countCategories();
85         
86         ///
87         GuiView & owner_;
88         ///
89         GuiToolbar * bar_;
90         ///
91         DocumentClass const * text_class_;
92         ///
93         Inset const * inset_;
94         
95         /// the layout model: 1st column translated, 2nd column raw layout name
96         QStandardItemModel * model_;
97         /// the proxy model filtering \c model_
98         GuiLayoutFilterModel * filterModel_;
99         /// the (model-) index of the last successful selection
100         int lastSel_;
101         /// the character filter
102         QString filter_;
103         ///
104         LayoutItemDelegate * layoutItemDelegate_;
105         ///
106         unsigned visibleCategories_;
107         ///
108         bool inShowPopup_;
109 };
110
111
112 class MenuButton : public QToolButton
113 {
114         Q_OBJECT
115 public:
116         ///
117         MenuButton(GuiToolbar * bar, ToolbarItem const & item,
118                 bool const sticky = false);
119         ///
120         void mousePressEvent(QMouseEvent * e);
121
122 private:
123         ///
124         GuiToolbar * bar_;
125         ///
126         ToolbarItem const & tbitem_;
127         ///
128         bool initialized_;
129
130 private Q_SLOTS:
131         ///
132         void actionTriggered(QAction * action);
133 };
134
135
136
137 class GuiToolbar : public QToolBar
138 {
139         Q_OBJECT
140 public:
141         ///
142         GuiToolbar(ToolbarInfo const &, GuiView &);
143
144         ///
145         void setVisibility(int visibility);
146
147         /// Add a button to the bar.
148         void add(ToolbarItem const & item);
149
150         /// Session key.
151         /**
152          * This key must be used for any session setting.
153          **/
154         QString sessionKey() const;
155         /// Save session settings.
156         void saveSession() const;
157         /// Restore session settings.
158         void restoreSession();
159
160         /// Refresh the contents of the bar.
161         void update(bool in_math, bool in_table, bool review,
162                 bool in_mathmacrotemplate);
163
164         ///
165         void toggle();
166
167         ///
168         GuiCommandBuffer * commandBuffer() { return command_buffer_; }
169
170         ///
171         Action * addItem(ToolbarItem const & item);
172
173 Q_SIGNALS:
174         ///
175         void updated();
176
177 private:
178         // load flags with saved values
179         void initFlags();
180         ///
181         void fill();
182         ///
183         void showEvent(QShowEvent *);
184
185         ///
186         QString name_;
187         ///
188         QList<Action *> actions_;
189         /// initial visibility flags
190         int visibility_;
191         ///
192         bool allowauto_;
193         ///
194         GuiView & owner_;
195         ///
196         GuiLayoutBox * layout_;
197         ///
198         GuiCommandBuffer * command_buffer_;
199         ///
200         ToolbarInfo const & tbinfo_;
201         ///
202         bool filled_;
203 };
204
205 } // namespace frontend
206 } // namespace lyx
207
208 #endif // GUITOOLBAR_H