summaryrefslogtreecommitdiff
path: root/core/launcher/syncdialog.cpp
Unidiff
Diffstat (limited to 'core/launcher/syncdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/syncdialog.cpp184
1 files changed, 184 insertions, 0 deletions
diff --git a/core/launcher/syncdialog.cpp b/core/launcher/syncdialog.cpp
new file mode 100644
index 0000000..6f6c781
--- a/dev/null
+++ b/core/launcher/syncdialog.cpp
@@ -0,0 +1,184 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "syncdialog.h"
22
23#include <qtopia/resource.h>
24
25#include <qimage.h>
26#include <qpainter.h>
27#include <qapplication.h>
28#include <qpushbutton.h>
29#include <qfile.h>
30
31
32SyncDialog::SyncDialog( QWidget *parent, const QString &w )
33 : QDialog( parent, "SyncDialog", FALSE, WStyle_Tool | WStyle_Customize |
34 WStyle_StaysOnTop ), what(w), nextPt(0), rev(FALSE), hideDot(TRUE)
35{
36 QFont f( font() );
37 f.setPointSize( 16 );
38 setFont(f);
39
40 loadPath();
41
42 QSize ds = qApp->desktop()->size();
43 setGeometry( 0, 0, ds.width(), ds.height() );
44 img = Resource::loadImage( "SyncScreen" );
45 if ( img.width() > ds.width() || img.height() > ds.height() ) {
46 path = scalePath( path, ds.width(), img.width(), ds.height(), img.height() );
47 img = img.smoothScale( ds.width(), ds.height() );
48 }
49 dot = Resource::loadImage( "syncdot" );
50 setBackgroundColor( white );
51
52 QPushButton *pb = new QPushButton( tr("Abort"), this, "CancelSync" );
53 QSize bs = pb->sizeHint();
54 bs.rwidth() += 10;
55 bs.rheight() += 5;
56 pb->setGeometry( (ds.width()-bs.width())/2, 4*ds.height()/5,
57 bs.width(), bs.height() );
58 connect( pb, SIGNAL(clicked()), this, SIGNAL(cancel()) );
59
60 if ( path.count() >= 2 ) {
61 path = generatePath( path, 8 );
62 startTimer( 200 );
63 }
64}
65
66void SyncDialog::paintEvent( QPaintEvent *pe )
67{
68 QPainter p(this );
69 p.setClipRect( pe->rect() );
70 int ox = (width() - img.width())/2;
71 int oy = (height() - img.height())/2;
72
73 QRect ir = QRect(ox, oy, img.width(), img.height()) & pe->rect();
74
75 if ( ir.isValid() )
76 p.drawImage( ir.x(), ir.y(), img, ir.x()-ox, ir.y()-oy, ir.width(), ir.height() );
77
78 QString syncMsg = tr("Syncing:");
79 p.setPen( black );
80 QRect r( 0, 0, width()/2-5, QMAX(oy,80) );
81 p.drawText( r, AlignRight | AlignVCenter, syncMsg );
82 r.moveBy( width()/2, 0 );
83 QFont f( font() );
84 f.setWeight( QFont::Bold );
85 p.setFont( f );
86 p.drawText( r, AlignLeft | AlignVCenter, what );
87
88 if ( !hideDot )
89 p.drawImage( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot );
90}
91
92void SyncDialog::timerEvent( QTimerEvent * )
93{
94 int ox = (width() - img.width())/2;
95 int oy = (height() - img.height())/2;
96 int oldPt = nextPt;
97
98 if ( !rev ) {
99 nextPt++;
100 if ( nextPt == (int)path.count() ) {
101 nextPt -= 2;
102 rev = TRUE;
103 }
104 } else {
105 nextPt--;
106 if ( nextPt < 0 ) {
107 nextPt = 1;
108 rev = FALSE;
109 }
110 }
111
112 hideDot = FALSE;
113 repaint( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2,
114 dot.width(), dot.height() );
115 hideDot = TRUE;
116 repaint( ox+path[oldPt].x()-dot.width()/2, oy+path[oldPt].y()-dot.height()/2,
117 dot.width(), dot.height() );
118}
119
120void SyncDialog::loadPath()
121{
122 QString pfile = Resource::findPixmap( "syncdot" );
123 if ( pfile.isEmpty() )
124 return;
125 int dp = pfile.findRev('.');
126 pfile.replace( dp, pfile.length()-dp, ".path" );
127
128 int count = 0;
129 QFile file( pfile );
130 if ( file.open( IO_ReadOnly ) ) {
131 QString line;
132 while ( file.readLine( line, 256 ) > 0 ) {
133 int x, y;
134 if ( sscanf( line.latin1(), "%d %d", &x, &y ) == 2 ) {
135 path.resize( count+1 );
136 path[count++] = QPoint(x, y);
137 }
138 }
139 }
140}
141
142QPointArray SyncDialog::scalePath( const QPointArray &pa, int xn, int xd, int yn, int yd )
143{
144 QPointArray sa( pa.size() );
145
146 for ( unsigned i = 0; i < pa.count(); i++ ) {
147 int x = xn * pa[int(i)].x() / xd;
148 int y = yn * pa[int(i)].y() / yd;
149 sa[int(i)] = QPoint( x, y );
150 }
151
152 return sa;
153}
154
155QPointArray SyncDialog::generatePath( const QPointArray &pa, int dist )
156{
157 if ( pa.count() < 2 )
158 return pa;
159
160 QPointArray fa;
161 int count = 0;
162 fa.resize( count+1 );
163 fa[count++] = pa[0];
164 for ( unsigned i = 0; i < pa.count()-1; i++ ) {
165 int x1 = pa[int(i)].x();
166 int y1 = pa[int(i)].y();
167 int x2 = pa[int(i+1)].x();
168 int y2 = pa[int(i+1)].y();
169 int dx = x2 - x1;
170 int dy = y2 - y1;
171 int pts = (QMAX(QABS(dx),QABS(dy)) + dist/2 )/dist;
172 for ( int j = 1; j < pts; j++ ) {
173 int x = j * dx / pts;
174 int y = j * dy / pts;
175 fa.resize( count+1 );
176 fa[count++] = pa[int(i)] + QPoint( x, y );
177 }
178 fa.resize( count+1 );
179 fa[count++] = pa[int(i+1)];
180 }
181
182 return fa;
183}
184