void CAlgorithmWidget::SetMode(AlgorithmModes mode)
{

    switch (mode) {
    case AlgorithmModes::individualWork:
        showWidgets(QList<QWidget*>() << ui->checkButton <<  ui->showButton);
        showSpacer(ui->checkSpacer);
        hideWidgets(QList<QWidget*>()
                    << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label << ui->beginButton << ui->endButton
                    << ui->prew_stepButton << ui->next_stepButton );
        hideSpacer(ui->stepSpacer);
        break;
    case AlgorithmModes::algorithmSteping:
        showWidgets(QList<QWidget*>() << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label << ui->beginButton << ui->endButton);
        hideWidgets(QList<QWidget*>()
                    << ui->checkButton <<  ui->showButton
                    << ui->prew_stepButton << ui->next_stepButton );
        hideSpacer(ui->stepSpacer);
        hideSpacer(ui->checkSpacer);
        break;
    case AlgorithmModes::instantChecking:
        showWidgets(QList<QWidget*>()<< ui->prew_stepButton << ui->next_stepButton);
        hideWidgets(QList<QWidget*>()
                    << ui->checkButton <<  ui->showButton
                    << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label << ui->beginButton << ui->endButton);
        showSpacer(ui->stepSpacer);
        hideSpacer(ui->checkSpacer);
        break;
    default:
        break;
    }
    hideWidgets(QList<QWidget*>()  << ui->prew_stepButton << ui->next_stepButton);
}
void WidgetToggle::updateWidgets()
{
	// Show/hide the widgets according to the _toggled state
	if (_toggled)
	{
		showWidgets();
	}
	else
	{
		hideWidgets();
	}

	// Pass the call to the base class to do the rest
	Toggle::updateWidgets();
}
bool
RemapWidget::setFile(QList<QString> flnm,
		     int voltype)
{  
  m_timeseriesFiles.clear();
  Global::statusBar()->clearMessage();

  hideWidgets();

  if (m_histogramWidget)
    delete m_histogramWidget;

  if (m_imageWidget)
    delete m_imageWidget;

  if (m_remapVolume)
    delete m_remapVolume;
  
  if (m_gradientWidget)
    delete m_gradientWidget;

  if (m_slider)
    delete m_slider;

  m_histogramWidget = 0;
  m_imageWidget = 0;
  m_gradientWidget = 0;
  m_remapVolume = 0;
  m_slider = 0;

  m_volumeType = voltype;
  m_volumeFile = flnm;

  if (m_volumeType == RAWVolume)
    m_remapVolume = new RemapRawVolume();
  else if (m_volumeType == TOMVolume)
    m_remapVolume = new RemapTomVolume();
  else if (m_volumeType == AnalyzeVolume)
    m_remapVolume = new RemapAnalyze();
  else if (m_volumeType == HDF4Volume)
    m_remapVolume = new RemapHDF4();
  else if (m_volumeType == RawSlices)
    m_remapVolume = new RemapRawSlices();
  else if (m_volumeType == RawSlabs)
    m_remapVolume = new RemapRawSlabs();
  else if (m_volumeType == NCVolume)
    m_remapVolume = new RemapNcVolume();
  else if (m_volumeType == ImageVolume)
    m_remapVolume = new RemapImageVolume();
  else if (m_volumeType == ImageMagickVolume)
    m_remapVolume = new RemapDicomVolume();

  if (! m_remapVolume->setFile(m_volumeFile))
    return false;

  m_histogramWidget = new RemapHistogramWidget();
  m_histogramWidget->setMinimumSize(100, 300);
  m_histogramWidget->setSizePolicy(QSizePolicy::Expanding,
				   QSizePolicy::Fixed);

  m_gradientWidget = new GradientEditorWidget();
  m_gradientWidget->setDrawBox(false);
  m_gradientWidget->setMinimumSize(200, 20);
  m_gradientWidget->setGeneralLock(GradientEditor::LockToTop);
  
  int d, w, h;
  m_remapVolume->gridSize(d, w, h);

  m_slider = new MySlider();
  m_slider->set(0, d-1, 0, d-1, 0);
  
  ui.histogramFrame->layout()->addWidget(m_histogramWidget);
  ui.colorFrame->layout()->addWidget(m_gradientWidget);
  ui.sliderFrame->layout()->addWidget(m_slider);

  m_imageWidget = new RemapImage();
  m_imageWidget->setGridSize(d, w, h);
  m_scrollArea->setWidget(m_imageWidget);

  m_currSlice = 0;

  connect(m_histogramWidget, SIGNAL(getHistogram()),
	  this, SLOT(getHistogram()));  

  connect(m_histogramWidget, SIGNAL(newMapping()),
	  this, SLOT(newMapping()));  

  connect(m_histogramWidget, SIGNAL(newMinMax(float, float)),
	  this, SLOT(newMinMax(float, float)));

  connect(m_imageWidget, SIGNAL(getSlice(int)),
	  this, SLOT(getSlice(int)));  

  connect(m_imageWidget, SIGNAL(getRawValue(int, int, int)),
	  this, SLOT(getRawValue(int, int, int)));

  connect(m_imageWidget, SIGNAL(newMinMax(float, float)),
	  this, SLOT(newMinMax(float, float)));

  connect(m_imageWidget, SIGNAL(saveTrimmed(int, int, int,
					    int, int, int)),
	  this, SLOT(saveTrimmed(int, int, int,
				 int, int, int)));
  
  connect(m_imageWidget, SIGNAL(saveTrimmedImages(int, int, int,
						  int, int, int)),
	  this, SLOT(saveTrimmedImages(int, int, int,
				       int, int, int)));
  
  connect(m_imageWidget, SIGNAL(extractRawVolume()),
	  this, SLOT(extractRawVolume()));
  
  connect(m_gradientWidget, SIGNAL(gradientChanged(QGradientStops)),
	  m_imageWidget, SLOT(setGradientStops(QGradientStops)));

  connect(m_gradientWidget, SIGNAL(gradientChanged(QGradientStops)),
	  m_histogramWidget, SLOT(setGradientStops(QGradientStops)));


  connect(m_slider, SIGNAL(valueChanged(int)),
	  m_imageWidget, SLOT(sliceChanged(int)));

  connect(m_slider, SIGNAL(userRangeChanged(int, int)),
	  m_imageWidget, SLOT(userRangeChanged(int, int)));


  QGradientStops stops;
  stops << QGradientStop(0, Qt::black)
	<< QGradientStop(1, Qt::white);
  m_gradientWidget->setColorGradient(stops);
  m_imageWidget->setGradientStops(stops);
  m_histogramWidget->setGradientStops(stops);

  setRawMinMax();
  
  showWidgets();

  return true;
}