Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
controlswidget.cpp
Go to the documentation of this file.
1 #include "controller.h"
2 #include "controlswidget.h"
3 #include "imageviewer.h"
4 #include "ui_controlswidget.h"
5 #include <QTimer>
6 
7 ControlsWidget::ControlsWidget( QWidget *parent ) : QWidget( parent ), ui( new Ui::ControlsWidget ) {
8  ui->setupUi( this );
9 
10  timer = new QTimer( this );
11  timer->setInterval( 1000 / ui->spinBoxSpeed->value( ) );
12  controller = nullptr;
13  ui->pushButton4Views->hide( );
14  ui->pushButton_3RGB->hide( );
15  /* ui->groupBoxEditor->hide( ); */
16 
17  ui->horizontalSliderZoom->setEnabled( false );
18  ui->horizontalSliderBrightness->setEnabled( false );
19  ui->horizontalSliderContrast->setEnabled( false );
20 
21  /*
22  * ui->horizontalSliderZoom->setEnabled(false);
23  * ui->horizontalSliderBrightness->setEnabled(false);
24  * ui->horizontalSliderContrast->setEnabled(false);
25  */
26 
27  /*
28  * ui->labelBrightness->setVisible(false);
29  * ui->labelContrast->setVisible(false);
30  * ui->labelZoom->setVisible(false);
31  */
32 }
33 
35  delete ui;
36 }
37 
39  controller = value;
40  connect( controller, &Controller::currentImageChanged, this, &ControlsWidget::imageChanged );
41  connect( controller, &Controller::imageUpdated, this, &ControlsWidget::imageUpdated );
42  connect( controller, &Controller::containerUpdated, this, &ControlsWidget::updateRange );
43  connect( ui->folderHorizontalSlider, &QAbstractSlider::valueChanged, controller, &Controller::setCurrentImagePos );
44  connect( ui->folderSpinBox, SIGNAL(valueChanged(int)), controller, SLOT(setCurrentImagePos(int)) );
45  connect( timer, &QTimer::timeout, controller, &Controller::loadNextImage );
46  updateRange( );
47 }
48 
49 void ControlsWidget::imageChanged( ) {
50  GuiImage *img = controller->currentImage( );
51  if( img == nullptr ) {
52  return;
53  }
54  ui->pushButtonHistogramNormalization->setChecked( img->getEqualizeHistogram( ) );
55  ui->folderHorizontalSlider->setValue( controller->currentImagePos( ) );
56  ui->folderSpinBox->setValue( controller->currentImagePos( ) );
57  DisplayFormat *format = controller->currentFormat( );
58  ui->pushButton1View->setChecked( format->getNumberOfViews( ) == 1 );
59  ui->pushButton3Views->setChecked( format->getNumberOfViews( ) == 3 );
60  ui->pushButton4Views->setChecked( format->getNumberOfViews( ) == 4 );
61  ui->pushButton_1RGB->setChecked( format->getNumberOfViews( ) == 1 );
62  ui->pushButton_3RGB->setChecked( format->getNumberOfViews( ) == 3 );
63  ui->pushButton_4RGB->setChecked( format->getNumberOfViews( ) == 4 );
64  switch( format->currentLayout( ) ) {
65  case Layout::GRID:
66  ui->pushButtonGrid->setChecked( true );
67  break;
68  case Layout::HORIZONTAL:
69  ui->pushButtonHorizontal->setChecked( true );
70  break;
71  case Layout::VERTICAL:
72  ui->pushButtonVertical->setChecked( true );
73  break;
74  }
75  switch( format->currentViews( ) ) {
76  case Views::SHOW0:
77  ui->pushButton1View->setChecked( true );
78  ui->pushButtonAxial->setChecked( true );
79  ui->pushButton_RGB->setChecked( true );
80  break;
81  case Views::SHOW1:
82  ui->pushButton1View->setChecked( true );
83  ui->pushButtonCoronal->setChecked( true );
84  ui->pushButton_R->setChecked( true );
85  break;
86  case Views::SHOW2:
87  ui->pushButton1View->setChecked( true );
88  ui->pushButtonSagittal->setChecked( true );
89  ui->pushButton_G->setChecked( true );
90  break;
91  case Views::SHOW3:
92  ui->pushButton1View->setChecked( true );
93  ui->pushButton_B->setChecked( true );
94  break;
95  case Views::SHOW012:
96  ui->pushButton3Views->setChecked( true );
97  break;
98  case Views::SHOW123:
99  ui->pushButton3Views->setChecked( true );
100  break;
101  case Views::SHOW0123:
102  ui->pushButton4Views->setChecked( true );
103  break;
104  }
105  ui->groupBoxNiftiViews->setVisible( format->showNiftiViews( ) );
106  ui->groupBoxNiftiAxis->setVisible( format->showNiftiAxis( ) );
107  ui->groupBoxOrientation->setVisible( format->showOrientation( ) );
108  ui->groupBoxPpmViews->setVisible( format->showPpmViews( ) );
109  ui->groupBoxPpmChannels->setVisible( format->showPpmChannels( ) );
110  ui->rotate->setVisible( format->rotateSingle( ) );
111  ui->groupBoxLabels->setVisible( false );
112 
113  /* TODO Continue ... */
114 }
115 
116 void ControlsWidget::imageUpdated( ) {
117 }
118 
119 void ControlsWidget::updateRange( ) {
120  size_t images = controller->size( );
121  if( images >= 1 ) {
122  ui->folderSpinBox->setMaximum( images );
123  ui->folderHorizontalSlider->setMaximum( images - 1 );
124  ui->folderHorizontalSlider->setMinimum( 0 );
125  }
126  else if( images == 0 ) {
127  ui->folderSpinBox->setMaximum( 0 );
128  ui->folderHorizontalSlider->setMaximum( 0 );
129  ui->folderHorizontalSlider->setMinimum( 0 );
130  }
131  ui->folderSpinBox->setEnabled( images > 1 );
132  ui->folderHorizontalSlider->setEnabled( images > 1 );
133  ui->groupBoxFolderControls->setVisible( images > 1 );
134  setVisible( images > 0 );
135 }
136 
137 void ControlsWidget::on_spinBoxSpeed_valueChanged( int value ) {
138  timer->setInterval( 1000 / value );
139 }
140 
141 void ControlsWidget::on_buttonPlay_clicked( bool checked ) {
142  if( checked ) {
143  timer->start( );
144  }
145  else {
146  timer->stop( );
147  }
148 }
149 
150 void ControlsWidget::on_pushButton1View_clicked( ) {
151  controller->currentFormat( )->setNumberOfViews( 1 );
152 }
153 
154 void ControlsWidget::on_pushButton3Views_clicked( ) {
155  controller->currentFormat( )->setNumberOfViews( 3 );
156 }
157 
158 void ControlsWidget::on_pushButton4Views_clicked( ) {
159  controller->currentFormat( )->setNumberOfViews( 4 );
160 }
161 
162 void ControlsWidget::on_pushButton_1RGB_clicked( ) {
163  controller->currentFormat( )->setNumberOfViews( 1 );
164 }
165 
166 void ControlsWidget::on_pushButton_3RGB_clicked( ) {
167  controller->currentFormat( )->setNumberOfViews( 3 );
168 }
169 
170 void ControlsWidget::on_pushButton_4RGB_clicked( ) {
171  controller->currentFormat( )->setNumberOfViews( 4 );
172 }
173 
174 void ControlsWidget::on_pushButtonGrid_clicked( ) {
175  controller->currentFormat( )->setCurrentLayout( Layout::GRID );
176 }
177 
178 void ControlsWidget::on_pushButtonHorizontal_clicked( ) {
180 }
181 
182 void ControlsWidget::on_pushButtonVertical_clicked( ) {
184 }
185 
186 void ControlsWidget::on_pushButtonAxial_clicked( ) {
187  controller->currentFormat( )->setCurrentViews( Views::SHOW0 );
188 }
189 
190 void ControlsWidget::on_pushButtonCoronal_clicked( ) {
191  controller->currentFormat( )->setCurrentViews( Views::SHOW1 );
192 }
193 
194 void ControlsWidget::on_pushButtonSagittal_clicked( ) {
195  controller->currentFormat( )->setCurrentViews( Views::SHOW2 );
196 }
197 
198 void ControlsWidget::on_pushButton_RGB_clicked( ) {
199  controller->currentFormat( )->setCurrentViews( Views::SHOW0 );
200 }
201 
202 void ControlsWidget::on_pushButton_R_clicked( ) {
203  controller->currentFormat( )->setCurrentViews( Views::SHOW1 );
204 }
205 
206 void ControlsWidget::on_pushButton_G_clicked( ) {
207  controller->currentFormat( )->setCurrentViews( Views::SHOW2 );
208 }
209 
210 void ControlsWidget::on_pushButton_B_clicked( ) {
211  controller->currentFormat( )->setCurrentViews( Views::SHOW3 );
212 }
213 
214 void ControlsWidget::on_pushButtonInterpolation_clicked( ) {
215  COMMENT( "Toggled interpolation button.", 1 );
216  controller->setInterpolation( ui->pushButtonInterpolation->isChecked( ) );
217 }
218 
219 void ControlsWidget::on_rotate_clicked( ) {
220  controller->rotateAll90( );
221 }
222 
223 void ControlsWidget::on_pushButtonHistogramNormalization_clicked( ) {
224  if( controller->currentImage( ) ) {
225  controller->currentImage( )->setEqualizeHistogram( ui->pushButtonHistogramNormalization->isChecked( ) );
226  }
227 }
228 
229 void ControlsWidget::on_pushButtonFitInView_clicked( ) {
230  emit controller->currentImageChanged( );
231 }
void setCurrentImagePos(int position)
setCurrentImagePos
Definition: controller.cpp:144
virtual void setCurrentViews(const Views &currentViews)
ControlsWidget(QWidget *parent=0)
DisplayFormat * currentFormat()
currentFormat returns the modality of current image.
Definition: controller.cpp:230
The GuiImage class is a bridge to the Bial::Image data structure to the QImage data structure...
Definition: guiimage.h:20
bool getEqualizeHistogram() const
getEqualizeHistogram returns a boolean value that says if the image must be equalized or not...
Definition: guiimage.cpp:451
virtual void setNumberOfViews(int numberOfViews)=0
void setInterpolation(bool isSmooth)
setInterpolation switches between smoot and fast interpolation.
Definition: controller.cpp:175
bool showNiftiAxis() const
int getNumberOfViews() const
bool showPpmViews() const
bool showNiftiViews() const
bool showOrientation() const
The Controller class is one of the most important classes of the User Interface, and is responsible t...
Definition: controller.h:17
void rotateAll90()
rotateAll90 rotates all views in 90 degrees.
Definition: controller.cpp:186
int size()
size
Definition: controller.cpp:114
bool rotateSingle() const
void loadNextImage()
loadNextImage is a slot called from controlsdock that loads the next image ( like an circular list )...
Definition: controller.cpp:156
void setController(Controller *value)
GuiImage * currentImage()
currentImage
Definition: controller.cpp:24
int currentImagePos() const
currentImagePos
Definition: controller.cpp:35
void currentImageChanged()
This signal is emmited every time the current image changes.
bool showPpmChannels() const
Layout currentLayout() const
Views currentViews() const
void setEqualizeHistogram(bool equalizeHistogram)
setEqualizeHistogram updates a boolean value that says if the image must be equalized or not...
Definition: guiimage.cpp:455
void containerUpdated()
This signal is emmited avery time the m_images vector is updated.
void imageUpdated()
This signal is emmited every time the current image is updated.
virtual void setCurrentLayout(const Layout &currentLayout)