]> Creatis software - clitk.git/blob - vv/vvToolCreatorBase.cxx
Reformatted using new coding style
[clitk.git] / vv / vvToolCreatorBase.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18
19 #include "vvToolCreatorBase.h"
20 #include "vvToolManager.h"
21 #include <QAction>
22 #include <QMenu>
23
24 //------------------------------------------------------------------------------
25 vvToolCreatorBase::vvToolCreatorBase(QString name): mExperimental(false)
26 {
27   mUseContextMenu = false;
28   mToolName = name;
29   vvToolManager::GetInstance()->AddTool(this);
30 }
31 //------------------------------------------------------------------------------
32
33 //------------------------------------------------------------------------------
34 void vvToolCreatorBase::MenuToolSlot()
35 {
36   mSender = QObject::sender();
37   MenuSpecificToolSlot();
38 }
39 //------------------------------------------------------------------------------
40
41
42 //------------------------------------------------------------------------------
43 void vvToolCreatorBase::InsertToolInMenu(vvMainWindowBase * m)
44 {
45   mMainWindow = m;
46   if (mUseContextMenu) {
47     InsertToolInContextMenu();
48     return;
49   }
50   // Create main action
51   if (mToolIconFilename == "noicon")
52     mAction = new QAction(QString("&").append(mToolMenuName), this);
53   else
54     mAction = new QAction(QIcon(mToolIconFilename),
55                           QString("&").append(mToolMenuName), this);
56   mAction->setStatusTip(mToolTip);
57   // Connect the action
58   connect(mAction, SIGNAL(triggered()), this, SLOT(MenuToolSlot()));
59   if (mExperimental)
60     mMainWindow->GetExperimentalToolMenu()->addAction(mAction);
61   else
62     mMainWindow->GetToolMenu()->addAction(mAction);
63 }
64 //------------------------------------------------------------------------------
65
66
67 //------------------------------------------------------------------------------
68 void vvToolCreatorBase::InsertToolInContextMenu()
69 {
70   mMainWindow->GetContextMenu()->addMenu(mToolMenu);
71   for(unsigned int i=0; i<mListOfActions.size(); i++) {
72     connect(mListOfActions[i], SIGNAL(triggered()), this, SLOT(MenuToolSlot()));
73   }
74 }
75 //------------------------------------------------------------------------------
76
77
78 //------------------------------------------------------------------------------
79 void vvToolCreatorBase::addMenuToContextMenu(QMenu * m)
80 {
81   mToolMenu = m;
82   for(int i=0; i<m->actions().size(); i++) {
83     mListOfActions.push_back(m->actions()[i]);
84   }
85   mUseContextMenu = true;
86 }
87 //------------------------------------------------------------------------------