cmtkQtScrollRenderView.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2363 $
00026 //
00027 //  $LastChangedDate: 2010-09-27 11:11:35 -0700 (Mon, 27 Sep 2010) $
00028 //
00029 //  $LastChangedBy: torsten_at_home $
00030 //
00031 */
00032 
00033 #include "cmtkQtScrollRenderView.h"
00034 
00035 #include <qlabel.h>
00036 #include <QFrame>
00037 #include <QGridLayout>
00038 #include <QVBoxLayout>
00039 
00040 namespace
00041 cmtk
00042 {
00043 
00046 
00047 QtScrollRenderView::QtScrollRenderView
00048 ( QWidget *parentWidget, const QString& title )
00049   : QGroupBox( parentWidget ),
00050     RenderImage( NULL )
00051 {
00052   if ( ! parentWidget )
00053     qFatal( "No parent widget in QtScrollRenderView constructor." );
00054 
00055   if ( title != QString::null ) 
00056     {
00057     this->setAlignment ( Qt::AlignLeft );
00058     this->setTitle( title );
00059     } 
00060   
00061   ScrollView = new QScrollArea( this ); //, "ScrollView", Qt::WResizeNoErase|Qt::WStaticContents  );
00062   RenderImage = new QtRenderImageRGB( this );
00063   ScrollView->setWidget( RenderImage );
00064   ScrollView->setFrameStyle( QFrame::NoFrame );
00065 
00066   // export viewer's mouse signal
00067   QObject::connect( RenderImage,SIGNAL(signalMousePressed( Qt::MouseButton, int, int )), SIGNAL(signalMousePressed( Qt::MouseButton, int, int )) );
00068   QObject::connect( RenderImage, SIGNAL(signalMouse3D( Qt::MouseButton, const Vector3D& )), SIGNAL(signalMouse3D( Qt::MouseButton, const Vector3D& )) );
00069   
00070   // lock minimum size so we can display 256x256 with not scrollbars.
00071   RenderImage->setMinimumSize( 256, 256 );
00072 
00073   this->m_SliderGroupBox = new QGroupBox( this );
00074   this->m_SliderGroupBox->hide();
00075 
00076   QGridLayout* sliderBoxLayout = new QGridLayout( this->m_SliderGroupBox );
00077   sliderBoxLayout->setContentsMargins( 0,0,0,0 );
00078   
00079   this->ImageIndexSlider = new QSlider( this->m_SliderGroupBox  );
00080   this->ImageIndexSlider->setOrientation( Qt::Horizontal );
00081   this->ImageIndexSlider->setDisabled( true );
00082   sliderBoxLayout->addWidget( this->ImageIndexSlider, 0, 1 );
00083 
00084   this->m_LabelL = new QLabel( this->m_SliderGroupBox );
00085   sliderBoxLayout->addWidget( this->m_LabelL, 0, 0 );
00086   this->m_LabelR = new QLabel( this->m_SliderGroupBox );
00087   sliderBoxLayout->addWidget( this->m_LabelR, 0, 2 );
00088 
00089   QVBoxLayout *vbox = new QVBoxLayout;  
00090   vbox->setContentsMargins( 0,0,0,0 );
00091   vbox->addWidget( this->ScrollView );
00092   vbox->addWidget( this->m_SliderGroupBox );
00093   vbox->setSpacing( 0 );
00094   this->setLayout(vbox);
00095 
00096   // export slider's signal
00097   QObject::connect( ImageIndexSlider, SIGNAL( valueChanged( int ) ), SIGNAL( indexChanged( int ) ) );
00098 }
00099 
00100 QtScrollRenderView::~QtScrollRenderView()
00101 {
00102 }
00103 
00104 void QtScrollRenderView::slotConnectImage( ImageRGB *const image )
00105 {
00106   if ( RenderImage ) 
00107     {
00108     RenderImage->SetInput( image );
00109     } 
00110   else 
00111     {
00112     qWarning( "RenderImage is NULL in QtScrollRenderView::ConnectRenderView." );
00113     }
00114 }
00115 
00116 void QtScrollRenderView::slotRender()
00117 {
00118   if ( RenderImage ) 
00119     {
00120     RenderImage->Render();
00121     } 
00122   else
00123     {
00124     qWarning( "RenderImage is NULL in QtScrollRenderView::Render." );
00125     }
00126 }
00127 
00128 void QtScrollRenderView::slotSetNumberOfSlices( unsigned int nSlices )
00129 {
00130   if ( nSlices ) 
00131     {
00132     ImageIndexSlider->setEnabled( true );
00133     ImageIndexSlider->setMinimum( 0 );
00134     ImageIndexSlider->setMaximum( nSlices - 1 );
00135 
00136     if ( ImageIndexSlider->value() < 0 || ImageIndexSlider->value() >= (int)nSlices )
00137       {
00138       ImageIndexSlider->setValue( nSlices / 2 );
00139       }
00140     this->ImageIndexSlider->setDisabled( false );
00141     } 
00142   else
00143     {
00144     ImageIndexSlider->setDisabled( true );
00145     }
00146 }
00147 
00148 void QtScrollRenderView::slotSetSlice( unsigned int slice )
00149 {
00150   if ( slice <= static_cast<unsigned>(ImageIndexSlider->maximum()) ) 
00151     {
00152     ImageIndexSlider->setValue( slice );
00153     }
00154 }
00155 
00156 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines