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