Image Component Library (ICL)
ThreadedUpdatableSlider.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/ThreadedUpdatableSlider.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <QSlider>
34 #include <QtCore/QThread>
35 #include <QApplication>
37 #include <ICLUtils/Macros.h>
38 #include <ICLUtils/Function.h>
39 
40 namespace icl{
41  namespace qt{
42 
44 
52  class ICLQt_API ThreadedUpdatableSlider : public QSlider{
53  Q_OBJECT;
54 
55  struct EventFilter;
56  friend struct EventFilter;
57  //int m_stepping;
58 
60  struct CB{
62  enum Event{ press,release,move,value,all } event;
64  };
65 
67  std::vector<CB> callbacks;
68 
70 
71  public:
72 
74  ThreadedUpdatableSlider(QWidget *parent = 0);
75 
76  ThreadedUpdatableSlider(Qt::Orientation o, QWidget *parent = 0);
77 
79 
81  void setValueFromOtherThread(int value){
82  value = (value/m_stepping)*m_stepping;
83  if(QThread::currentThread() == QCoreApplication::instance()->thread()){
84  setValue(value);
85  }else{
86  QApplication::postEvent(this,new SliderUpdateEvent(value),Qt::HighEventPriority);
87  }
88  }
89 
91  void setStepping(int stepping){
92  if(m_stepping < 1) m_stepping = 1;
93  m_stepping = stepping;
94  }
95 
97  virtual bool event ( QEvent * event );
98 
100 
107  void registerCallback(const utils::Function<void> &cb, const std::string &events = "value");
108 
110  void removeCallbacks();
111 
112  protected Q_SLOTS:
114  void collectValueChanged(int);
115 
117  void collectSliderPressed();
118 
120  void collectSliderMoved(int);
121 
123  void collectSliderReleased();
124 
125  };
126 
127  } // namespace qt
128 }
129 
undocument this line if you encounter any issues!
Definition: Any.h:37
Event
associated event
Definition: ThreadedUpdatableSlider.h:62
Definition: ThreadedUpdatableSlider.h:62
Utility class for threaded updatable sliders.
Definition: SliderUpdateEvent.h:40
int m_stepping
Definition: ThreadedUpdatableSlider.h:69
void setStepping(int stepping)
the given stepping is automatically clipped to [1,...]
Definition: ThreadedUpdatableSlider.h:91
utils::Function< void > f
associated 'void f()' -function
Definition: ThreadedUpdatableSlider.h:63
#define ICLQt_API
Definition: CompatMacros.h:178
std::vector< CB > callbacks
internal list of callbacks
Definition: ThreadedUpdatableSlider.h:67
internally callback type
Definition: ThreadedUpdatableSlider.h:60
Compability class.
Definition: ThreadedUpdatableSlider.h:52
void setValueFromOtherThread(int value)
call this function to update a widget's UI from an external thread
Definition: ThreadedUpdatableSlider.h:81