Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HelperClasses.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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #ifndef HELPERCLASSES_HH_INCLUDED
51 #define HELPERCLASSES_HH_INCLUDED
52 
54 
55 #include <QAction>
56 #include <QPushButton>
57 #include <QGridLayout>
58 
59 class HandleAction : public QAction {
60 
61  public:
63  HandleAction(QIcon _icon, QString _description, QObject* _parent = 0, DataType _objectTypeRestriction = DATA_ALL) :
64  QAction(_icon, _description, _parent),
65  associatedTypes_(0u),
66  objectTypeRestriction_(_objectTypeRestriction) {}
67 
70 
72  void selectionEnvironmentHandle(QString _handle) { selectionEnvHandle_ = _handle; }
73  QString selectionEnvironmentHandle() { return selectionEnvHandle_; }
74 
76  void selectionModeHandle(QString _handle) { selectionModeHandle_ = _handle; }
77  QString selectionModeHandle() { return selectionModeHandle_; }
78 
80  void addAssociatedType(unsigned int _associatedType) { associatedTypes_ |= _associatedType; }
81  void removeAssociatedType(unsigned int _associatedType) { associatedTypes_ &= ~_associatedType; }
82  bool isAssociated(unsigned int _type, bool _associatedWithAll = false) {
83 
84  if(_associatedWithAll && _type != 0u)
85  return ((associatedTypes_ | _type) == associatedTypes_);
86  else
87  return ((associatedTypes_ & _type) != 0);
88  }
89 
90  void objectTypeRestriction(const DataType& _type) {
91  objectTypeRestriction_ = _type;
92  }
93 
94  const DataType& objectTypeRestriction() const {
95  return objectTypeRestriction_;
96  }
97 
98  private:
99  QString selectionEnvHandle_;
100  QString selectionModeHandle_;
101 
102  unsigned int associatedTypes_;
103 
104  DataType objectTypeRestriction_;
105 };
106 
107 class PrimitiveAction : public QAction {
108 
109  public:
111  PrimitiveAction(QIcon _icon, QString _description, QObject* _parent = 0) :
112  QAction(_icon, _description, _parent),
113  primitiveType_(0),
114  selectionEnvironmentHandle_("")
115  {};
116 
119 
121  void primitiveType(unsigned int _type) { primitiveType_ = _type; }
122  unsigned int primitiveType() { return primitiveType_; }
123 
125  void selectionEnvironmentHandle(const QString _handle) {
126  selectionEnvironmentHandle_ = _handle;
127  }
128  QString selectionEnvironmentHandle() const {
129  return selectionEnvironmentHandle_;
130  }
131 
132  private:
133  unsigned int primitiveType_;
134  QString selectionEnvironmentHandle_;
135 };
136 
137 class ActionButton : public QPushButton {
138  Q_OBJECT
139 
140  public:
142  ActionButton(QAction* _action, QWidget* _parent = 0) :
143  QPushButton(_parent), action_(_action) {
144  // Initialize button with action parameters
145  setCheckable(true);
146  setIcon(action_->icon());
147  setIconSize(QSize(48,48));
148  setToolTip(action_->text());
149 
150  connect(action_, SIGNAL(toggled(bool)), this, SLOT(setChecked(bool)));
151  connect(this, SIGNAL(toggled(bool)), action_, SLOT(setChecked(bool)));
152  };
153 
156 
157  private slots:
158 
159  // Avoid back sending of signal (this results in an infinite loop)
160  void setChecked(bool _checked) {
161  blockSignals(true);
162  QPushButton::setChecked(_checked);
163  blockSignals(false);
164  }
165 
166  void changeRegistered() {
167  setChecked(action_->isChecked());
168  }
169 
170  private:
171  QAction* action_;
172 };
173 
174 class FillingLayout : public QGridLayout {
175  public:
177  FillingLayout(int _numColumns) :
178  QGridLayout(),
179  currentRow_(0),
180  currentColumn_(0),
181  numColumns_(_numColumns) {};
182 
183  void addWidget(QWidget* _widget) {
184 
185  QGridLayout::addWidget(_widget, currentRow_, currentColumn_);
186 
187  currentColumn_++;
188  if(currentColumn_ == numColumns_) {
189  currentColumn_ = 0;
190  currentRow_++;
191  }
192  };
193 
194  private:
195  unsigned int currentRow_;
196  unsigned int currentColumn_;
197  unsigned int numColumns_;
198 };
199 
200 #endif // HELPERCLASSES_HH_INCLUDED
~PrimitiveAction()
Default destructor.
void selectionEnvironmentHandle(QString _handle)
Get/Set selection environment handle name.
void addAssociatedType(unsigned int _associatedType)
Get/Set associated primitive types.
~HandleAction()
Default destructor.
ActionButton(QAction *_action, QWidget *_parent=0)
Default constructor.
void selectionEnvironmentHandle(const QString _handle)
Get/Set associated selection environment handle.
PrimitiveAction(QIcon _icon, QString _description, QObject *_parent=0)
Default constructor.
void selectionModeHandle(QString _handle)
Get/Set selection mode handle name.
HandleAction(QIcon _icon, QString _description, QObject *_parent=0, DataType _objectTypeRestriction=DATA_ALL)
Default constructor.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Predefined datatypes.
Definition: DataTypes.hh:96
~ActionButton()
Default destructor.
void primitiveType(unsigned int _type)
Get/Set primitive type.
FillingLayout(int _numColumns)
Default Constructor.