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

zonemap.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of 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 #ifndef ZONEMAP_H
00022 #define ZONEMAP_H
00023 
00024 #include "stylusnormalizer.h"
00025 
00026 #include <qlist.h>
00027 #include <qscrollview.h>
00028 #include <qstring.h>
00029 
00030 extern const int iCITYOFFSET;
00031 
00032 class QImage;
00033 class QComboBox;
00034 class QLabel;
00035 class QTimer;
00036 class QToolButton;
00037 class QListViewItem;
00038 class QListView;
00039 
00040 
00041 class ZoneField
00042 {
00043 public:
00044     ZoneField( const QString & );
00045     void showStructure( void ) const;
00046     inline int x( void ) const { return _x; };
00047     inline int y( void ) const { return _y; };
00048 
00049     inline QString city( void ) const { return strCity; };
00050     inline QString country( void ) const { return strCountry; };
00051     inline QString code( void ) const { return strCountryCode; };
00052 private:
00053     int _x;
00054     int _y;
00055     QString strCountryCode;
00056     QString strCountry;
00057     QString strCity;
00058 };
00059 
00060 class ZoneMap : public QScrollView
00061 {
00062     Q_OBJECT
00063 public:
00064     ZoneMap( QWidget *parent = 0, const char *name = 0 );
00065     ~ZoneMap();
00066     void showZones( void ) const;
00067     QWidget* selectionWidget( QWidget* parent );
00068     // convert between the pixels on the image and the coordinates in the
00069     // database
00070     inline bool zoneToWin( int zoneX, int zoneY, int &winX, int &winY ) const;
00071     inline bool winToZone( int winX, int winY, int &zoneX, int &zoneY ) const;
00072 
00073 public slots:
00074     void slotZoom( bool setZoom );
00075     void slotIllum( bool setIllum );
00076     void slotUpdate( void );
00077     void slotRedraw( void );
00078     void slotFindCity( const QPoint &pos );  // Find the closest city
00079     void changeClock( bool );
00080 
00081 signals:
00082     void signalTz( const QString &newCountry, const QString &newCity );
00083 
00084 protected:
00085     virtual void viewportMouseMoveEvent( QMouseEvent *event );
00086     virtual void viewportMousePressEvent( QMouseEvent *event );
00087     virtual void viewportMouseReleaseEvent( QMouseEvent *event );
00088     virtual void keyPressEvent( QKeyEvent * );
00089     virtual void resizeEvent( QResizeEvent *);
00090     virtual void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00091 
00092 private slots:
00093     void slotGetCities( QListViewItem * );
00094     void slotCitySelected(  QListViewItem * );
00095 private:
00096     ZoneField *findCityNear( ZoneField *city, int key );
00097     void showCity( ZoneField *city );
00098     void drawCities( QPainter *p );     // put all the cities on the map (ugly)
00099     void drawCity( QPainter *p, const ZoneField *pCity ); // draw the given city on the map
00100     void readZones( void ); // Read in the zone information from the file
00101     void zoom( void );  // Zoom the map...
00102     void makeMap( int width, int height );
00103     QPixmap* pixCurr; // image to be drawn on the screen
00104     QLabel* lblCity;    // the "tool-tip" that shows up when you pick a city...
00105     QToolButton *cmdZoom;   // our zoom option...
00106     QTimer*     tHide;  // the timer to hide the "tool tip"
00107     ZoneField *pLast;   // the last known good city that was found...
00108     ZoneField *pRepaint; // save the location to maximize the repaint...
00109     QList<ZoneField> zones; // a linked list to hold all this information
00110     StylusNormalizer norm;
00111 
00112     QListView *cityView;
00113     QString selectedCont;
00114 
00115     //the True width and height of the map...
00116     int wImg;
00117     int hImg;
00118     // the pixel points that correspond to (0, 0);
00119     int ox;
00120     int oy;
00121 
00122     // the drawable area of the map...
00123     int drawableW;
00124     int drawableH;
00125 
00126     bool bZoom; // a flag to indicate zoom is active
00127     bool bIllum;    // flag to indicat that illumination is active
00128     bool ampm;
00129 
00130     ZoneField *cursor;
00131 };
00132 
00133 inline bool ZoneMap::zoneToWin( int zoneX, int zoneY,
00134                                 int &winX, int &winY ) const
00135 {
00136     winY = oy - ( ( hImg * zoneY ) / 648000 );  // 180 degrees in secs
00137     winX = ox + ( ( wImg * zoneX ) / 1296000 ); // 360 degrees in secs
00138     // whoa, some things aren't in the best spots..
00139     if ( winX > wImg ) {
00140         winX = wImg - iCITYOFFSET;
00141     } else if ( winX <= 0 ) {
00142         winX = iCITYOFFSET;
00143     }
00144 
00145     if ( winY >= hImg ) {
00146         winY = hImg - iCITYOFFSET;
00147     } else if ( winY <= 0 ) {
00148         winY = iCITYOFFSET;
00149     }
00150     // perhaps in the future there will be some real error checking
00151     // for now just return true...
00152     return true;
00153 }
00154 
00155 inline bool ZoneMap::winToZone( int winX, int winY,
00156                                 int &zoneX, int &zoneY ) const
00157 {
00158     zoneY = ( 648000 * ( oy - winY ) ) / hImg;
00159     zoneX = ( 1296000 * ( winX - ox ) ) / wImg;
00160     // perhaps in the future there will be some real error checking
00161     // for now just return true...
00162     return true;
00163 }
00164 
00165 #endif

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