/***************************************************************************
                          mapview.h  -  description
                             -------------------
    begin                : Sun Jul 21 2002
    copyright            : (C) 2002 by Andre Somers
    email                : andre@kflog.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MAPVIEW_H
#define MAPVIEW_H

#include <qwidget.h>
#include <qstatusbar.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qpixmap.h>
#include <qvector.h>
#include "distance.h"
#include "speed.h"
#include "altitude.h"
#include "gpsnmea.h"
#include "cucalc.h"
#include "map.h"
#include <qlayout.h>
#include <qdatastream.h>

/**This is the main view for the application, provinding the map and other usefull inflight information.
  *@author Andre Somers
  */
class MapInfoBox;
class Map;

class MapView : public QWidget  {
   Q_OBJECT
public: 
	MapView(QWidget *parent=0, const char *name=0);
	~MapView();

  /** reference to the map */
  Map * _theMap;
  inline QStatusBar* statusBar () const {return _statusbar; };
  inline MapInfoBox* getAltitudeWidget () const {return _altitude; };
  inline MapInfoBox* getVarioWidget () const {return _vario; };

private: // Private attributes
  /** reference to the heading label */
  MapInfoBox* _heading;
  /** reference to the bearing label */
  MapInfoBox* _bearing;
  /** reference to the relative bearing label */
  QLabel* _rel_bearing;
  /** reference to the distance label */
  MapInfoBox* _distance;
  /** reference to the speed label */
  MapInfoBox* _speed;
  /** reference to the best speed label */
  MapInfoBox* _speed2fly;
  /** reference to the McCready label */
  MapInfoBox* _mc;
  /** reference to the variometer label */
  MapInfoBox* _vario;
  /** reference to the wind label */
  MapInfoBox* _wind;
  /** reference to the waypoint label */
  MapInfoBox* _waypoint;
  /** reference to the flighttime label */
  //MapInfoBox* _flighttime;
  /** reference to the eta label */
  MapInfoBox* _eta;
  /** reference to the altitude label */
  MapInfoBox* _altitude;
  /** reference to the elevation label */
  MapInfoBox* _elevation;
  /** reference to the glide path label */
  MapInfoBox* _glidepath;
  /** reference to statusbar */
  QStatusBar* _statusbar;
  /** reference to GPS status */
  QLabel* _statusGps;
  /** reference to flightstatus, including logging status and flightmode */
  QLabel* _statusFlightstatus;
  /** reference to filler for statusbar */
  QLabel* _statusFiller;
  /** timer to reset font for loggingindicator */
  QTimer* loggingTimer;
  /** index of mode select button 0: MSL,  1: GND */
  int _altimeter_mode;  
  /** last selected waypoint */
  const wayPoint * wp;

  QVector<QWidget> * elements;

  /**
   * Loads a layout definition from the file mentioned in argument @arg name
   */
  bool loadLayout(QString pathName);
  bool loadLayoutElement(QDataStream& in, QBoxLayout * l);
  QWidget * getElement(int typeID, bool resetLineCounter);

public slots: // Public slots
  /** Called if speed has changed */
  void slot_Speed(const Speed& speed);
  /** called if heading has changed */
  void slot_Heading(int head);
  /** called if the waypoint is changed in the calculator */
  void slot_Waypoint(const QString& wpName);
  /** This slot is called by calculator if a new ETA (Estimated Time to Arrival, or the time that is approximatly needed to arrive at the waypoint) has been calculated. */
  void slot_ETA(const QTime& eta);
  /** This slot is called by calculator if a new distance has been calculated. */
  void slot_Distance(const Distance& distance);
  /** This slot is called by calculator if a new bearing has been calculated */
  void slot_Bearing(int bearing);
  /** This slot is called by calculator if a new relative bearing has been calculated */
  void slot_RelBearing(int relbearing);
  /** This slot is called if a new positionfix has been established. */
  void slot_Position(const QPoint& position);
  /** This slot is called if a logentry has been made. */
  void slot_LogEntry();
  /** This slot is called if the status of the GPS changes. */
  void slotGPSStatus(GPSNMEA::connectedStatus status);
  /** This slot is called if the number of satelites changes. */
  void slotSatConstellation();
  /** This slot is being called if the altitude has changed. */
  void slot_Altitude(const Altitude& alt);
  /** This slot is changed when the "above glide path" value has changed */
  void slot_GlidePath (const Altitude& above);
  /** This slot is changed when the best speed value has changed */
  void slot_bestSpeed (const Speed& above);
  /** This slot is called if a new McCready value has been set */
  void slot_Mc (const Speed& mc);
  /** This slot is called if a new variometer value has been set */
  void slot_vario (const Speed& vario);
  /** This slot is called if a new wind value has been set */
  void slot_wind (Vector& wind);
  /** This slot is called if the settings have been changed. It refreshes all displayed data because units might have beeen changed. */
  void slot_settingschange();
  /** Format and set the FlightStatus string */
  void setFlightStatus();

private slots:

  /** toggle between distance and eta widget on mouse signal */
  void slot_toggleDistanceEta();

private: // Private methods
  QPixmap _arrows;
  
};

#endif
