CMS 3D CMS Logo

IgQtRangeControlImp.h

Go to the documentation of this file.
00001 #ifndef IGUANA_GL_BROWSERS_IG_QT_RANGE_CONTROL_IMP_H
00002 # define IGUANA_GL_BROWSERS_IG_QT_RANGE_CONTROL_IMP_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "Iguana/GLBrowsers/interface/IgQtRangeControl.h"
00007 # include "Iguana/GLBrowsers/interface/IgQtRangeValue.h"
00008 # include "Iguana/GLBrowsers/interface/IgQtRangeSetting.h"
00009 # include "Iguana/Studio/interface/IgQtLineEdit.h"
00010 # include <qslider.h>
00011 
00012 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00013 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00014 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00015 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00016 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00017 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00018 
00019 template <class T>
00020 class IGUANA_GL_BROWSERS_API IgQtRangeControlImp : public IgQtRangeControl, public IgQtRangeValue<T>
00021 {
00022 public:
00023     typedef IgQtRangeControlImp<T> inherited;
00024 
00025     IgQtRangeControlImp (QWidget *parent, int parts, T value = 0,
00026                          const char *name = 0);
00027     // implicit copy constructor
00028     // implicit assignment operator
00029     // implicit destructor
00030 
00031     virtual T           stringToNumber (const QString& /*val*/) const
00032     { return (T)(0); }
00033     
00034     using IgQtRangeControl::setDirty;
00035     T                   getSmallStep (void) const
00036     { return m_smallStep; }
00037     
00038     T                   getLongStep (void) const
00039     { return m_longStep; }
00040 
00041     void                setSmallStep (T size)
00042     {
00043       m_smallStep = size;
00044       if (m_longStep < m_smallStep)
00045           m_longStep = m_smallStep;
00046       adjustSliderSteps ();
00047       editSettingsChanged ();
00048     }
00049     
00050     void                setLongStep (T size)
00051     {
00052       m_longStep = size;
00053       if (m_smallStep > m_longStep)
00054         m_smallStep = m_longStep;
00055       adjustSliderSteps ();
00056       editSettingsChanged ();
00057     }
00058 
00059     void                setRange (T min, T max)
00060     {
00061       // Like base class, just adjust the number of slider steps.
00062       IgQtRangeValue<T>::setRange (min, max);
00063       adjustSliderSteps ();
00064       editSettingsChanged ();
00065     }
00066 
00067     virtual void        setValue (T newval);
00068 
00069     void                revMin (void)
00070     { setValue (inherited::minValue ()); }
00071 
00072     void                revLong (void)
00073     { moveValue (m_longStep,  MoveREV); }
00074 
00075     void                revSmall (void)
00076     { moveValue (m_smallStep, MoveREV); }
00077 
00078     void                fwdSmall (void)
00079     { moveValue (m_smallStep, MoveFWD); }
00080 
00081     void                fwdLong (void)
00082     { moveValue (m_longStep,  MoveFWD); }
00083 
00084     void                fwdMax (void)
00085     { setValue (inherited::maxValue ()); }
00086 
00087     void                setDirty (bool dirty);
00088 
00089     void                sliderChanged (int value)
00090     { setValue ((value * m_smallStep) + inherited::minValue ()); }
00091     
00092     void        editSettings (void)
00093     {
00094       IgQtRangeSetting* setting = new IgQtRangeSetting (widget (), "setting");
00095       setting->setPrecision ("");
00096       setting->setValue (QString::number (inherited::value ()));
00097       setting->setMin (QString::number (inherited::minValue ()));
00098       setting->setMax (QString::number (inherited::maxValue ()));
00099       setting->setSmall (QString::number (getSmallStep ()));
00100       setting->setLong (QString::number (getLongStep ()));
00101       setting->enableValue (isValueEditable ());
00102       setting->enableStep (isStepEditable ());
00103       setting->enableRange (isRangeEditable ());
00104       setting->enablePrecision (isPrecisionEditable ());
00105       setting->clear ();
00106       setting->exec ();
00107       bool changed = false;
00108       setEmitSettingsChanged (false);
00109       if (setting->isApplied ())
00110       {
00111         if (setting->isRangeChanged ())
00112         {
00113           setRange (stringToNumber (setting->getMin ()),
00114                     stringToNumber (setting->getMax ()));
00115           changed = true;
00116         }
00117         if (setting->isStepChanged ())
00118         {
00119           setSmallStep (stringToNumber (setting->getSmall ()));
00120           setLongStep  (stringToNumber (setting->getLong ()));
00121           changed = true;
00122         }
00123         if (setting->isValueChanged ())
00124           textChanged (setting->getValue ());
00125       }
00126       setEmitSettingsChanged (true);
00127       if (changed)
00128         editSettingsChanged ();
00129      delete setting;
00130     }
00131     
00132     QString     getSettingString (void) const
00133     {
00134       QString setting ("");
00135       addSettingItem (QString::number(inherited::minValue ()), setting);
00136       addSettingItem (QString::number(inherited::maxValue ()), setting);
00137       addSettingItem (QString::number(getSmallStep ()), setting);
00138       addSettingItem (QString::number(getLongStep ()), setting);
00139       return setting;
00140     }
00141     
00142     void        setSettingString (QString &setting)
00143     {
00144       bool oldValue = isEmitSettingsChanged ();
00145       setEmitSettingsChanged (false);
00146     
00147       if (!setting.isEmpty ())
00148       {
00149         T min = stringToNumber (getSettingItem (setting));
00150         if (!setting.isEmpty ())
00151           setRange (min , stringToNumber (getSettingItem (setting)));
00152         else
00153           setRange (min , inherited::maxValue ());
00154       }
00155       
00156       if (!setting.isEmpty ())
00157         setSmallStep (stringToNumber (getSettingItem (setting)));
00158         
00159       if (!setting.isEmpty ())
00160         setLongStep (stringToNumber (getSettingItem (setting)));
00161     
00162       setEmitSettingsChanged (oldValue);
00163       editSettingsChanged ();
00164     }
00165     
00166 protected:
00167     virtual void        textChanged (const QString &newval)
00168     { setValue (stringToNumber (newval)); }
00169 
00170     virtual void        adjustSliderSteps (void)
00171     {
00172       if (m_slider)
00173       {
00174         disconnect (m_slider, SIGNAL (valueChanged (int)),
00175                     this,     SLOT (sliderChanged (int)));
00176         m_slider->setRange (0, int (round ((inherited::maxValue()-inherited::minValue()) / m_smallStep)));
00177         m_slider->setPageStep (int (round (m_longStep / m_smallStep)));
00178         m_slider->setValue (int (round ((inherited::value () - inherited::minValue ()) / m_smallStep)));
00179         connect (m_slider, SIGNAL (valueChanged (int)),
00180                  this,     SLOT (sliderChanged (int)));
00181       }
00182     }
00183     
00184     virtual void        moveValue (T delta, MoveDirection direction);
00185     
00186     void                fwdEnable (bool enable)
00187     {
00188       if (!(!enable && inherited::boundaryHandling () == inherited::MODULATE))
00189         IgQtRangeControl::fwdEnable (enable);
00190     }
00191     
00192     void                revEnable (bool enable)
00193     {
00194       if (!(!enable && inherited::boundaryHandling () == inherited::MODULATE))
00195         IgQtRangeControl::revEnable (enable);
00196     }
00197 
00198     void                initialize (int parts);
00199 
00200     T                   m_longStep;
00201     T                   m_smallStep;
00202 };
00203 
00204 template<class T> 
00205 IgQtRangeControlImp<T>::IgQtRangeControlImp (QWidget *parent, int parts,
00206                                              T value /* = 0 */,
00207                                              const char *name /* = 0 */)
00208     : IgQtRangeControl  (parent, parts, name),
00209       IgQtRangeValue<T> (value),
00210       m_longStep   (5),
00211       m_smallStep  (1)
00212 { initialize (parts);}
00213 
00214 template<class T> void
00215 IgQtRangeControlImp<T>::initialize (int /* parts */)
00216 {
00217     // Pretend to step into the value to get it properly bounded
00218     T oldValue = inherited::value ();
00219     inherited::forceValue (inherited::value () + m_smallStep);
00220     setValue (oldValue);
00221     inherited::forceValueChanged (0);
00222     precisionEditable (false);
00223 }
00224 
00225 template<class T> void
00226 IgQtRangeControlImp<T>::setValue (T newval)
00227 {
00228     // First let the base class handle it.  If the value doesn't
00229     // actually change, we have nothing further to do.
00230     //If tracking was not on then keep the accumulate the change value
00231     T prevChangedValue = inherited::valueChange ();
00232     IgQtRangeValue<T>::setValue (newval);
00233     if (! inherited::valueChange ())
00234     {
00235         inherited::forceValueChanged (prevChangedValue);
00236         return;
00237     }
00238     inherited::forceValueChanged (prevChangedValue + inherited::valueChange ());
00239 
00240     // Adjust the various display.
00241     if (m_text)
00242     {   
00243         m_text->setText (QString::number (inherited::value ()));
00244         m_text->setChanged (false);
00245     }
00246 
00247     if (m_slider)
00248     {
00249         disconnect (m_slider, SIGNAL (valueChanged (int)),
00250                     this, SLOT (sliderChanged (int)));
00251 
00252         m_slider->setValue (int (round ((inherited::value () - inherited::minValue ()) / m_smallStep)));
00253 
00254         connect (m_slider, SIGNAL (valueChanged (int)),
00255                  this, SLOT (sliderChanged (int)));
00256     }
00257 
00258     // Indicate where we are for various buttons and then set myself
00259     // dirty so they'll get updated.
00260     fwdEnable (inherited::maxValue () - inherited::value () >= m_smallStep);
00261     revEnable (inherited::value () - inherited::minValue () >= m_smallStep);
00262     setDirty ();
00263 }
00264 
00265 template<class T> void
00266 IgQtRangeControlImp<T>::setDirty (bool dirty)
00267 {
00268     if (dirty)
00269     {
00270         emitSignals ();
00271         IgQtRangeControl::setDirty (dirty);
00272         if (m_resetChangedValue)
00273           inherited::forceValueChanged (0);
00274     }
00275     else
00276     {
00277         inherited::forceValueChanged (0);
00278         IgQtRangeControl::setDirty (dirty);
00279     }
00280 }
00281 
00282 template<class T> void
00283 IgQtRangeControlImp<T>::moveValue (T delta, MoveDirection direction)
00284 {
00285     T oldValue = inherited::value ();
00286     switch (m_stepType)
00287     {
00288     case ADD:
00289       if(direction == MoveREV)
00290       {
00291         T newValue = oldValue - delta;
00292         if (newValue < oldValue)
00293           setValue (newValue < inherited::minValue () ? inherited::minValue (): newValue);
00294         else
00295           setValue (inherited::minValue ());
00296       }
00297       else
00298       {
00299         T newValue = oldValue + delta;
00300         if (newValue > oldValue)
00301           setValue (newValue > inherited::maxValue () ? inherited::maxValue (): newValue);
00302         else
00303           setValue (inherited::maxValue ());
00304       }
00305       break;
00306     case MULTIPLE:
00307       setValue (inherited::value () * (direction == MoveREV ? 1/delta : delta));
00308       break;
00309     }
00310 }
00311 
00312 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00313 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00314 
00315 #endif // IGUANA_GL_BROWSERS_IG_QT_RANGE_CONTROL_IMP_H

Generated on Tue Jun 9 17:38:32 2009 for CMSSW by  doxygen 1.5.4