Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

rohfeedback.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include <rohfeedback.h>
00022 #include <stdio.h>
00023 #include <qpeapplication.h>
00024 #include <qevent.h>
00025 #include <resource.h>
00026 #include <qpixmap.h>
00027 #include <qbitmap.h>
00028 
00029 #define SPEED 600
00030 #define DELAY 500
00031 
00032 namespace Opie {
00033 namespace Internal {
00034 /*
00035 
00036     RightOnHold feedback
00037 
00038 */
00039 
00040 QPixmap * RoHFeedback::Imgs[NOOFICONS] = { 0, 0, 0, 0, 0 };
00041 QBitmap * RoHFeedback::Masks[NOOFICONS];
00042 int RoHFeedback::IconWidth;
00043 int RoHFeedback::IconHeight;
00044 
00045 RoHFeedback::RoHFeedback() :
00046                         QLabel( 0, 0, Qt::WType_Popup ), Timer() {
00047 
00048     Receiver = 0l;
00049     connect( &Timer, SIGNAL( timeout() ), this, SLOT( iconShow() ) );
00050 
00051     if( Imgs[0] == 0 ) {
00052       QString S;
00053 
00054 
00055       for( int i = 0; i < NOOFICONS ; i ++ ) {
00056         Imgs[i] =  new QPixmap( Resource::loadPixmap(
00057               "RoH/star/"+ QString::number(i+1)  ));
00058         Masks[i] = new QBitmap();
00059         (*Masks[i]) = Resource::loadPixmap(
00060               "RoH/star/"+QString::number(i+1) + "-mask" );
00061       }
00062     }
00063 
00064     IconWidth = Imgs[0]->size().width();
00065     IconHeight = Imgs[0]->size().height();
00066 
00067     resize( IconWidth, IconHeight );
00068 }
00069 
00070 int RoHFeedback::delay( void ) {
00071     return DELAY+SPEED+50;
00072 }
00073 
00074 RoHFeedback::~RoHFeedback() {
00075     for ( int i = 0; i < NOOFICONS; ++i ) {
00076         delete Imgs [i];
00077         delete Masks[i];
00078     }
00079 }
00080 
00081 void RoHFeedback::init( const QPoint & P, QWidget* wid ) {
00082     if( ! IconWidth )
00083       return;
00084 
00085     Receiver =  wid;
00086     IconNr = FeedbackTimerStart;
00087     move( P.x()-IconWidth/2, P.y() - IconHeight/2 );
00088     // to initialize
00089     Timer.start( DELAY );
00090 }
00091 
00092 void RoHFeedback::stop( void ) {
00093     IconNr = FeedbackStopped; // stop
00094 }
00095 
00096 bool RoHFeedback::event( QEvent * E ) {
00097 
00098     if( E->type() >= QEvent::MouseButtonPress &&
00099         E->type() <= QEvent::MouseMove ) {
00100       // pass the event to the receiver with translated coord
00101       QMouseEvent QME( ((QMouseEvent *)E)->type(),
00102                        Receiver->mapFromGlobal(
00103                           ((QMouseEvent *)E)->globalPos() ),
00104                        ((QMouseEvent *)E)->globalPos(),
00105                        ((QMouseEvent *)E)->button(),
00106                        ((QMouseEvent *)E)->state()
00107                    );
00108       return QPEApplication::sendEvent( Receiver, &QME );
00109     }
00110 
00111     // first let the label treat the event
00112     return QLabel::event( E );
00113 }
00114 
00115 void RoHFeedback::iconShow( void ) {
00116     switch( IconNr ) {
00117       case FeedbackTimerStart:
00118         IconNr = FeedbackShow;
00119         Timer.start( SPEED/NOOFICONS );
00120         break;
00121       case FeedbackStopped:
00122         // stopped
00123         IconNr = FeedbackTimerStart;
00124         hide();
00125         Timer.stop();
00126         break;
00127       case FeedbackShow: // first
00128         show();
00129         // FT
00130       default :
00131         // show
00132 
00133         setPixmap( *(Imgs[IconNr]) );
00134         setMask( *(Masks[IconNr]) );
00135         IconNr = (IconNr+1)%NOOFICONS; // rotate
00136         break;
00137     }
00138 }
00139 
00140 }
00141 }
00142 

Generated on Sat Nov 5 16:16:33 2005 for OPIE by  doxygen 1.4.2