OpenWalnut  1.5.0dev
WQtColormapper.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTCOLORMAPPER_H
26 #define WQTCOLORMAPPER_H
27 
28 #include <memory>
29 #include <vector>
30 
31 #include <QDockWidget>
32 #include <QListWidget>
33 #include <QListWidgetItem>
34 #include <QPushButton>
35 #include <QVBoxLayout>
36 #include <boost/signals2/signal.hpp>
37 
38 #include "../guiElements/WQtDockWidget.h"
39 #include "core/common/WSharedObject.h"
40 #include "core/common/WSharedSequenceContainer.h"
41 #include "core/graphicsEngine/WGETexture.h"
42 
43 class WDataSet;
44 
45 /**
46  * This widget controls the colormapper of openwalnut. It directly interacts with WGEColormapper.
47  */
49 {
50  Q_OBJECT
51 
52 public:
53  /**
54  * Default constructor.
55  *
56  * \param parent Parent widget.
57  */
58  explicit WQtColormapper( QWidget* parent = 0 );
59 
60  /**
61  * Destructor.
62  */
63  virtual ~WQtColormapper();
64 
65  /**
66  * Select a certain texture in the texture sorter belonging to the specified dataset
67  *
68  * \param dataSet this data set will be selected after calling this method
69  */
70  void selectTexture( std::shared_ptr< WDataSet > dataSet );
71 
72 signals:
73  /**
74  * Indicates that a texture has been clicked and return the texture
75  *
76  * \param texture the texture that got selected
77  */
78  void textureSelectionChanged( osg::ref_ptr< WGETexture3D > texture );
79 
80 protected:
81  /**
82  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
83  * processes several custom events.
84  *
85  * \param event the event that got transmitted.
86  *
87  * \return true if the event got handled properly.
88  */
89  virtual bool event( QEvent* event );
90 
91 private:
92  QListWidget* m_textureListWidget; //!< pointer to the tree widget
93  QVBoxLayout* m_layout; //!< Layout of the widget
94 
95  /**
96  * Connection of the WGEColormapping signal "registered" to the member function pushUpdateEvent.
97  */
98  boost::signals2::connection m_registerConnection;
99 
100  /**
101  * Connection of the WGEColormapping signal "deregistered" to the member function pushUpdateEvent.
102  */
103  boost::signals2::connection m_deregisterConnection;
104 
105  /**
106  * Connection of the WGEColormapping signal "replaced" to the member function pushUpdateEvent.
107  */
108  boost::signals2::connection m_replaceConnection;
109 
110  /**
111  * Connection of the WGEColormapping signal "Sort" to the member function pushUpdateEvent.
112  */
113  boost::signals2::connection m_sortConnection;
114 
115  /**
116  * Called by the colormapper causing an update event being pushed to the event queue.
117  */
118  void pushUpdateEvent();
119 
120  /**
121  * Update the list view from the list of data sets.
122  */
123  void update();
124 
125  /**
126  * This class represents a texture item in the list widget. It provides the pointer to the texture it manages.
127  */
129  {
130  public: // NOLINT
131  /**
132  * Creates new instance of list item. It takes the texture it handles as argument.
133  *
134  * \param texture the texture to handle with this item
135  * \param parent parent widget
136  * \param cmapper the colormapper widget managing updates for this item.
137  */
138  WQtTextureListItem( const osg::ref_ptr< WGETexture3D > texture, WQtColormapper* cmapper, QListWidget* parent = 0 );
139 
140  /**
141  * Destructor.
142  */
143  virtual ~WQtTextureListItem();
144 
145  /**
146  * Returns the associated texture.
147  *
148  * \return the associated texture
149  */
150  const osg::ref_ptr< WGETexture3D > getTexture() const;
151 
152  /**
153  * Create a new widget for this item.
154  *
155  * \return the widget
156  */
157  QWidget* getWidget() const;
158  private:
159  /**
160  * The texture that gets handled
161  */
162  const osg::ref_ptr< WGETexture3D > m_texture;
163 
164  /**
165  * Parent list.
166  */
167  QListWidget* m_parent;
168 
169  /**
170  * Widget representing the item.
171  */
172  QWidget* m_itemWidget;
173  };
174 
175 private slots:
176 
177  /**
178  * A item was moved into another row
179  *
180  * \param sourceParent parent of the item(s) moved.
181  * \param sourceStart items moved start index
182  * \param sourceEnd items moved end index (when multiple selected)
183  * \param destinationParent item moved as childs for this item
184  * \param destinationRow items moved to this position
185  */
186  void rowsMoved( const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow );
187 
188  /**
189  * Handles a click to a texture in the list
190  */
191  void handleTextureClicked();
192 
193  /**
194  * change order of items, move currently selected item down
195  */
196  void moveItemDown();
197 
198  /**
199  * change order of items, move currently selected item up
200  */
201  void moveItemUp();
202 
203  /**
204  * change order of items, move currently selected item to bottom
205  */
206  void moveItemBottom();
207 
208  /**
209  * change order of items, move currently selected item to top
210  */
211  void moveItemTop();
212 };
213 
214 #endif // WQTCOLORMAPPER_H
215 
Base class for all data set types.
Definition: WDataSet.h:50
This class represents a texture item in the list widget.
const osg::ref_ptr< WGETexture3D > getTexture() const
Returns the associated texture.
const osg::ref_ptr< WGETexture3D > m_texture
The texture that gets handled.
virtual ~WQtTextureListItem()
Destructor.
QWidget * m_itemWidget
Widget representing the item.
QWidget * getWidget() const
Create a new widget for this item.
QListWidget * m_parent
Parent list.
WQtTextureListItem(const osg::ref_ptr< WGETexture3D > texture, WQtColormapper *cmapper, QListWidget *parent=0)
Creates new instance of list item.
This widget controls the colormapper of openwalnut.
void moveItemUp()
change order of items, move currently selected item up
WQtColormapper(QWidget *parent=0)
Default constructor.
QListWidget * m_textureListWidget
pointer to the tree widget
QVBoxLayout * m_layout
Layout of the widget.
void update()
Update the list view from the list of data sets.
void selectTexture(std::shared_ptr< WDataSet > dataSet)
Select a certain texture in the texture sorter belonging to the specified dataset.
virtual bool event(QEvent *event)
Custom event dispatcher.
boost::signals2::connection m_replaceConnection
Connection of the WGEColormapping signal "replaced" to the member function pushUpdateEvent.
void moveItemTop()
change order of items, move currently selected item to top
boost::signals2::connection m_deregisterConnection
Connection of the WGEColormapping signal "deregistered" to the member function pushUpdateEvent.
virtual ~WQtColormapper()
Destructor.
void moveItemBottom()
change order of items, move currently selected item to bottom
boost::signals2::connection m_sortConnection
Connection of the WGEColormapping signal "Sort" to the member function pushUpdateEvent.
void textureSelectionChanged(osg::ref_ptr< WGETexture3D > texture)
Indicates that a texture has been clicked and return the texture.
void handleTextureClicked()
Handles a click to a texture in the list.
void pushUpdateEvent()
Called by the colormapper causing an update event being pushed to the event queue.
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
A item was moved into another row.
void moveItemDown()
change order of items, move currently selected item down
boost::signals2::connection m_registerConnection
Connection of the WGEColormapping signal "registered" to the member function pushUpdateEvent.
Advanced QDockWidget.
Definition: WQtDockWidget.h:50