Diffstat (limited to 'noncore/unsupported/qpdf/qbusybar.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/qbusybar.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/qbusybar.cpp b/noncore/unsupported/qpdf/qbusybar.cpp new file mode 100644 index 0000000..f5c62fa --- a/dev/null +++ b/noncore/unsupported/qpdf/qbusybar.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | #include <qapplication.h> | ||
2 | #include <qtimer.h> | ||
3 | #include <qpainter.h> | ||
4 | |||
5 | #include "qbusybar.h" | ||
6 | |||
7 | |||
8 | |||
9 | QBusyBar::QBusyBar ( QWidget *parent, const char *name, int flags ) : QWidget ( parent, name, flags | WRepaintNoErase ) | ||
10 | { | ||
11 | m_busy = 0; | ||
12 | |||
13 | m_div = 0; | ||
14 | m_pos = 0; | ||
15 | m_fade = 0; | ||
16 | m_fadecols = 0; | ||
17 | m_speed = 500; | ||
18 | |||
19 | m_timer = new QTimer ( this ); | ||
20 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( slotTimeout ( ))); | ||
21 | |||
22 | setParameters ( 12, 8, 200 ); | ||
23 | } | ||
24 | |||
25 | void QBusyBar::setParameters ( int d, int s, int v ) | ||
26 | { | ||
27 | bool running = m_timer-> isActive ( ); | ||
28 | |||
29 | if ( running ) | ||
30 | m_timer-> stop ( ); | ||
31 | |||
32 | m_div = d; | ||
33 | m_speed = v; | ||
34 | |||
35 | delete [] m_fadecols; | ||
36 | m_fade = s; | ||
37 | m_fadecols = new QColor [m_fade]; | ||
38 | |||
39 | int rt, gt, bt; | ||
40 | int rf, gf, bf; | ||
41 | |||
42 | colorGroup ( ). color ( QColorGroup::Highlight ). rgb ( &rf, &gf, &bf ); | ||
43 | colorGroup ( ). color ( QColorGroup::Background ). rgb ( &rt, >, &bt ); | ||
44 | |||
45 | for ( int i = 0; i < s; i++ ) | ||
46 | m_fadecols [i]. setRgb ( rf + ( rt - rf ) * i / s, gf + ( gt - gf ) * i / s, bf + ( bt - bf ) * i / s ); | ||
47 | |||
48 | if ( running ) { | ||
49 | m_pos = 0; | ||
50 | m_timer-> start ( m_speed ); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | QBusyBar::~QBusyBar ( ) | ||
55 | { | ||
56 | } | ||
57 | |||
58 | bool QBusyBar::isBusy ( ) const | ||
59 | { | ||
60 | return m_busy; | ||
61 | } | ||
62 | |||
63 | void QBusyBar::beginBusy ( ) | ||
64 | { | ||
65 | setBusy ( true ); | ||
66 | } | ||
67 | |||
68 | void QBusyBar::endBusy ( ) | ||
69 | { | ||
70 | setBusy ( false ); | ||
71 | } | ||
72 | |||
73 | void QBusyBar::setBusy ( bool b ) | ||
74 | { | ||
75 | int busy = m_busy + ( b ? 1 : -1 ); | ||
76 | |||
77 | if ( busy < 0 ) | ||
78 | busy = 0; | ||
79 | |||
80 | if (( m_busy == 0 ) && ( busy > 0 )) { // Changed stateto on | ||
81 | m_pos = 0; | ||
82 | m_timer-> start ( m_speed ); | ||
83 | update ( ); | ||
84 | } | ||
85 | else if (( m_busy > 0 ) && ( busy == 0 )) { // Changed state to off | ||
86 | m_timer-> stop ( ); | ||
87 | update ( ); | ||
88 | } | ||
89 | |||
90 | m_busy = busy; | ||
91 | } | ||
92 | |||
93 | void QBusyBar::slotTimeout ( ) | ||
94 | { | ||
95 | m_pos++; | ||
96 | m_pos %= ( 2 * ( m_fade + m_div )); | ||
97 | |||
98 | update ( ); | ||
99 | } | ||
100 | |||
101 | void QBusyBar::paintEvent ( QPaintEvent *e ) | ||
102 | { | ||
103 | QPainter p ( this ); | ||
104 | |||
105 | QRect clip = e-> rect ( ); | ||
106 | |||
107 | int x = 0; | ||
108 | int dx = width ( ) / m_div; | ||
109 | int y = clip. top ( ); | ||
110 | int dy = clip. height ( ); | ||
111 | |||
112 | if ( m_busy ) { | ||
113 | int dir = ( m_pos < ( m_fade + m_div )) ? 1 : -1; | ||
114 | int pos = ( dir > 0 ) ? m_pos : ( 2 * ( m_div + m_fade )) - m_pos - m_fade - 1; | ||
115 | |||
116 | for ( int i = 0; i < m_div; i++ ) { | ||
117 | int ind = ( pos - i ) * dir; | ||
118 | if (( ind < 0 ) || ( ind >= m_fade )) | ||
119 | ind = m_fade - 1; | ||
120 | |||
121 | if ((( x + dx ) > clip. left ( )) || ( x < clip. right ( ))) | ||
122 | p. fillRect ( x, y, ( i < ( m_div - 1 )) ? dx : width ( ) - x, dy, m_fadecols [ind] ); | ||
123 | x += dx; | ||
124 | } | ||
125 | } | ||
126 | else { | ||
127 | p. fillRect ( e-> rect ( ), m_fadecols [m_fade - 1] ); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | |||
132 | |||