]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/IconPalette.h
* Allow toolbar menus and panels (qt>=4.2) to be torn off
[lyx.git] / src / frontends / qt4 / IconPalette.h
1 // -*- C++ -*-
2 /**
3  * \file IconPalette.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef ICONPALETTE_H
13 #define ICONPALETTE_H
14
15 #include <QWidget>
16 #include <QMenu>
17 #include <QLayout>
18 #include "Action.h"
19
20 // FIXME: this can go when we move to Qt 4.3
21 #define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
22
23 #if QT_VERSION >= QT_VERSION_CHECK(4, 2, 0)
24 #include <QWidgetAction>
25 #endif
26
27 namespace lyx {
28 namespace frontend {
29
30 /**
31  * For holding an arbitrary set of icons.
32  */
33 #if QT_VERSION >= QT_VERSION_CHECK(4, 2, 0)
34
35 class IconPalette : public QWidgetAction {
36         Q_OBJECT
37 public:
38         IconPalette(QWidget * parent);
39         void addButton(QAction *);
40         QWidget * createWidget(QWidget * parent);
41 public Q_SLOTS:
42         void updateParent();
43         void setIconSize(const QSize &);
44 Q_SIGNALS:
45         void enabled(bool);
46         void iconSizeChanged(const QSize &);
47 private:
48         QList<QAction *> actions_;
49         QSize size_;
50 };
51
52 #else
53
54 class IconPalette : public QWidget {
55         Q_OBJECT
56 public:
57         IconPalette(QWidget * parent);
58         void addButton(QAction *);
59
60 public Q_SLOTS:
61         void updateParent();
62
63 Q_SIGNALS:
64         void triggered(QAction *);
65         void visible(bool);
66
67 protected:
68         void showEvent(QShowEvent * event);
69         void hideEvent(QHideEvent * event);
70         void paintEvent(QPaintEvent * event);
71
72 private Q_SLOTS:
73         virtual void clicked(QAction *);
74
75 private:
76         QGridLayout * layout_;
77         QList<QAction *> actions_;
78 };
79
80 #endif // QT_VERSION >= QT_VERSION_CHECK(4, 2, 0)
81
82 /**
83  * Popup menu for a toolbutton.
84  * We need this to keep track whether
85  * it is necessary to enable/disable
86  * the toolbutton
87  */
88 class ButtonMenu : public QMenu {
89         Q_OBJECT
90 public:
91         ButtonMenu(const QString & title, QWidget * parent = 0 );
92         void add(QAction *);
93
94 public Q_SLOTS:
95         void updateParent();
96
97 private:
98         QList<QAction *> actions_;
99 };
100
101
102 } // namespace frontend
103 } // namespace lyx
104
105 #endif // ICONPALETTE_H