Developer Documentation
QtFlapBox.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44
45
46//=============================================================================
47//
48// CLASS QtFlapBox
49//
50//=============================================================================
51
52#ifndef ACG_QT_FLAPBOX_HH
53#define ACG_QT_FLAPBOX_HH
54
55//== INCLUDES =================================================================
56
57#include <iostream>
58
59#include <QPushButton>
60#include <QBoxLayout>
61#include <QResizeEvent>
62#include <QFrame>
63#include <QScrollArea>
64#include "../Config/ACGDefines.hh"
65
66//== NAMESPACES ===============================================================
67
68namespace ACG {
69namespace QtWidgets {
70
71//== CLASS DEFINITION =========================================================
72
73class ACGDLLEXPORT QtFlapBox : public QScrollArea
74{
75 Q_OBJECT
76
77public:
78
79#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
80 QtFlapBox( QWidget * _parent = 0, Qt::WindowFlags _f = 0 );
81#else
82 QtFlapBox( QWidget * _parent = 0, Qt::WindowFlags _f = Qt::WindowFlags() );
83#endif
84
85 ~QtFlapBox ();
86
87 int addItem( QWidget * _widget, const QIcon & _icon, const QString & _text );
88 int addItem( QWidget * _widget, const QString & _text );
89
90 int count () const;
91
92 int indexOf( QWidget * _widget ) const;
93 int insertItem( int _index, QWidget * _widget,
94 const QIcon & _icon, const QString & _text );
95 int insertItem( int _index, QWidget * _widget, const QString & _text );
96
97 bool isItemEnabled( int _index ) const;
98 QIcon itemIcon( int _index ) const;
99
100 QString itemText( int _index ) const;
101 QString itemToolTip( int _index ) const;
102 void removeItem( int _index );
103 void setItemEnabled( int _index, bool _enabled );
104 void setItemIcon( int _index, const QIcon & _icon );
105 void setItemText( int _index, const QString & _text );
106 void setItemToolTip( int _index, const QString & _toolTip );
107 QWidget * widget( int _index ) const;
108
109 // the following methods are specific for QtFlapBox
110
111 bool isItemHidden( int _index ) const;
112 void setItemHidden( int _index, bool _hidden );
113
114 virtual QSize sizeHint() const;
115
116
117 virtual void resizeEvent ( QResizeEvent * _event );
118
119signals:
120
121 void sizeHintChanged();
122
123
124// void toggled( int index, bool state );
125
126
127// public slots:
128
129// void toggle( int index );
130
131
132// private slots:
133
134// void flapToggled( bool );
135
136 // virtual QSize sizeHint () const;
137
138private:
139
140
141 struct Flap
142 {
143 QPushButton * button;
144 QWidget * widget;
145
146 void setText( const QString & _text )
147 {
148 button->setText( _text );
149 }
150
151 void setIcon( const QIcon & _icon )
152 {
153 button->setIcon( _icon );
154 }
155
156 void setToolTip( const QString & _tip )
157 {
158 button->setToolTip( _tip );
159 }
160
161 QString text() const
162 {
163 return button->text();
164 }
165
166 QIcon icon() const
167 {
168 return button->icon();
169 }
170
171 QString toolTip() const
172 {
173 return button->toolTip();
174 }
175
176 bool operator==( const Flap & _other ) const
177 {
178 return widget == _other.widget;
179 }
180 };
181
182
183
184private slots:
185
186 void buttonClicked();
187 void widgetDestroyed(QObject*);
188
189private:
190
191 typedef QList< Flap > FlapList;
192
193 Flap * flap( QWidget * _widget ) const;
194 const Flap * flap( int _index ) const;
195 Flap * flap( int _index );
196
197 void updateFlaps();
198 void relayout();
199
200 FlapList flapList;
201 QVBoxLayout * boxlayout;
202 QWidget * container;
203
204};
205
206//=============================================================================
207} // namespace QtWidgets
208} // namespace ACG
209//=============================================================================
210#endif // ACG_QT_FLAPBOX_HH defined
211//=============================================================================
Namespace providing different geometric functions concerning angles.