-rw-r--r-- | library/backend/rohfeedback.cpp | 28 | ||||
-rw-r--r-- | library/backend/rohfeedback.h | 3 |
2 files changed, 17 insertions, 14 deletions
diff --git a/library/backend/rohfeedback.cpp b/library/backend/rohfeedback.cpp index ff76a36..21aad34 100644 --- a/library/backend/rohfeedback.cpp +++ b/library/backend/rohfeedback.cpp | |||
@@ -1,125 +1,125 @@ | |||
1 | #include <rohfeedback.h> | 1 | #ifdef OPIE_WITHROHFEEDBACK |
2 | |||
3 | 2 | ||
3 | #include <rohfeedback.h> | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <qpeapplication.h> | 5 | #include <qpeapplication.h> |
6 | #include <qevent.h> | 6 | #include <qevent.h> |
7 | #include <resource.h> | 7 | #include <resource.h> |
8 | #include <qpixmap.h> | 8 | #include <qpixmap.h> |
9 | #include <qbitmap.h> | 9 | #include <qbitmap.h> |
10 | 10 | ||
11 | #define SPEED 600 | 11 | #define SPEED 600 |
12 | #define DELAY 500 | 12 | #define DELAY 500 |
13 | 13 | ||
14 | namespace Opie { | 14 | namespace Opie { |
15 | namespace Internal { | 15 | namespace Internal { |
16 | /* | 16 | /* |
17 | 17 | ||
18 | RightOnHold feedback | 18 | RightOnHold feedback |
19 | 19 | ||
20 | */ | 20 | */ |
21 | 21 | ||
22 | QPixmap * RoHFeedback::Imgs[NOOFICONS] = { 0, 0, 0, 0, 0 }; | 22 | QPixmap * RoHFeedback::Imgs[NOOFICONS] = { 0, 0, 0, 0, 0 }; |
23 | QBitmap * RoHFeedback::Masks[NOOFICONS]; | 23 | QBitmap * RoHFeedback::Masks[NOOFICONS]; |
24 | int RoHFeedback::IconWidth; | 24 | int RoHFeedback::IconWidth; |
25 | int RoHFeedback::IconHeight; | 25 | int RoHFeedback::IconHeight; |
26 | 26 | ||
27 | RoHFeedback::RoHFeedback() : | 27 | RoHFeedback::RoHFeedback() : |
28 | QLabel( 0, 0, Qt::WType_Popup ), Timer() { | 28 | QLabel( 0, 0, Qt::WType_Popup ), Timer() { |
29 | 29 | ||
30 | Receiver = 0l; | 30 | Receiver = 0l; |
31 | connect( &Timer, SIGNAL( timeout() ), this, SLOT( iconShow() ) ); | 31 | connect( &Timer, SIGNAL( timeout() ), this, SLOT( iconShow() ) ); |
32 | 32 | ||
33 | if( Imgs[0] == 0 ) { | 33 | if( Imgs[0] == 0 ) { |
34 | QString S; | 34 | QString S; |
35 | 35 | ||
36 | 36 | ||
37 | for( int i = 0; i < NOOFICONS ; i ++ ) { | 37 | for( int i = 0; i < NOOFICONS ; i ++ ) { |
38 | Imgs[i] = new QPixmap( Resource::loadPixmap("RoH/star/"+ | 38 | Imgs[i] = new QPixmap( Resource::loadPixmap( |
39 | QString::number(i+1) + | 39 | "RoH/star/"+ QString::number(i+1) + ".png" )); |
40 | ".png" )); | ||
41 | Masks[i] = new QBitmap(); | 40 | Masks[i] = new QBitmap(); |
42 | (*Masks[i]) = Resource::loadPixmap("RoH/star/"+QString::number(i+1) + | 41 | (*Masks[i]) = Resource::loadPixmap( |
43 | ".png" ); | 42 | "RoH/star/"+QString::number(i+1) + "-mask.png" ); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | 45 | ||
47 | IconWidth = Imgs[0]->size().width(); | 46 | IconWidth = Imgs[0]->size().width(); |
48 | IconHeight = Imgs[0]->size().height(); | 47 | IconHeight = Imgs[0]->size().height(); |
49 | 48 | ||
50 | resize( IconWidth, IconHeight ); | 49 | resize( IconWidth, IconHeight ); |
51 | } | 50 | } |
52 | 51 | ||
53 | int RoHFeedback::delay( void ) { | 52 | int RoHFeedback::delay( void ) { |
54 | return DELAY+SPEED+50; | 53 | return DELAY+SPEED+50; |
55 | } | 54 | } |
56 | 55 | ||
57 | RoHFeedback::~RoHFeedback() { | 56 | RoHFeedback::~RoHFeedback() { |
58 | for ( int i = 0; i < NOOFICONS; ++i ) { | 57 | for ( int i = 0; i < NOOFICONS; ++i ) { |
59 | delete Imgs [i]; | 58 | delete Imgs [i]; |
60 | delete Masks[i]; | 59 | delete Masks[i]; |
61 | } | 60 | } |
62 | } | 61 | } |
63 | 62 | ||
64 | void RoHFeedback::init( const QPoint & P, QWidget* wid ) { | 63 | void RoHFeedback::init( const QPoint & P, QWidget* wid ) { |
65 | if( ! IconWidth ) | 64 | if( ! IconWidth ) |
66 | return; | 65 | return; |
67 | 66 | ||
68 | Receiver = wid; | 67 | Receiver = wid; |
69 | IconNr = -1; | 68 | IconNr = FeedbackTimerStart; |
70 | move( P.x()-IconWidth/2, P.y() - IconHeight/2 ); | 69 | move( P.x()-IconWidth/2, P.y() - IconHeight/2 ); |
71 | // to initialize | 70 | // to initialize |
72 | Timer.start( DELAY - SPEED/NOOFICONS ); | 71 | Timer.start( DELAY ); |
73 | } | 72 | } |
74 | 73 | ||
75 | void RoHFeedback::stop( void ) { | 74 | void RoHFeedback::stop( void ) { |
76 | IconNr = -2; // stop | 75 | IconNr = FeedbackStopped; // stop |
77 | hide(); | ||
78 | Timer.stop(); | ||
79 | } | 76 | } |
80 | 77 | ||
81 | bool RoHFeedback::event( QEvent * E ) { | 78 | bool RoHFeedback::event( QEvent * E ) { |
82 | 79 | ||
83 | if( E->type() >= QEvent::MouseButtonPress && | 80 | if( E->type() >= QEvent::MouseButtonPress && |
84 | E->type() <= QEvent::MouseMove ) { | 81 | E->type() <= QEvent::MouseMove ) { |
85 | // pass the event to the receiver with translated coord | 82 | // pass the event to the receiver with translated coord |
86 | QMouseEvent QME( ((QMouseEvent *)E)->type(), | 83 | QMouseEvent QME( ((QMouseEvent *)E)->type(), |
87 | Receiver->mapFromGlobal( | 84 | Receiver->mapFromGlobal( |
88 | ((QMouseEvent *)E)->globalPos() ), | 85 | ((QMouseEvent *)E)->globalPos() ), |
89 | ((QMouseEvent *)E)->globalPos(), | 86 | ((QMouseEvent *)E)->globalPos(), |
90 | ((QMouseEvent *)E)->button(), | 87 | ((QMouseEvent *)E)->button(), |
91 | ((QMouseEvent *)E)->state() | 88 | ((QMouseEvent *)E)->state() |
92 | ); | 89 | ); |
93 | return QPEApplication::sendEvent( Receiver, &QME ); | 90 | return QPEApplication::sendEvent( Receiver, &QME ); |
94 | } | 91 | } |
95 | 92 | ||
96 | // first let the label treat the event | 93 | // first let the label treat the event |
97 | return QLabel::event( E ); | 94 | return QLabel::event( E ); |
98 | } | 95 | } |
99 | 96 | ||
100 | void RoHFeedback::iconShow( void ) { | 97 | void RoHFeedback::iconShow( void ) { |
101 | switch( IconNr ) { | 98 | switch( IconNr ) { |
102 | case FeedbackTimerStart: | 99 | case FeedbackTimerStart: |
103 | IconNr = 0; | 100 | IconNr = FeedbackShow; |
104 | Timer.start( SPEED/NOOFICONS ); | 101 | Timer.start( SPEED/NOOFICONS ); |
105 | break; | 102 | break; |
106 | case FeedbackStopped: | 103 | case FeedbackStopped: |
107 | // stopped | 104 | // stopped |
108 | IconNr = FeedbackTimerStart; | 105 | IconNr = FeedbackTimerStart; |
109 | hide(); | 106 | hide(); |
107 | Timer.stop(); | ||
110 | break; | 108 | break; |
111 | case FeedbackShow: // first | 109 | case FeedbackShow: // first |
112 | show(); | 110 | show(); |
113 | // FT | 111 | // FT |
114 | default : | 112 | default : |
115 | // show | 113 | // show |
116 | 114 | ||
117 | setPixmap( *(Imgs[IconNr]) ); | 115 | setPixmap( *(Imgs[IconNr]) ); |
118 | setMask( *(Masks[IconNr]) ); | 116 | setMask( *(Masks[IconNr]) ); |
119 | IconNr = (IconNr+1)%NOOFICONS; // rotate | 117 | IconNr = (IconNr+1)%NOOFICONS; // rotate |
120 | break; | 118 | break; |
121 | } | 119 | } |
122 | } | 120 | } |
123 | 121 | ||
124 | } | 122 | } |
125 | } \ No newline at end of file | 123 | } |
124 | |||
125 | #endif | ||
diff --git a/library/backend/rohfeedback.h b/library/backend/rohfeedback.h index f38a095..9ffd35a 100644 --- a/library/backend/rohfeedback.h +++ b/library/backend/rohfeedback.h | |||
@@ -1,62 +1,65 @@ | |||
1 | #ifndef ROHFEEDBACK_H | 1 | #ifndef ROHFEEDBACK_H |
2 | #define ROHFEEDBACK_H | 2 | #define ROHFEEDBACK_H |
3 | 3 | ||
4 | #ifdef OPIE_WITHROHFEEDBACK | ||
5 | |||
4 | /* | 6 | /* |
5 | 7 | ||
6 | RightOnHold feedback show | 8 | RightOnHold feedback show |
7 | 9 | ||
8 | */ | 10 | */ |
9 | 11 | ||
10 | #define NOOFICONS 5 | 12 | #define NOOFICONS 5 |
11 | 13 | ||
12 | #include <qlabel.h> | 14 | #include <qlabel.h> |
13 | #include <qtimer.h> | 15 | #include <qtimer.h> |
14 | 16 | ||
15 | class QEvent; | 17 | class QEvent; |
16 | class QPixmap; | 18 | class QPixmap; |
17 | class QBitmap; | 19 | class QBitmap; |
18 | class QMouseEvent; | 20 | class QMouseEvent; |
19 | 21 | ||
20 | namespace Opie { | 22 | namespace Opie { |
21 | namespace Internal { | 23 | namespace Internal { |
22 | 24 | ||
23 | class RoHFeedback : public QLabel { | 25 | class RoHFeedback : public QLabel { |
24 | 26 | ||
25 | Q_OBJECT | 27 | Q_OBJECT |
26 | 28 | ||
27 | enum Actions { | 29 | enum Actions { |
28 | FeedbackStopped = -2, | 30 | FeedbackStopped = -2, |
29 | FeedbackTimerStart = -1, | 31 | FeedbackTimerStart = -1, |
30 | FeedbackShow = 0 | 32 | FeedbackShow = 0 |
31 | }; | 33 | }; |
32 | public : | 34 | public : |
33 | 35 | ||
34 | RoHFeedback(); | 36 | RoHFeedback(); |
35 | ~RoHFeedback(); | 37 | ~RoHFeedback(); |
36 | 38 | ||
37 | 39 | ||
38 | void init( const QPoint & P, QWidget* wid ); | 40 | void init( const QPoint & P, QWidget* wid ); |
39 | void stop( void ); | 41 | void stop( void ); |
40 | int delay( void ); | 42 | int delay( void ); |
41 | 43 | ||
42 | public slots : | 44 | public slots : |
43 | 45 | ||
44 | void iconShow( void ); | 46 | void iconShow( void ); |
45 | 47 | ||
46 | protected : | 48 | protected : |
47 | 49 | ||
48 | bool event( QEvent * E ); | 50 | bool event( QEvent * E ); |
49 | 51 | ||
50 | QTimer Timer; | 52 | QTimer Timer; |
51 | int IconNr; | 53 | int IconNr; |
52 | QWidget * Receiver; | 54 | QWidget * Receiver; |
53 | 55 | ||
54 | static int IconWidth; | 56 | static int IconWidth; |
55 | static int IconHeight; | 57 | static int IconHeight; |
56 | static QPixmap * Imgs[NOOFICONS]; | 58 | static QPixmap * Imgs[NOOFICONS]; |
57 | static QBitmap * Masks[NOOFICONS]; | 59 | static QBitmap * Masks[NOOFICONS]; |
58 | }; | 60 | }; |
59 | } | 61 | } |
60 | } | 62 | } |
61 | 63 | ||
62 | #endif | 64 | #endif |
65 | #endif | ||