fw4spl
SliceSelector.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGuiQt/SliceSelector.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <boost/lambda/lambda.hpp>
12 
13 #include <QComboBox>
14 #include <QHBoxLayout>
15 #include <QLineEdit>
16 #include <QSlider>
17 #include <QStringList>
18 
19 #include <functional>
20 
21 namespace fwGuiQt
22 {
23 
24 //------------------------------------------------------------------------------
25 
26 SliceSelector::SliceSelector(QWidget* const parent ) noexcept :
27  QWidget( parent )
28 {
29  m_fctChangeIndexCallback = std::bind( &::fwGuiQt::SliceSelector::printIndex, this, std::placeholders:: _1);
30  m_fctChangeTypeCallback = std::bind( &::fwGuiQt::SliceSelector::printType, this, std::placeholders:: _1);
31 
32  m_sliceType = new QComboBox( this );
34  QStringList sliceTypesArray;
35  sliceTypesArray << tr("Sagittal") << tr("Frontal") << tr("Axial");
36  m_sliceType->addItems(sliceTypesArray);
37 
38  m_sliceIndex = new QSlider(Qt::Horizontal, this);
39 
40  m_pSliceIndexText = new QLineEdit(this);
41  m_pSliceIndexText->setReadOnly(true);
42  m_pSliceIndexText->setMaximumWidth(80);
43 
44  QHBoxLayout* layout = new QHBoxLayout(this);
45  layout->addWidget(m_sliceType, 0);
46  layout->addWidget(m_sliceIndex, 1);
47  layout->addWidget(m_pSliceIndexText, 0);
48  layout->setContentsMargins(0, 0, 0, 0);
49 
50  QObject::connect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
51  QObject::connect(m_sliceType, SIGNAL(currentIndexChanged(int)), this, SLOT(onSliceTypeChange(int)));
52 
53  this->setLayout( layout );
54 }
55 
56 //------------------------------------------------------------------------------
57 
59 {
60  QObject::disconnect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
61  QObject::disconnect(m_sliceType, SIGNAL(currentIndexChanged(int)), this, SLOT(onSliceTypeChange(int)));
62 }
63 
64 //------------------------------------------------------------------------------
65 
66 void SliceSelector::setSliceRange( int min, int max )
67 {
68  QObject::disconnect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
69  this->m_sliceIndex->setRange(min, max);
70  QObject::connect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
71 }
72 
73 //------------------------------------------------------------------------------
74 
75 void SliceSelector::setSliceValue( int index )
76 {
77  QObject::disconnect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
78  this->m_sliceIndex->setValue(index);
79  QObject::connect(m_sliceIndex, SIGNAL(valueChanged(int)), this, SLOT(onSliceIndexChange(int)));
80 
81  std::stringstream ss;
82  ss << index << " / " << this->m_sliceIndex->maximum();
83  this->m_pSliceIndexText->setText( QString::fromStdString(ss.str()));
84 }
85 
86 //------------------------------------------------------------------------------
87 
88 void SliceSelector::setTypeSelection( int type )
89 {
90  this->m_sliceType->setCurrentIndex(type);
91 }
92 
93 //------------------------------------------------------------------------------
94 
95 void SliceSelector::onSliceIndexChange( int value ) noexcept
96 {
98  m_fctChangeIndexCallback( value );
99  this->setSliceValue( value );
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 void SliceSelector::setChangeIndexCallback(ChangeIndexCallback fct)
105 {
106  m_fctChangeIndexCallback = fct;
107 }
108 
109 //------------------------------------------------------------------------------
110 
111 void SliceSelector::setChangeTypeCallback(ChangeTypeCallback fct)
112 {
113  m_fctChangeTypeCallback = fct;
114 }
115 
116 //------------------------------------------------------------------------------
117 
118 void SliceSelector::printIndex(int index)
119 {
120  OSLM_TRACE("index= "<<index);
121 }
122 
123 //------------------------------------------------------------------------------
124 
125 void SliceSelector::printType(int type)
126 {
127  OSLM_TRACE("type= "<<type);
128 }
129 
130 //------------------------------------------------------------------------------
131 
132 void SliceSelector::setEnable(bool enable)
133 {
134  m_sliceType->setEnabled(enable);
135  m_sliceIndex->setEnabled(enable);
136  m_pSliceIndexText->setEnabled(enable);
137 }
138 
139 //------------------------------------------------------------------------------
141 {
142  m_fctChangeTypeCallback(index);
143  this->setSliceValue( this->m_sliceIndex->value());
144 }
145 
146 //------------------------------------------------------------------------------
147 
148 } // fwGuiQt
149 
FWGUIQT_API void onSliceIndexChange(int value) noexcept
Event handler for a slice index change.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual FWGUIQT_API ~SliceSelector() noexcept
Destructor.
#define OSLM_TRACE(message)
Definition: spyLog.hpp:230
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
Definition: WindowLevel.hpp:32
FWGUIQT_API void onSliceTypeChange(int index)
Event handler for a slice type change.
FWGUIQT_API SliceSelector(QWidget *const parent=nullptr) noexcept
Constructor.