Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ThreadedUpdatableSlider.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/ThreadedUpdatableSlider.h              **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <QtGui/QSlider>
00034 #include <QtGui/QApplication>
00035 #include <ICLQt/SliderUpdateEvent.h>
00036 #include <ICLUtils/Macros.h>
00037 #include <ICLUtils/Function.h>
00038 
00039 namespace icl{
00040   namespace qt{
00041     
00043 
00051     class ThreadedUpdatableSlider : public QSlider{
00052       Q_OBJECT;
00053       
00055       struct CB{
00057         enum Event{ press,release,move,value,all } event;
00058         utils::Function<void> f; 
00059       };
00060       
00062       std::vector<CB> callbacks;
00063       
00064       public:
00065       
00067       ThreadedUpdatableSlider(QWidget *parent = 0);
00068   
00069       ThreadedUpdatableSlider(Qt::Orientation o, QWidget *parent = 0);
00070       
00072       void setValueFromOtherThread(int value){
00073         QApplication::postEvent(this,new SliderUpdateEvent(value),Qt::HighEventPriority);
00074       }
00075       
00077       virtual bool event ( QEvent * event ){
00078         ICLASSERT_RETURN_VAL(event,false);
00079         if(event->type() == SliderUpdateEvent::EVENT_ID){
00080           setValue(reinterpret_cast<SliderUpdateEvent*>(event)->value);
00081           return true;
00082         }else{
00083           return QSlider::event(event);
00084         }
00085       } 
00086       
00088 
00095       void registerCallback(const utils::Function<void> &cb, const std::string &events="value");
00096   
00098       void removeCallbacks();
00099   
00100       protected slots:
00102       void collectValueChanged(int);
00103   
00105       void collectSliderPressed();
00106   
00108       void collectSliderMoved(int);
00109   
00111       void collectSliderReleased();
00112       
00113     };
00114   
00115   } // namespace qt
00116 }
00117 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines