WQtControlPanel.h 10.4 KB
Newer Older
wiebel's avatar
wiebel committed
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
wiebel's avatar
wiebel committed
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
wiebel's avatar
wiebel committed
7
//
wiebel's avatar
wiebel committed
8
// This file is part of OpenWalnut.
wiebel's avatar
wiebel committed
9
//
wiebel's avatar
wiebel committed
10
// OpenWalnut is free software: you can redistribute it and/or modify
wiebel's avatar
wiebel committed
11 12 13 14
// 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.
//
wiebel's avatar
wiebel committed
15
// OpenWalnut is distributed in the hope that it will be useful,
wiebel's avatar
wiebel committed
16 17 18 19 20
// 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 Lesser General Public License
wiebel's avatar
wiebel committed
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
wiebel's avatar
wiebel committed
22
//
wiebel's avatar
wiebel committed
23 24
//---------------------------------------------------------------------------

25 26
#ifndef WQTCONTROLPANEL_H
#define WQTCONTROLPANEL_H
27

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
28
#include <list>
29
#include <string>
30
#include <vector>
wiebel's avatar
wiebel committed
31 32

#include <QtGui/QDockWidget>
33
#include <QtGui/QSplitter>
34 35 36
#include <QtGui/QTabWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
37
#include <QtGui/QListWidget>
wiebel's avatar
wiebel committed
38

Mathias Goldau's avatar
Mathias Goldau committed
39 40
#include "../../../dataHandler/WDataSet.h"
#include "../../../graphicsEngine/WROI.h"
41

42
#include "../WQtCombinerToolbar.h"
43
#include "WQtPropertyGroupWidget.h"
schurade's avatar
schurade committed
44
#include "WQtModuleHeaderTreeItem.h"
Mathias Goldau's avatar
Mathias Goldau committed
45
#include "WQtModuleTreeItem.h"
schurade's avatar
schurade committed
46
#include "WQtRoiHeaderTreeItem.h"
Mathias Goldau's avatar
Mathias Goldau committed
47
#include "WQtSubjectTreeItem.h"
48
#include "WQtTreeWidget.h"
49
#include "WQtTextureSorter.h"
50

51 52
class WMainWindow;

wiebel's avatar
wiebel committed
53
/**
54
 * container widget for a tree widget with context menu and some control widgets
wiebel's avatar
wiebel committed
55
 */
56
class WQtControlPanel : public QDockWidget
wiebel's avatar
wiebel committed
57
{
58 59
    Q_OBJECT

60
public:
61
    /**
62
     * Constructor.
63 64 65
     *
     * \param parent Parent widget.
     */
66
    explicit WQtControlPanel( WMainWindow* parent = 0 );
wiebel's avatar
wiebel committed
67

68
    /**
69
     * Default Destructor.
70
     */
71
    virtual ~WQtControlPanel();
72

73
    /**
74
     * Adds a page to the context widget
schurade's avatar
schurade committed
75 76
     *
     * \param content A widget with controls
77 78
     *
     * \return the index of the new tab
79
     */
80
    int addTabWidgetContent( WQtPropertyGroupWidget* content );
81

82
    /**
83
     * Adds a subject entry to the tree widget
schurade's avatar
schurade committed
84 85 86
     *
     * \param name The entry name of the subjectin the tree widget
     * \return A pointer to the tree widget item
87 88
     */
    WQtSubjectTreeItem* addSubject( std::string name );
wiebel's avatar
wiebel committed
89

90
    /**
91
     * Adds a dataset entry to any given subject in the tree widget
schurade's avatar
schurade committed
92 93 94 95 96
     *
     * \param module shared pointer to the module associated with this tree widget entry
     * \param subjectId subject id this dataset belongs to
     *
     * \return A pointer to the tree widget item
97
     */
98
    WQtDatasetTreeItem* addDataset( boost::shared_ptr< WModule > module, int subjectId = 0 );
99

100
    /**
101
     * Adds a module to the control panel.
102 103 104
     *
     * \param module the module to add.
     *
105
     * \return the representation in control panel.
106
     */
107 108
    WQtModuleTreeItem* addModule( boost::shared_ptr< WModule > module );

schurade's avatar
[DOC]  
schurade committed
109
    /**
110
     * Adds a roi entry to the control panel
schurade's avatar
[DOC]  
schurade committed
111 112 113
     *
     * \param roi pointer to the roi representation object
     */
114
    void addRoi( osg::ref_ptr< WROI > roi );
schurade's avatar
schurade committed
115

116
    /**
117
     * Removes a roi entry from the control panel
118 119 120
     *
     * \param roi pointer to the roi representation object
     */
121
    void removeRoi( osg::ref_ptr< WROI > roi );
122

123
    /**
124
     * helper funtion to connect all qt widgets with their functions
125 126 127
     */
    void connectSlots();

128
    /**
129
     * Returns the module currently selected in control panel.
130 131 132 133 134
     *
     * \return the module.
     */
    boost::shared_ptr< WModule > getSelectedModule();

schurade's avatar
schurade committed
135
    /**
schurade's avatar
[DOC]  
schurade committed
136
     * Returns the currently selected roi.
schurade's avatar
schurade committed
137
     *
schurade's avatar
[DOC]  
schurade committed
138
     * \return pointer to roi representation
schurade's avatar
schurade committed
139
     */
140
    osg::ref_ptr< WROI > getSelectedRoi();
schurade's avatar
schurade committed
141

schurade's avatar
schurade committed
142 143 144 145 146
    /**
     * Returns the first roi in the currently selected branch.
     *
     * \return pointer to roi representation
     */
147
    osg::ref_ptr< WROI > getFirstRoiInSelectedBranch();
schurade's avatar
schurade committed
148

149 150 151 152 153 154 155 156 157 158
    /**
     * Returns a checkable action that can be used to show or close this dock widget.
     * The action's text is set to the dock widget's window title.
     *
     * This member function is overwritten to add a keyboard shortcut to this action.
     *
     * \return Modified QAction
     */
    QAction* toggleViewAction() const;

159
    /**
160
     * Add the specified toolbar to the top of the control panel.
161 162 163 164 165
     *
     * \param tb the toolbar to add
     */
    void addToolbar( QToolBar* tb );

166 167 168 169 170
    /**
     * Selects the uppermost entry in the module tree.
     */
    void selectUpperMostEntry();

171 172
protected:

173 174 175 176 177 178 179 180 181 182
    /**
     * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
     * processes several custom events, like WModuleAssocEvent.
     *
     * \param event the event that got transmitted.
     *
     * \return true if the event got handled properly.
     */
    virtual bool event( QEvent* event );

schurade's avatar
schurade committed
183 184 185 186 187 188
    /**
     * Helper function to return the first subject id in the tree widget
     */
    int getFirstSubject();

    /**
schurade's avatar
[DOC]  
schurade committed
189 190
     * fills the modul toolbar with buttons for modules that are compatible with the currently
     * selected dataset
schurade's avatar
schurade committed
191
     *
schurade's avatar
[DOC]  
schurade committed
192
     * \param module pointer to the currently selected module
193
     *
schurade's avatar
schurade committed
194
     */
195
    void createCompatibleButtons( boost::shared_ptr< WModule > module );
schurade's avatar
schurade committed
196

197 198 199 200
    /**
     * Reference to the main window of the application.
     */
    WMainWindow* m_mainWindow;
201

202
    /**
203
     * Searches the specified tree for all tree items matching the specified module.
204 205
     *
     * \param module the module uses as search criteria.
206
     * \param where in which subtree to search.
207 208 209
     *
     * \return a list of all matching items.
     */
210 211 212 213 214 215
    std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module, QTreeWidgetItem* where );

    /**
     * Searches the tree for all tree items matching the specified module.
     *
     * \param module the module uses as search criteria.
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
216
     *
217 218
     * \return a list of all matching items.
     */
219 220
    std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module );

221
private:
222
    WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget
223 224 225

    WQtTreeWidget* m_roiTreeWidget; //!< pointer to the tree widget

226
    WQtTextureSorter* m_textureSorter; //!< pointer to the tree widget
schurade's avatar
schurade committed
227

schurade's avatar
[DOC]  
schurade committed
228
    QTabWidget* m_tabWidget; //!< pointer to the tab widget
schurade's avatar
schurade committed
229

230 231
    QTabWidget* m_tabWidget2; //!< pointer to the tab widget

schurade's avatar
[DOC]  
schurade committed
232
    QWidget* m_panel; //!< panel
schurade's avatar
schurade committed
233

schurade's avatar
[DOC]  
schurade committed
234
    QVBoxLayout* m_layout; //!< layout
235

236 237
    QSplitter* m_splitter; //!< splitter to have resizable widgets in the control panel

schurade's avatar
[DOC]  
schurade committed
238
    WQtModuleHeaderTreeItem* m_tiModules; //!< header for modules
schurade's avatar
schurade committed
239

schurade's avatar
[DOC]  
schurade committed
240
    WQtRoiHeaderTreeItem* m_tiRois; //!< header for rois
schurade's avatar
schurade committed
241

242 243
    bool m_showToolBarText; //!< Show tool bar icons with text

244 245 246 247 248
    /**
     * The action to remove a module from the tree.
     */
    QAction* m_deleteModuleAction;

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    /**
     * Action which uses a compatibles list (submenu) to connect a selected item with other existing modules.
     */
    QAction* m_connectWithModuleAction;

    /**
     * Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
     */
    QAction* m_connectWithPrototypeAction;

    /**
     * Action which disconnects a connector from the module.
     */
    QAction* m_disconnectAction;

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    /**
     * List all actions created for applying a prototype. Is needed for m_connectWithPrototypeAction.
     *
     * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
     * manually.
     */
    WQtCombinerActionList m_connectWithPrototypeActionList;

    /**
     * List all actions created for applying a prototype. Is needed for m_connectWithModuleAction.
     *
     * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
     * manually.
     */
    WQtCombinerActionList m_connectWithModuleActionList;

    /**
     * List all actions created for applying a prototype. Is needed for m_disconnectAction.
     *
     * \note We need to store this action list here as Qt is not able to delete the actions if they get replaced. We need to handle this
     * manually.
     */
    WQtCombinerActionList m_disconnectActionList;

288 289 290 291 292 293
    /**
     * If true, a selection change does not cause the property tab to rebuild. This is useful if multiple items get selected at once
     * programatically.
     */
    bool m_ignoreSelectionChange;

294 295
private slots:
    /**
schurade's avatar
schurade committed
296 297
     * function that gets called when a tree item is selected, on a new select that tab widget
     * is rebuilt with the controls provided by the tree item
298 299
     */
    void selectTreeItem();
300

301 302 303 304 305 306
    /**
     * function that gets called when a tree item is selected, on a new select that tab widget
     * is rebuilt with the controls provided by the tree item
     */
    void selectRoiTreeItem();

307 308 309 310 311 312
    /**
     * Will be called to select the data module for the given dataset.
     * \param dataSet the module for this dataset will be selected.
     */
    void selectDataModule( boost::shared_ptr< WDataSet > dataSet );

313 314 315
    /**
     * function that builds the property tab
     *
316
     * \param props the properties.
317
     * \param infoProps the information properties shown on a separate tab
318
     */
319
    void buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps );
320

321 322 323 324 325
    /**
     * Method builds a widgets containing all properties in props. It recursively calls itself to build group widgets for WPropGroup properties.
     *
     * \param props the properties.
     */
326
    WQtPropertyGroupWidget* buildPropWidget( boost::shared_ptr< WProperties > props );
327

328
    /**
schurade's avatar
schurade committed
329
     * function gets called when a change to a tree item, eg. check box status, occurs
330
     */
331 332 333 334 335 336 337
    /**
     * Function gets change when a change to a tree item occurs.
     *
     * \param item the item
     * \param column column index
     */
    void changeTreeItem( QTreeWidgetItem* item, int column );
338

schurade's avatar
schurade committed
339
    /**
340
     * delete a ROI tree item
schurade's avatar
schurade committed
341
     */
342
    void deleteROITreeItem();
schurade's avatar
schurade committed
343

344 345 346 347
    /**
     * delete a module tree item
     */
    void deleteModuleTreeItem();
348

schurade's avatar
schurade committed
349 350 351
    /**
     * function to notify the roi manager of any drag&drop action in the roi tree
     */
352
    void handleDragDrop();
wiebel's avatar
wiebel committed
353 354
};

355
#endif  // WQTCONTROLPANEL_H