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