]> Creatis software - bbtk.git/blob - packages/qt/src/bbqtSlider.cxx
913697d915024bc69f1fe6eace763d152fd05256
[bbtk.git] / packages / qt / src / bbqtSlider.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbqtSlider.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/14 16:21:19 $
6   Version:   $Revision: 1.2 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  * \file 
33  * \brief Short description in one line
34  *
35  * Long 
36  * description
37  *  
38  */
39
40 #ifdef USE_QT
41
42 #include "bbqtSlider.h"
43 #include "bbqtPackage.h"
44 #include "bbtkUtilities.h"
45
46 namespace bbqt
47 {
48
49  
50
51   //--------------------------------------------------------------------------
52   //-------------------------------------------------------------------------
53   // QtBlackBox implementation
54   //--------------------------------------------------------------------------
55   //--------------------------------------------------------------------------
56
57   //--------------------------------------------------------------------------
58   BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::QtBlackBox);
59   BBTK_ADD_BLACK_BOX_TO_PACKAGE(qt,Slider);
60   
61   //--------------------------------------------------------------------------
62   void Slider::bbUserSetDefaultValues() 
63   { 
64     bbSetInputIn(0);
65     bbSetInputMin(0);
66     bbSetInputMax(500);
67     bbSetOutputOut(0);
68     bbSetInputOrientation("HORIZONTAL");
69     bbSetInputChangeResolution(false);
70     bbSetInputLabel(true);
71     bbSetInputReactiveOnTrack(false);    
72   }
73   //--------------------------------------------------------------------------
74   
75         
76         //--------------------------------------------------------------------------
77         void Slider::bbUserInitializeProcessing()
78         {
79         }
80         //--------------------------------------------------------------------------
81
82         
83         //--------------------------------------------------------------------------
84         void Slider::bbUserFinalizeProcessing()
85         {
86         }
87         //--------------------------------------------------------------------------
88         
89         
90         
91   //--------------------------------------------------------------------------
92   void Slider::Process() 
93   {
94     bbtkDebugMessage("process",3,
95                      "Slider "<<bbGetName()<<" input="
96                      <<bbGetInputIn()<<std::endl);
97    
98     bbSetOutputOut( bbGetInputIn() );
99     if (bbGetOutputWidget()!=0)
100       {
101         ((QSlider*)bbGetOutputWidget())->setValue(bbGetInputIn());
102       }
103   }
104   //--------------------------------------------------------------------------
105
106   //--------------------------------------------------------------------------
107   void Slider::CreateWidget(QWidget* parent)
108   {
109
110      Qt::Orientation orientation;
111     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|HORIZONTAL")
112         ==true)  
113       { orientation = Qt::Horizontal; }
114     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")
115         ==true)    
116       { orientation = Qt::Vertical ; }
117     
118     
119     //    std::cout << "bbGetQtParent = "<<bbGetQtParent()<<std::endl;
120     QSlider *w =  new QSlider(parent);
121     w->setOrientation(orientation);
122     w->setMinimum( bbGetInputMin() );
123     w->setMaximum( bbGetInputMax() );
124     w->setSliderPosition ( bbGetInputIn() );
125     
126     if (bbGetInputReactiveOnTrack()) 
127       w->setTracking(true);
128     else 
129       w->setTracking(false);
130
131     connect(w,SIGNAL(valueChanged(int)),this,SLOT(OnValueChanged(int)));
132
133
134     bbSetOutputWidget( w );
135   }
136   //--------------------------------------------------------------------------
137
138   //--------------------------------------------------------------------------
139   void Slider::OnValueChanged(int v)
140   {
141     //   std::cout << "OnValueChanged "<<v<<std::endl;
142     bbSetOutputOut( v ); 
143     bbSetInputIn( v );
144     // and signal that the output has changed
145     bbSignalOutputModification(std::string("Out"));
146
147   }
148   //--------------------------------------------------------------------------
149
150
151 } //namespace bbqt
152
153 #endif // USE_QT
154
155