]> Creatis software - bbtk.git/blob - packages/qt/src/bbqtQSlider.cxx
*** empty log message ***
[bbtk.git] / packages / qt / src / bbqtQSlider.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbqtQSlider.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/04/08 07:56:33 $
6   Version:   $Revision: 1.1 $
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 "bbqtQSlider.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::bbUserConstructor() 
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   void Slider::Process() 
77   {
78     bbtkDebugMessage("process",3,
79                      "Slider "<<bbGetName()<<" input="
80                      <<bbGetInputIn()<<std::endl);
81    
82     bbSetOutputOut( bbGetInputIn() );
83     if (bbGetOutputWidget()!=0)
84       {
85         ((QSlider*)bbGetOutputWidget())->setValue(bbGetInputIn());
86       }
87   }
88   //--------------------------------------------------------------------------
89
90   //--------------------------------------------------------------------------
91   void Slider::CreateWidget(QWidget* parent)
92   {
93
94      Qt::Orientation orientation;
95     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|HORIZONTAL")
96         ==true)  
97       { orientation = Qt::Horizontal; }
98     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")
99         ==true)    
100       { orientation = Qt::Vertical ; }
101     
102     
103     //    std::cout << "bbGetQtParent = "<<bbGetQtParent()<<std::endl;
104     QSlider *w =  new QSlider(parent);
105     w->setOrientation(orientation);
106     w->setMinimum( bbGetInputMin() );
107     w->setMaximum( bbGetInputMax() );
108     w->setSliderPosition ( bbGetInputIn() );
109     
110     if (bbGetInputReactiveOnTrack()) 
111       w->setTracking(true);
112     else 
113       w->setTracking(false);
114
115     connect(w,SIGNAL(valueChanged(int)),this,SLOT(OnValueChanged(int)));
116
117
118     bbSetOutputWidget( w );
119   }
120   //--------------------------------------------------------------------------
121
122   //--------------------------------------------------------------------------
123   void Slider::OnValueChanged(int v)
124   {
125     //   std::cout << "OnValueChanged "<<v<<std::endl;
126     bbSetOutputOut( v ); 
127     bbSetInputIn( v );
128     // and signal that the output has changed
129     bbSignalOutputModification(std::string("Out"));
130
131   }
132   //--------------------------------------------------------------------------
133
134
135 } //namespace bbqt
136
137 #endif // USE_QT
138
139