raDIYo 0.4
swflipdigit.h
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14/*+
15 * contains copy-written material from qt example code:
16 * @see shaped clock example
17 * @see embedded/flipdigits example
18 *
19 * **/
20
21
22#ifndef SWFLIPDIGIT_H
23#define SWFLIPDIGIT_H
24
25#include <QWidget>
26#include <QTimeLine>
27
28class SWFlipDigit : public QWidget
29{
30
31 Q_OBJECT
32
33public:
34
35 enum SWFlipMode
36 {
37 Slide,
38 Flip,
39 Rotate
40 };
41
42 explicit SWFlipDigit(QWidget *parent = nullptr);
43 virtual ~SWFlipDigit();
44
45 void setTransition( SWFlipMode tr );
46 SWFlipMode transition() const;
47
48 void setRange( int from, int to );
49
50public slots:
51
52 void setNumber( int n );
53 void flipTo( int n );
54
55protected:
56
57 const double SWSCALEFACTOR = 2.7;
58 const double SWFONTSCALE = 0.85;
59
60 void drawFrame( QPainter* p, const QRect& rect );
61 QPixmap drawDigits(int n, const QRect &rect);
62 void preparePixmap();
63
64 void resizeEvent( QResizeEvent* event ) override;
65 void paintEvent( QPaintEvent* event ) override;
66 void paintStatic();
67 void paintSlide();
68 void paintFlip();
69 void paintRotate();
70
71 //const int SWPADWIDTH = 0;//1;//15;
72
73 int _rangeFrom = 0;
74 int _rangeTo = 99;
75 int _number;
76 SWFlipMode _transition;
77 QPixmap _pixmap;
78 QPixmap _lastPixmap;
79 QTimeLine _animator;
80
81};
82
83
84
85
86#endif // SWFLIPDIGIT_H