]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Toolbar_pimpl.h
better selection and scrolling behaviour
[lyx.git] / src / frontends / qt2 / Toolbar_pimpl.h
1 // -*- C++ -*-
2 /**
3  * \file qt2/Toolbar_pimpl.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  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef TOOLBAR_PIMPL_H
13 #define TOOLBAR_PIMPL_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "frontends/Toolbar.h"
20
21 #include <boost/scoped_ptr.hpp>
22 #include <map>
23 #include <vector>
24
25 #include <qobject.h>
26 #include <qtoolbutton.h>
27
28 class QtView;
29 class QToolBar;
30 class QLComboBox;
31 class ToolbarProxy;
32
33 struct Toolbar::Pimpl {
34 public:
35         friend class ToolbarProxy;
36
37         Pimpl(LyXView * o, int x, int y);
38
39         ~Pimpl();
40
41         /// add a new button to the toolbar.
42         void add(int action);
43
44         /// update the state of the icons
45         void update();
46
47         /// select the right layout in the combox
48         void setLayout(string const & layout);
49         /// Populate the layout combox; re-do everything if force is true.
50         void updateLayoutList(bool force);
51         /// Drop down the layout list
52         void openLayoutList();
53         /// Erase the layout list
54         void clearLayoutList();
55 private:
56         void changed_layout(string const & sel);
57
58         void button_selected(QToolButton * button);
59
60         QtView * owner_;
61
62         boost::scoped_ptr<ToolbarProxy> proxy_;
63
64         std::vector<QToolBar *> toolbars_;
65
66         QLComboBox * combo_;
67
68         typedef std::map<QToolButton *, int> ButtonMap;
69
70         ButtonMap map_;
71 };
72
73
74 // moc is mind-numbingly stupid
75 class ToolbarProxy : public QObject {
76         Q_OBJECT
77 public:
78         ToolbarProxy(Toolbar::Pimpl & owner)
79                 : owner_(owner) {}
80 public slots:
81
82         void layout_selected(const QString & str) {
83                 owner_.changed_layout(str.latin1());
84         }
85
86         void button_selected() {
87                 owner_.button_selected(
88                         const_cast<QToolButton *>(
89                         static_cast<QToolButton const *>(sender()))
90                 );
91         }
92 private:
93         Toolbar::Pimpl & owner_;
94 };
95
96 #endif