Developer Documentation
CoreWidgetToolbar.cc
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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS MViewWidget - IMPLEMENTATION
55 //
56 //=============================================================================
57 
58 
59 //== INCLUDES =================================================================
60 
61 // -------------------- mview
62 #include "CoreWidget.hh"
63 // -------------------- ACG
64 
65 // -------------------- Qt
66 
67 //== IMPLEMENTATION ==========================================================
68 
69 void CoreWidget::slotAddToolbar(QToolBar* _toolbar) {
70 
71  int id = -1;
72 
73  // Find the plugin which added this Toolbox
74  for ( unsigned int i = 0 ; i < plugins_.size(); ++i ) {
75  if ( plugins_[i].plugin == sender() ) {
76  id = i;
77  break;
78  }
79  }
80 
81  // Find the scripting plugin because we assign this toolBox to it as we did not find the original sender
82  if ( id == -1 ) {
83  for ( unsigned int i = 0 ; i < plugins_.size(); ++i ) {
84  if ( plugins_[i].name == "Scripting" ) {
85  id = i;
86  break;
87  }
88  }
89 
90  }
91 
92  // Check if a toolbar with the same name is already registered
93  for ( unsigned int i = 0 ; i < toolbars_.size(); ++i ) {
94  if ( toolbars_[i]->windowTitle() == _toolbar->windowTitle() ) {
95  emit log(LOGERR,tr("slotAddToolbar: Toolbar already added to system: ") + _toolbar->windowTitle() );
96  return;
97  }
98  }
99 
100  // Correctly set the object ame
101  _toolbar->setObjectName( _toolbar->windowTitle() );
102 
103  // Store in internal vector
104  toolbars_.push_back( _toolbar );
105 
106  // Add to main ui
107  addToolBar( _toolbar );
108 
109  // Remember which plugin this toolbar belongs to
110  if ( id != -1 )
111  plugins_[id].toolbars.push_back( std::pair< QString,QToolBar* >( _toolbar->windowTitle() , _toolbar) );
112 
113  // add widget name to viewMode 'all'
114  if ( !viewModes_[0]->visibleToolbars.contains( _toolbar->windowTitle() ) ){
115  viewModes_[0]->visibleToolbars << _toolbar->windowTitle();
116  viewModes_[0]->visibleToolbars.sort();
117  }
118 
119 }
120 
121 void CoreWidget::getToolBar( QString _name, QToolBar*& _toolbar) {
122 
123  for ( unsigned int i = 0 ; i < toolbars_.size(); ++i ) {
124 
125  if ( toolbars_[i]->windowTitle() == _name ) {
126  _toolbar = toolbars_[i];
127  return;
128  }
129 
130  }
131 
132  _toolbar = 0;
133 
134  emit log(LOGERR,tr("getToolBar: Toolbar \"%1\" not found.").arg(_name) );
135 }
136 
137 void CoreWidget::slotRemoveToolbar(QToolBar* _toolbar) {
138  for ( unsigned int i = 0 ; i < toolbars_.size(); ++i ) {
139 
140  if ( toolbars_[i]->windowTitle() == _toolbar->windowTitle() ) {
141  std::cerr << "Todo : erase Toolbar from list" << std::endl;
142  removeToolBar( _toolbar );
143  return;
144  }
145 
146  }
147 
148  emit log(LOGERR,tr("Remove Toolbar: Toolbar not found.") );
149 }
150 
152  return defaultIconSize_;
153 }
154 
155 //=============================================================================
std::vector< PluginInfo > plugins_
List of all loaded plugins_.
Definition: Core.hh:1208
QSize defaultIconSize_
Show logger in splitter or not.
Definition: CoreWidget.hh:562
QSize defaultIconSize()
Show logger in splitter or not.
void slotRemoveToolbar(QToolBar *_toolbar)
Called by Plugins to remove a Toolbar.
void slotAddToolbar(QToolBar *_toolbar)
Called by Plugins to add a Toolbar.
void getToolBar(QString _name, QToolBar *&_toolbar)
Called by Plugins to get access to specific Toolbars by name.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
std::vector< QToolBar * > toolbars_
Called by Plugins to add a Toolbar.
Definition: CoreWidget.hh:1235
QVector< ViewMode * > & viewModes_
List of currently available viewModes.
Definition: CoreWidget.hh:577