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 | |
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
-rw-r--r-- | library/backend/rohfeedback.cpp | 125 | ||||
-rw-r--r-- | library/backend/rohfeedback.h | 62 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 32 |
3 files changed, 216 insertions, 3 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 | ||
diff --git a/library/backend/rohfeedback.h b/library/backend/rohfeedback.h new file mode 100644 index 0000000..f38a095 --- a/dev/null +++ b/library/backend/rohfeedback.h | |||
@@ -0,0 +1,62 @@ | |||
1 | #ifndef ROHFEEDBACK_H | ||
2 | #define ROHFEEDBACK_H | ||
3 | |||
4 | /* | ||
5 | |||
6 | RightOnHold feedback show | ||
7 | |||
8 | */ | ||
9 | |||
10 | #define NOOFICONS 5 | ||
11 | |||
12 | #include <qlabel.h> | ||
13 | #include <qtimer.h> | ||
14 | |||
15 | class QEvent; | ||
16 | class QPixmap; | ||
17 | class QBitmap; | ||
18 | class QMouseEvent; | ||
19 | |||
20 | namespace Opie { | ||
21 | namespace Internal { | ||
22 | |||
23 | class RoHFeedback : public QLabel { | ||
24 | |||
25 | Q_OBJECT | ||
26 | |||
27 | enum Actions { | ||
28 | FeedbackStopped = -2, | ||
29 | FeedbackTimerStart = -1, | ||
30 | FeedbackShow = 0 | ||
31 | }; | ||
32 | public : | ||
33 | |||
34 | RoHFeedback(); | ||
35 | ~RoHFeedback(); | ||
36 | |||
37 | |||
38 | void init( const QPoint & P, QWidget* wid ); | ||
39 | void stop( void ); | ||
40 | int delay( void ); | ||
41 | |||
42 | public slots : | ||
43 | |||
44 | void iconShow( void ); | ||
45 | |||
46 | protected : | ||
47 | |||
48 | bool event( QEvent * E ); | ||
49 | |||
50 | QTimer Timer; | ||
51 | int IconNr; | ||
52 | QWidget * Receiver; | ||
53 | |||
54 | static int IconWidth; | ||
55 | static int IconHeight; | ||
56 | static QPixmap * Imgs[NOOFICONS]; | ||
57 | static QBitmap * Masks[NOOFICONS]; | ||
58 | }; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | #endif | ||
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 59ca61b..acad81d 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -97,8 +97,12 @@ | |||
97 | #endif | 97 | #endif |
98 | #include "qt_override_p.h" | 98 | #include "qt_override_p.h" |
99 | 99 | ||
100 | #include <qpe/rohfeedback.h> | ||
101 | |||
102 | |||
100 | static bool useBigPixmaps = 0; | 103 | static bool useBigPixmaps = 0; |
101 | 104 | ||
105 | |||
102 | class HackWidget : public QWidget | 106 | class HackWidget : public QWidget |
103 | { | 107 | { |
104 | public: | 108 | public: |
@@ -126,6 +130,7 @@ public: | |||
126 | fontSize = cfg.readNumEntry( "FontSize", 10 ); | 130 | fontSize = cfg.readNumEntry( "FontSize", 10 ); |
127 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); | 131 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); |
128 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); | 132 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); |
133 | RoH = 0; | ||
129 | } | 134 | } |
130 | 135 | ||
131 | int presstimer; | 136 | int presstimer; |
@@ -492,6 +497,8 @@ static void qpe_show_dialog( QDialog* d, bool nomax ) | |||
492 | } | 497 | } |
493 | } | 498 | } |
494 | } | 499 | } |
500 | |||
501 | Opie::Internal::RoHFeedback * RoH; | ||
495 | }; | 502 | }; |
496 | 503 | ||
497 | class ResourceMimeFactory : public QMimeSourceFactory | 504 | class ResourceMimeFactory : public QMimeSourceFactory |
@@ -1205,7 +1212,7 @@ QPEApplication::~QPEApplication() | |||
1205 | delete sysChannel; | 1212 | delete sysChannel; |
1206 | delete pidChannel; | 1213 | delete pidChannel; |
1207 | #endif | 1214 | #endif |
1208 | 1215 | delete d->RoH; | |
1209 | delete d; | 1216 | delete d; |
1210 | } | 1217 | } |
1211 | 1218 | ||
@@ -2023,16 +2030,30 @@ bool QPEApplication::eventFilter( QObject *o, QEvent *e ) | |||
2023 | switch ( me->type() ) { | 2030 | switch ( me->type() ) { |
2024 | case QEvent::MouseButtonPress: | 2031 | case QEvent::MouseButtonPress: |
2025 | if ( me->button() == LeftButton ) { | 2032 | if ( me->button() == LeftButton ) { |
2026 | if (!d->presstimer ) | ||
2027 | d->presstimer = startTimer(500); // #### pref. | ||
2028 | d->presswidget = (QWidget*)o; | 2033 | d->presswidget = (QWidget*)o; |
2029 | d->presspos = me->pos(); | 2034 | d->presspos = me->pos(); |
2030 | d->rightpressed = FALSE; | 2035 | d->rightpressed = FALSE; |
2036 | // just for the time being | ||
2037 | static int pref = 500; | ||
2038 | #ifdef WITHROHFEEDBACK | ||
2039 | if( ! d->RoH ) | ||
2040 | d->RoH = new Opie::Internal::RoHFeedback; | ||
2041 | |||
2042 | d->RoH->init( me->globalPos(), d->presswidget ); | ||
2043 | pref = d->RoH->delay(); | ||
2044 | #endif | ||
2045 | if (!d->presstimer ) | ||
2046 | d->presstimer = startTimer( pref ); // #### pref. | ||
2047 | |||
2031 | } | 2048 | } |
2032 | break; | 2049 | break; |
2033 | case QEvent::MouseMove: | 2050 | case QEvent::MouseMove: |
2034 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { | 2051 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { |
2035 | killTimer(d->presstimer); | 2052 | killTimer(d->presstimer); |
2053 | #ifdef WITHROHFEEDBACK | ||
2054 | if( d->RoH ) | ||
2055 | d->RoH->stop( ); | ||
2056 | #endif | ||
2036 | d->presstimer = 0; | 2057 | d->presstimer = 0; |
2037 | } | 2058 | } |
2038 | break; | 2059 | break; |
@@ -2040,6 +2061,10 @@ bool QPEApplication::eventFilter( QObject *o, QEvent *e ) | |||
2040 | if ( me->button() == LeftButton ) { | 2061 | if ( me->button() == LeftButton ) { |
2041 | if ( d->presstimer ) { | 2062 | if ( d->presstimer ) { |
2042 | killTimer(d->presstimer); | 2063 | killTimer(d->presstimer); |
2064 | #ifdef WITHROHFEEDBACK | ||
2065 | if( d->RoH ) | ||
2066 | d->RoH->stop( ); | ||
2067 | #endif | ||
2043 | d->presstimer = 0; | 2068 | d->presstimer = 0; |
2044 | } | 2069 | } |
2045 | if ( d->rightpressed && d->presswidget ) { | 2070 | if ( d->rightpressed && d->presswidget ) { |
@@ -2093,6 +2118,7 @@ void QPEApplication::timerEvent( QTimerEvent *e ) | |||
2093 | killTimer( d->presstimer ); | 2118 | killTimer( d->presstimer ); |
2094 | d->presstimer = 0; | 2119 | d->presstimer = 0; |
2095 | d->rightpressed = TRUE; | 2120 | d->rightpressed = TRUE; |
2121 | d->RoH->stop(); | ||
2096 | } | 2122 | } |
2097 | } | 2123 | } |
2098 | 2124 | ||