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