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

syncdialog.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003               =.             (C) 2000-2002 Trolltech AS
00004             .=l.             (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
00005            .>+-=
00006  _;:,     .>    :=|.         This program is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00008     :`=1 )Y*s>-.--   :       the terms of the GNU Library General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; version 2 of the License.
00011      ._= =}       :
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This program is distributed in the hope that
00014      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00018 ..}^=.=       =       ;      Library General Public License for more
00019 ++=   -.     .`     .:       details.
00020     :     =  ...= . :.=-
00021  -.   .:....=;==+<;          You should have received a copy of the GNU
00022   -_. . .   )=.  =           Library General Public License along with
00023     --        :-=`           this library; see the file COPYING.LIB.
00024                              If not, write to the Free Software Foundation,
00025                              Inc., 59 Temple Place - Suite 330,
00026                              Boston, MA 02111-1307, USA.
00027 */
00028 #include "syncdialog.h"
00029 
00030 /* OPIE */
00031 #include <opie2/oresource.h>
00032 using namespace Opie::Core;
00033 
00034 /* QT */
00035 #include <qpainter.h>
00036 #include <qapplication.h>
00037 #include <qpushbutton.h>
00038 #include <qfile.h>
00039 
00040 SyncDialog::SyncDialog( QWidget *parent, const QString &w )
00041     : QDialog( parent, "SyncDialog", FALSE, WStyle_Tool | WStyle_Customize |
00042         WStyle_StaysOnTop ), what(w), nextPt(0), rev(FALSE), hideDot(TRUE)
00043 {
00044     QFont f( font() );
00045     f.setPointSize( 16 );
00046     setFont(f);
00047 
00048     loadPath();
00049 
00050     QSize ds = qApp->desktop()->size();
00051     setGeometry( 0, 0, ds.width(), ds.height() );
00052     img = OResource::loadImage( "SyncScreen", OResource::NoScale );
00053     if ( img.width() > ds.width() || img.height() > ds.height() ) {
00054         path = scalePath( path, ds.width(), img.width(), ds.height(), img.height() );
00055         img = img.smoothScale( ds.width(), ds.height() );
00056     }
00057     dot = OResource::loadImage( "syncdot", OResource::NoScale );
00058     setBackgroundColor( white );
00059 
00060     QPushButton *pb = new QPushButton( tr("Abort"), this, "CancelSync" );
00061     QSize bs = pb->sizeHint();
00062     bs.rwidth() += 10;
00063     bs.rheight() += 5;
00064     pb->setGeometry( (ds.width()-bs.width())/2, 4*ds.height()/5,
00065                         bs.width(), bs.height() );
00066     connect( pb, SIGNAL(clicked()), this, SIGNAL(cancel()) );
00067 
00068     if ( path.count() >= 2 ) {
00069         path = generatePath( path, 8 );
00070         startTimer( 200 );
00071     }
00072 }
00073 
00074 void SyncDialog::paintEvent( QPaintEvent *pe )
00075 {
00076     QPainter p(this );
00077     p.setClipRect( pe->rect() );
00078     int ox = (width() - img.width())/2;
00079     int oy = (height() - img.height())/2;
00080 
00081     QRect ir = QRect(ox, oy, img.width(), img.height()) & pe->rect();
00082 
00083     if ( ir.isValid() )
00084         p.drawImage( ir.x(), ir.y(), img, ir.x()-ox, ir.y()-oy, ir.width(), ir.height() );
00085 
00086     QString syncMsg = tr("Syncing:");
00087     p.setPen( black );
00088     QRect r( 0, 0, width()/2-5, QMAX(oy,80) );
00089     p.drawText( r, AlignRight | AlignVCenter, syncMsg );
00090     r.moveBy( width()/2, 0 );
00091     QFont f( font() );
00092     f.setWeight( QFont::Bold );
00093     p.setFont( f );
00094     p.drawText( r, AlignLeft | AlignVCenter, what );
00095 
00096     if ( !hideDot )
00097         p.drawImage( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot );
00098 }
00099 
00100 void SyncDialog::timerEvent( QTimerEvent * )
00101 {
00102     int ox = (width() - img.width())/2;
00103     int oy = (height() - img.height())/2;
00104     int oldPt = nextPt;
00105 
00106     if ( !rev ) {
00107         nextPt++;
00108         if ( nextPt == (int)path.count() ) {
00109             nextPt -= 2;
00110             rev = TRUE;
00111         }
00112     } else {
00113         nextPt--;
00114         if ( nextPt < 0 ) {
00115             nextPt = 1;
00116             rev = FALSE;
00117         }
00118     }
00119 
00120     hideDot = FALSE;
00121     repaint( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2,
00122             dot.width(), dot.height() );
00123     hideDot = TRUE;
00124     repaint( ox+path[oldPt].x()-dot.width()/2, oy+path[oldPt].y()-dot.height()/2,
00125             dot.width(), dot.height() );
00126 }
00127 
00128 void SyncDialog::loadPath()
00129 {
00130     QString pfile = OResource::findPixmap( "syncdot" );
00131     if ( pfile.isEmpty() )
00132         return;
00133     int dp = pfile.findRev('.');
00134     pfile.replace( dp, pfile.length()-dp, ".path" );
00135 
00136     int count = 0;
00137     QFile file( pfile );
00138     if ( file.open( IO_ReadOnly ) ) {
00139         QString line;
00140         while ( file.readLine( line, 256 ) > 0 ) {
00141             int x, y;
00142             if ( sscanf( line.latin1(), "%d %d", &x, &y ) == 2 ) {
00143                 path.resize( count+1 );
00144                 path[count++] = QPoint(x, y);
00145             }
00146         }
00147     }
00148 }
00149 
00150 QPointArray SyncDialog::scalePath( const QPointArray &pa, int xn, int xd, int yn, int yd )
00151 {
00152     QPointArray sa( pa.size() );
00153 
00154     for ( unsigned i = 0; i < pa.count(); i++ ) {
00155         int x = xn * pa[int(i)].x() / xd;
00156         int y = yn * pa[int(i)].y() / yd;
00157         sa[int(i)] = QPoint( x, y );
00158     }
00159 
00160     return sa;
00161 }
00162 
00163 QPointArray SyncDialog::generatePath( const QPointArray &pa, int dist )
00164 {
00165     if ( pa.count() < 2 )
00166         return pa;
00167 
00168     QPointArray fa;
00169     int count = 0;
00170     fa.resize( count+1 );
00171     fa[count++] = pa[0];
00172     for ( unsigned i = 0; i < pa.count()-1; i++ ) {
00173         int x1 = pa[int(i)].x();
00174         int y1 = pa[int(i)].y();
00175         int x2 = pa[int(i+1)].x();
00176         int y2 = pa[int(i+1)].y();
00177         int dx = x2 - x1;
00178         int dy = y2 - y1;
00179         int pts = (QMAX(QABS(dx),QABS(dy)) + dist/2 )/dist;
00180         for ( int j = 1; j < pts; j++ ) {
00181             int x = j * dx / pts;
00182             int y = j * dy / pts;
00183             fa.resize( count+1 );
00184             fa[count++] = pa[int(i)] + QPoint( x, y );
00185         }
00186         fa.resize( count+1 );
00187         fa[count++] = pa[int(i+1)];
00188     }
00189 
00190     return fa;
00191 }
00192 

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