add a new aoclocklabel class that is a QLabel with fancy DR-Style timing features
WIP
This commit is contained in:
		
							parent
							
								
									af1e760225
								
							
						
					
					
						commit
						edf3d463e9
					
				
							
								
								
									
										29
									
								
								include/aoclocklabel.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								include/aoclocklabel.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					#ifndef AOCLOCKLABEL_H
 | 
				
			||||||
 | 
					#define AOCLOCKLABEL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QLabel>
 | 
				
			||||||
 | 
					#include <QBasicTimer>
 | 
				
			||||||
 | 
					#include <QTimerEvent>
 | 
				
			||||||
 | 
					#include <QTime>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AOClockLabel : public QLabel {
 | 
				
			||||||
 | 
					  Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					  AOClockLabel(QWidget *parent);
 | 
				
			||||||
 | 
					  void start();
 | 
				
			||||||
 | 
					  void start(QTime p_time);
 | 
				
			||||||
 | 
					  void pause();
 | 
				
			||||||
 | 
					  void resume();
 | 
				
			||||||
 | 
					  void stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
					  void timerEvent(QTimerEvent *event) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    QBasicTimer timer;
 | 
				
			||||||
 | 
					    QTime starting_time;
 | 
				
			||||||
 | 
					    QTime target_time;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // AOCLOCKLABEL_H
 | 
				
			||||||
							
								
								
									
										35
									
								
								src/aoclocklabel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/aoclocklabel.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					#include "aoclocklabel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::start()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  this->resume();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::start(QTime p_time)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  QTime time = QTime::currentTime();
 | 
				
			||||||
 | 
					  if (p_time > time)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    target_time = p_time;
 | 
				
			||||||
 | 
					    starting_time = time;
 | 
				
			||||||
 | 
					    timer.start(100, this);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::pause() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::resume() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::stop() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOClockLabel::timerEvent(QTimerEvent *event)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (event->timerId() == timer.timerId()) {
 | 
				
			||||||
 | 
					        QTime elapsed = QTime(0,0).addSecs(starting_time.secsTo(starting_time));
 | 
				
			||||||
 | 
					        this->setText(elapsed.toString("hh:mm:ss.zzz"));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        QWidget::timerEvent(event);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user