1 /*=========================================================================
4 Module: $RCSfile: vvToolWidgetBase.cxx,v $
6 Date: $Date: 2010/02/24 11:43:37 $
7 Version: $Revision: 1.1 $
8 Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
28 #include "vvToolWidgetBase.h"
29 #include "vvMainWindowBase.h"
30 #include "vvSlicerManager.h"
32 //------------------------------------------------------------------------------
33 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f)
35 Ui::vvToolWidgetBase() {
37 // Set Modality : dialog is not modal but stay always on top because
38 // parent is set at construction
39 mIsInitialized = false;
41 mMainWindowBase = parent;
43 setAttribute(Qt::WA_DeleteOnClose);
48 // Connect signals & slots
49 connect(mMainWindowBase, SIGNAL(AnImageIsBeingClosed(vvSlicerManager*)),
50 this, SLOT(AnImageIsBeingClosed(vvSlicerManager*)));
51 connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected()));
52 connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close()));
53 connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply()));
54 connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
56 // Disable main widget while input image is not selected
57 mToolWidget->setEnabled(false);
59 //------------------------------------------------------------------------------
62 //------------------------------------------------------------------------------
63 vvToolWidgetBase::~vvToolWidgetBase() {
66 //------------------------------------------------------------------------------
69 //------------------------------------------------------------------------------
70 void vvToolWidgetBase::show() {
71 if (!mIsInitialized) {
76 //------------------------------------------------------------------------------
79 //------------------------------------------------------------------------------
80 bool vvToolWidgetBase::close() {
81 return QDialog::close();
83 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87 void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m) {
88 if (m == mCurrentSlicerManager) {
92 //------------------------------------------------------------------------------
95 //------------------------------------------------------------------------------
96 void vvToolWidgetBase::InitializeInputs() {
99 mToolInputSelectionWidget->SetToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
100 for(unsigned int i=0; i<mMainWindowBase->GetSlicerManagers().size(); i++) {
101 vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage();
102 if (mFilter->CheckImageType(s->GetNumberOfDimensions(),
103 s->GetNumberOfScalarComponents(),
104 s->GetScalarTypeAsString())) {
105 mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]);
106 if ((int)i == mMainWindowBase->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
112 mSlicerManagersCompatible = mMainWindowBase->GetSlicerManagers();
113 mCurrentCompatibleIndex = mMainWindowBase->GetSlicerManagerCurrentIndex();
115 mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible,
116 mCurrentCompatibleIndex);
117 mIsInitialized = true;
119 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 void vvToolWidgetBase::InputIsSelected() {
125 int index = mToolInputSelectionWidget->GetSelectedInputIndex();
126 mCurrentSlicerManager = mSlicerManagersCompatible[index];
127 mToolWidget->setEnabled(true);
128 if (!mCurrentSlicerManager) close();
129 InputIsSelected(mCurrentSlicerManager);
131 //------------------------------------------------------------------------------