/***********************************************************************
**
**   wpinfowidget.h
**
**   This file is part of Cumulus.
**
************************************************************************
**
**   Copyright (c):  2002 by André Somers
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: wpinfowidget.h,v 1.9 2004/04/24 21:10:06 andre Exp $
**
***********************************************************************/

#ifndef WPINFOWIDGET_H
#define WPINFOWIDGET_H

#include <qwidget.h>
#include <qtimer.h>
#include <qtextview.h>
#include <qpushbutton.h>
#include "cumulusapp.h"
#include "wp.h"
#include <qlayout.h>


#define SECONDS_OPEN 7

/**This widget provides a view to the details of a waypoint.
  *@author André Somers
  */

class CumulusApp;

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

  /** This method is called by CumulusApp to set the view to which there must be returned and the waypoint to view. */
  bool showWP(int lastView, const wayPoint * wp=0);

private: // Private attributes
  /** This is the object that actually contains the info we want to represent. */
  QTextView * text;
  /**  */
  QPushButton * cmdClose;
  /**  */
  QPushButton * cmdKeep;
  QPushButton * cmdAddWaypoint;
  QPushButton * cmdSetHome;
  QPushButton * cmdSelectWaypoint;
  QPushButton * cmdUnselectWaypoint;
  
  /** Reference to a timer. When this timer fires, the view is returned to the previous one. This allow for a brief display of data (i.e.: what is the freqency of my target field?) after wich the view is automaticly returned to the last one. */
  QTimer * timer;
  /** TimerCount */
  int _timerCount;
  /** Reference to the waypoint who's details must be written. */
  wayPoint * _wp;
  /** last selected waypoint  */
  wayPoint    myWp;
  /** contains the ID of the last view (the view that called this one) */
  int _lastView;
  /** contains a ref to the parent, the application */
  CumulusApp * cuApp;
  QHBoxLayout * buttonrow1;
  QHBoxLayout * buttonrow2;
  
private slots: // Private slots
  /** This slot get called on the timer timeout. */
  void slot_timeout();
  /** This slot is called if the Add as Waypoint button is clicked. */
  void slot_addAsWaypoint();
  /** This slot is called if the Home button is clicked. */
  void slot_setAsHome();
  /** This slot is called if the Select Waypoint button is clicked. */
  void slot_selectWaypoint();
  /** This slot is called if the Unselect Waypoint button is clicked. */
  void slot_unselectWaypoint();
public slots: //Public slots
  /** No descriptions */
  void slotSwitchBack();
  /** This slot is called by the KeepOpen button to... yes... keep the dialog open. :-) */
  void slot_KeepOpen();

private: // Private methods
/** get back the current state of cumlus. In flight true, otherwise false */
  bool inFlight();

private: // Private methods
  /** This method actually fills the widget with the info. */
  void writeText();
signals: // Signals
  /** Emitted if a waypoint has been added to the list. */
  void waypointAdded(wayPoint * wp);
  /** Emitted if a waypoint has been selected. */
  void waypointSelected(wayPoint*);
  /** Emitted if a new home position is selected */
  void newHomePosition(const QPoint*);
};

#endif
