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