Developer Documentation
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 #pragma once
43 
45 
46 #include "Actionbutton.hh"
47 #include <QAction>
48 #include <QPushButton>
49 #include <QGridLayout>
50 
51 class HandleAction : public QAction {
52 
53  public:
55  HandleAction(QIcon _icon, QString _description, QObject* _parent = 0, DataType _objectTypeRestriction = DATA_ALL) :
56  QAction(_icon, _description, _parent),
57  associatedTypes_(0u),
58  objectTypeRestriction_(_objectTypeRestriction) {}
59 
62 
64  void selectionEnvironmentHandle(QString _handle) { selectionEnvHandle_ = _handle; }
65  QString selectionEnvironmentHandle() { return selectionEnvHandle_; }
66 
68  void selectionModeHandle(QString _handle) { selectionModeHandle_ = _handle; }
69  QString selectionModeHandle() { return selectionModeHandle_; }
70 
72  void addAssociatedType(unsigned int _associatedType) { associatedTypes_ |= _associatedType; }
73  void removeAssociatedType(unsigned int _associatedType) { associatedTypes_ &= ~_associatedType; }
74  bool isAssociated(unsigned int _type, bool _associatedWithAll = false) {
75 
76  if(_associatedWithAll && _type != 0u)
77  return ((associatedTypes_ | _type) == associatedTypes_);
78  else
79  return ((associatedTypes_ & _type) != 0);
80  }
81 
82  void objectTypeRestriction(const DataType& _type) {
83  objectTypeRestriction_ = _type;
84  }
85 
86  const DataType& objectTypeRestriction() const {
87  return objectTypeRestriction_;
88  }
89 
90  private:
91  QString selectionEnvHandle_;
92  QString selectionModeHandle_;
93 
94  unsigned int associatedTypes_;
95 
96  DataType objectTypeRestriction_;
97 };
98 
99 class PrimitiveAction : public QAction {
100 
101  public:
103  PrimitiveAction(QIcon _icon, QString _description, QObject* _parent = 0) :
104  QAction(_icon, _description, _parent),
105  primitiveType_(0),
106  selectionEnvironmentHandle_("")
107  {};
108 
111 
113  void primitiveType(unsigned int _type) { primitiveType_ = _type; }
114  unsigned int primitiveType() { return primitiveType_; }
115 
117  void selectionEnvironmentHandle(const QString _handle) {
118  selectionEnvironmentHandle_ = _handle;
119  }
120  QString selectionEnvironmentHandle() const {
121  return selectionEnvironmentHandle_;
122  }
123 
124  private:
125  unsigned int primitiveType_;
126  QString selectionEnvironmentHandle_;
127 };
128 
129 
130 class FillingLayout : public QGridLayout {
131  public:
133  explicit FillingLayout(int _numColumns) :
134  QGridLayout(),
135  currentRow_(0),
136  currentColumn_(0),
137  numColumns_(_numColumns) {};
138 
139  void addWidget(QWidget* _widget) {
140 
141  QGridLayout::addWidget(_widget, currentRow_, currentColumn_);
142 
143  currentColumn_++;
144  if(currentColumn_ == numColumns_) {
145  currentColumn_ = 0;
146  currentRow_++;
147  }
148  };
149 
150  private:
151  unsigned int currentRow_;
152  unsigned int currentColumn_;
153  unsigned int numColumns_;
154 };
155 
156 
void selectionEnvironmentHandle(const QString _handle)
Get/Set associated selection environment handle.
~HandleAction()
Default destructor.
PrimitiveAction(QIcon _icon, QString _description, QObject *_parent=0)
Default constructor.
Predefined datatypes.
Definition: DataTypes.hh:83
~PrimitiveAction()
Default destructor.
FillingLayout(int _numColumns)
Default Constructor.
void addAssociatedType(unsigned int _associatedType)
Get/Set associated primitive types.
void primitiveType(unsigned int _type)
Get/Set primitive type.
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.
void selectionEnvironmentHandle(QString _handle)
Get/Set selection environment handle name.
void selectionModeHandle(QString _handle)
Get/Set selection mode handle name.