summaryrefslogtreecommitdiff
path: root/core/settings/citytime/zonemap.h
Unidiff
Diffstat (limited to 'core/settings/citytime/zonemap.h') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/zonemap.h157
1 files changed, 157 insertions, 0 deletions
diff --git a/core/settings/citytime/zonemap.h b/core/settings/citytime/zonemap.h
new file mode 100644
index 0000000..c9c2035
--- a/dev/null
+++ b/core/settings/citytime/zonemap.h
@@ -0,0 +1,157 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of 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#ifndef ZONEMAP_H
22#define ZONEMAP_H
23
24#include "stylusnormalizer.h"
25
26#include <qlist.h>
27#include <qscrollview.h>
28#include <qstring.h>
29
30extern const int iCITYOFFSET;
31
32class QImage;
33class QComboBox;
34class QLabel;
35class QTimer;
36class QToolButton;
37
38
39
40class ZoneField
41{
42public:
43 ZoneField( const QString & );
44 void showStructure( void ) const;
45 inline int x( void ) const { return _x; };
46 inline int y( void ) const { return _y; };
47
48 inline QString city( void ) const { return strCity; };
49 inline QString country( void ) const { return strCountry; };
50 inline QString code( void ) const { return strCountryCode; };
51private:
52 int _x;
53 int _y;
54 QString strCountryCode;
55 QString strCountry;
56 QString strCity;
57};
58
59class ZoneMap : public QScrollView
60{
61 Q_OBJECT
62public:
63 ZoneMap( QWidget *parent = 0, const char *name = 0 );
64 ~ZoneMap();
65 void showZones( void ) const;
66 // convert between the pixels on the image and the coordinates in the
67 // database
68 inline bool zoneToWin( int zoneX, int zoneY, int &winX, int &winY ) const;
69 inline bool winToZone( int winX, int winY, int &zoneX, int &zoneY ) const;
70
71public slots:
72 void slotZoom( bool setZoom );
73 void slotIllum( bool setIllum );
74 void slotUpdate( void );
75 void slotRedraw( void );
76 void slotFindCity( const QPoint &pos ); // Find the closest city
77 void changeClock( bool );
78
79signals:
80 void signalTz( const QString &newCountry, const QString &newCity );
81
82protected:
83 virtual void viewportMouseMoveEvent( QMouseEvent *event );
84 virtual void viewportMousePressEvent( QMouseEvent *event );
85 virtual void viewportMouseReleaseEvent( QMouseEvent *event );
86 virtual void keyPressEvent( QKeyEvent * );
87 virtual void resizeEvent( QResizeEvent *);
88 virtual void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
89
90private:
91 ZoneField *findCityNear( ZoneField *city, int key );
92 void showCity( ZoneField *city );
93 void drawCities( QPainter *p );// put all the cities on the map (ugly)
94 void drawCity( QPainter *p, const ZoneField *pCity ); // draw the given city on the map
95 void readZones( void ); // Read in the zone information from the file
96 void zoom( void ); // Zoom the map...
97 void makeMap( int width, int height );
98 QPixmap* pixCurr; // image to be drawn on the screen
99 QLabel* lblCity; // the "tool-tip" that shows up when you pick a city...
100 QToolButton *cmdZoom; // our zoom option...
101 QTimer*tHide; // the timer to hide the "tool tip"
102 ZoneField *pLast; // the last known good city that was found...
103 ZoneField *pRepaint; // save the location to maximize the repaint...
104 QList<ZoneField> zones; // a linked list to hold all this information
105 StylusNormalizer norm;
106
107 //the True width and height of the map...
108 int wImg;
109 int hImg;
110 // the pixel points that correspond to (0, 0);
111 int ox;
112 int oy;
113
114 // the drawable area of the map...
115 int drawableW;
116 int drawableH;
117
118 bool bZoom; // a flag to indicate zoom is active
119 bool bIllum; // flag to indicat that illumination is active
120 bool ampm;
121
122 ZoneField *cursor;
123};
124
125inline bool ZoneMap::zoneToWin( int zoneX, int zoneY,
126 int &winX, int &winY ) const
127{
128 winY = oy - ( ( hImg * zoneY ) / 648000 ); // 180 degrees in secs
129 winX = ox + ( ( wImg * zoneX ) / 1296000 ); // 360 degrees in secs
130 // whoa, some things aren't in the best spots..
131 if ( winX > wImg ) {
132 winX = wImg - iCITYOFFSET;
133 } else if ( winX <= 0 ) {
134 winX = iCITYOFFSET;
135 }
136
137 if ( winY >= hImg ) {
138 winY = hImg - iCITYOFFSET;
139 } else if ( winY <= 0 ) {
140 winY = iCITYOFFSET;
141 }
142 // perhaps in the future there will be some real error checking
143 // for now just return true...
144 return true;
145}
146
147inline bool ZoneMap::winToZone( int winX, int winY,
148 int &zoneX, int &zoneY ) const
149{
150 zoneY = ( 648000 * ( oy - winY ) ) / hImg;
151 zoneX = ( 1296000 * ( winX - ox ) ) / wImg;
152 // perhaps in the future there will be some real error checking
153 // for now just return true...
154 return true;
155}
156
157#endif