HelperClasses.hh 7.75 KB
Newer Older
Jan Möbius's avatar
   
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
38
39
 *   $Revision$                                                       *
 *   $Author$                                                       *
 *   $Date$                   *
Jan Möbius's avatar
   
Jan Möbius committed
40
41
42
43
44
45
 *                                                                           *
\*===========================================================================*/

#ifndef HELPERCLASSES_HH_INCLUDED
#define HELPERCLASSES_HH_INCLUDED

46
47
#include <OpenFlipper/common/DataTypes.hh>

Jan Möbius's avatar
   
Jan Möbius committed
48
49
50
51
52
53
54
55
#include <QAction>
#include <QPushButton>
#include <QGridLayout>

class HandleAction : public QAction {
    
    public:
        /// Default constructor
56
        HandleAction(QIcon _icon, QString _description, QObject* _parent = 0, DataType _objectTypeRestriction = DATA_ALL) :
Jan Möbius's avatar
   
Jan Möbius committed
57
            QAction(_icon, _description, _parent),
58
59
            associatedTypes_(0u),
            objectTypeRestriction_(_objectTypeRestriction) {}
Jan Möbius's avatar
   
Jan Möbius committed
60
61
       
        /// Default destructor
62
        ~HandleAction() {}
Jan Möbius's avatar
   
Jan Möbius committed
63
64
        
        /// Get/Set selection environment handle name
65
66
        void selectionEnvironmentHandle(QString _handle) { selectionEnvHandle_ = _handle; }
        QString selectionEnvironmentHandle() { return selectionEnvHandle_; }
Jan Möbius's avatar
   
Jan Möbius committed
67
68
        
        /// Get/Set selection mode handle name
69
70
        void selectionModeHandle(QString _handle) { selectionModeHandle_ = _handle; }
        QString selectionModeHandle() { return selectionModeHandle_; }
Jan Möbius's avatar
   
Jan Möbius committed
71
72
73
74
75
76
77
78
79
80
81
82
        
        /// Get/Set associated primitive types
        void addAssociatedType(unsigned int _associatedType) { associatedTypes_ |= _associatedType; }
        void removeAssociatedType(unsigned int _associatedType) { associatedTypes_ &= ~_associatedType; }
        bool isAssociated(unsigned int _type, bool _associatedWithAll = false) {

            if(_associatedWithAll && _type != 0u)
                return ((associatedTypes_ | _type) == associatedTypes_);
            else
                return ((associatedTypes_ & _type) != 0);
        }
        
83
84
85
86
87
88
89
90
        void objectTypeRestriction(const DataType& _type) {
            objectTypeRestriction_ = _type;
        }

        const DataType& objectTypeRestriction() const {
            return objectTypeRestriction_;
        }

Jan Möbius's avatar
   
Jan Möbius committed
91
92
93
94
95
    private:
        QString selectionEnvHandle_;
        QString selectionModeHandle_;
        
        unsigned int associatedTypes_;
96
97

        DataType objectTypeRestriction_;
Jan Möbius's avatar
   
Jan Möbius committed
98
99
100
101
102
103
104
};

class PrimitiveAction : public QAction {
    
    public:
        /// Default constructor
        PrimitiveAction(QIcon _icon, QString _description, QObject* _parent = 0) :
Jan Möbius's avatar
Jan Möbius committed
105
106
107
108
            QAction(_icon, _description, _parent),
            primitiveType_(0),
            selectionEnvironmentHandle_("")
        {};
Jan Möbius's avatar
   
Jan Möbius committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
       
        /// Default destructor
        ~PrimitiveAction() {};
        
        /// Get/Set primitive type
        void primitiveType(unsigned int _type) { primitiveType_ = _type; }
        unsigned int primitiveType() { return primitiveType_; }
        
        /// Get/Set associated selection environment handle
        void selectionEnvironmentHandle(const QString _handle) {
            selectionEnvironmentHandle_ = _handle;
        }
        QString selectionEnvironmentHandle() const {
            return selectionEnvironmentHandle_;
        }
        
    private:
        unsigned int primitiveType_;
        QString selectionEnvironmentHandle_;
};

class ActionButton : public QPushButton {
    Q_OBJECT
    
    public:
        /// Default constructor
        ActionButton(QAction* _action, QWidget* _parent = 0) :
            QPushButton(_parent), action_(_action) {
            // Initialize button with action parameters
            setCheckable(true);
            setIcon(action_->icon());
            setIconSize(QSize(48,48));
            setToolTip(action_->text());
            
            connect(action_, SIGNAL(toggled(bool)), this, SLOT(setChecked(bool)));
            connect(this, SIGNAL(toggled(bool)), action_, SLOT(setChecked(bool)));
        };
        
        /// Default destructor
        ~ActionButton() {};

    private slots:

        // Avoid back sending of signal (this results in an infinite loop)
        void setChecked(bool _checked) {
            blockSignals(true);
            QPushButton::setChecked(_checked);
            blockSignals(false);
        }

        void changeRegistered() {
            setChecked(action_->isChecked());
        }
        
    private:
        QAction* action_;
};

class FillingLayout : public QGridLayout {
    public:
        /// Default Constructor
        FillingLayout(int _numColumns) :
            QGridLayout(),
            currentRow_(0),
            currentColumn_(0),
            numColumns_(_numColumns) {};
            
        void addWidget(QWidget* _widget) {
            
            QGridLayout::addWidget(_widget, currentRow_, currentColumn_);
            
            currentColumn_++;
            if(currentColumn_ == numColumns_) {
                currentColumn_ = 0;
                currentRow_++;
            }
        };
        
    private:
        unsigned int currentRow_;
        unsigned int currentColumn_;
        unsigned int numColumns_;
};

#endif // HELPERCLASSES_HH_INCLUDED