#ifndef OPERATORDIALOG_H
#define OPERATORDIALOG_H

#include <QDialog>
#include <QGraphicsScene>
#include <QPolygonF>
#include <QGraphicsTextItem>
#include <QGraphicsItemGroup>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QGraphicsEllipseItem>

#include "graphicsScene.h"
#include "mPathItem.h"
#include "chartGraphicsItem.h"
#include "buttonX.h"

//	----------------------------------------------------------------------------
//  xyz combo knob modes
//	----------------------------------------------------------------------------

enum{
	XYZ_Camera = 0,
	XYZ_Altitude,
};

//	----------------------------------------------------------------------------
//  xyz combo knob modes
//	----------------------------------------------------------------------------

enum{
	JSZ_Roll = 0,
	JSZ_Altitude,
};

//	----------------------------------------------------------------------------
//  numTargetHistory
//	----------------------------------------------------------------------------

enum{
	maxTargetHistory = 10,
};

//	----------------------------------------------------------------------------
//  button ids
//	----------------------------------------------------------------------------

enum{
	B_xyzButton_ = 0,
	B_irisButton_,
	B_focusButton_,
	B_menuButton_,
	B_alarmButton_,
	B_insButton_,
	B_geoAltButton_,
	B_stowButton_,
	B_zoomButton_,
	B_zmulButton_,
	B_wrapButton_,
	B_wrapMapButton_,
	B_dynButton_,
	B_losPanButton_,
	B_camButton_,
	B_panButton_,
	B_tiltButton_,
	B_rollButton_,
	B_losTiltButton_,
	B_wrapPoly01_,
	B_wrapPoly02_,
	B_wrapMapPoly01_,
	B_wrapMapPoly02_,
	B_losPanPoly_,
	B_losTiltPoly_,
	B_zoomPoly_,
	B_redPoly_,
	B_yellowPoly_,
	B_greenPoly_,
	B_bluePoly_,
	B_mapButton_,
	B_exitButton_,
	B_sliderPoly_,
	B_menuBox_,
	B_menuButton_01_,
	B_menuButton_02_,
	B_menuButton_03_,
	B_menuButton_04_,
	B_menuButton_05_,
	B_menuButton_06_,
	B_menuButton_07_,
	B_menuButton_08_,
	B_menuTBox_,
	B_menuTButton_01_,
	B_menuTButton_02_,
	B_menuTButton_03_,
	B_menuTButton_04_,
	B_shutdownBox_,
	B_shutdownButton_01_,
	B_shutdownButton_02_,
	B_shutdownButton_03_,
	B_shutdownButton_04_,
	B_modemenuButton_,
	B_modemenuBox_,
	B_modemenuButton_Rate_,
	B_modemenuButton_Slave_,
	B_modemenuButton_Geo_,
	B_modemenuButton_Outer_,
	B_modemenuButton_Stow_,
	B_modemenuButton_Standby_,
	B_geomenuBox_,
	B_geomenuButton_New_,
	B_geomenuButton_Prev_,
	B_geomenuButton_Alt_,
	B_geomenuButton_Targets_,
	B_mapButton_Exit_,
	B_mapButton_Load_,
	B_mapButton_Sat_,
	B_mapButton_Select_,
	B_mapButton_Hist_,
	B_mapButton_Mode_,
	B_mapButton_Alt_,
	B_mapButton_Aid_,
	B_geoTargetButton_01_,
	B_geoTargetButton_02_,
	B_geoTargetButton_03_,
	B_geoTargetButton_04_,
	B_geoTargetButton_05_,
	B_geoTargetButton_06_,
	B_geoTargetButton_07_,
	B_geoTargetButton_08_,
	B_geoTargetButton_09_,
	B_geoTargetButton_10_,
	B_geoTargetButton_11_,
	B_geoTargetButton_12_,
	B_geoTargetButton_13_,
	B_geoTargetButton_14_,
	B_geoTargetButton_15_,
	B_geoTargetButton_16_,
	B_acposButton_,
	B_acpos1Button_,
	B_acpos2Button_,
	B_geoTwoPointButton_,
	B_geoTargetButton_,
	B_geoPassiveButton_,
	B_simWaypoint1Button_,
	B_simWaypoint2Button_,
	B_geoTarget2Button_01_,
	B_geoTarget2Button_02_,
	B_geoTarget2Button_03_,
	B_geoTarget2Button_04_,
	B_geoTarget2Button_05_,
	B_geoTargetSButton_01_,
	B_geoTargetSButton_02_,
	B_geoTargetSButton_03_,
	B_geoTargetSButton_04_,
	B_geoTargetSButton_05_,
	B_aidButton_,
};

//	----------------------------------------------------------------------------
//  steering_t
//	----------------------------------------------------------------------------

	extern steering_t steeringOut;
	extern int cmdSteering;

//	----------------------------------------------------------------------------
//  gimReadouts_t
//	----------------------------------------------------------------------------

typedef struct {
	float zoom;
	float iris;
	float focus;
	float yaw;
	float pitch;
	float roll;
	float losPan;
	float losTilt;
	float wrap;
	int mode;
	int modeX;
	int standby;
	uint32_t buttons;
	double lat;
	double lon;
	double alt;
	double targetLat;
	double targetLon;
	double targetAlt;
	double passiveLat;
	double passiveLon;
	float ypr[3];
	float yprA[3];
	float xyCamera[2];
	float xyTarget[2];
	float range;
	float rangeP;
	float dxTarget;
	float dyTarget;
	float dzTarget;
	int simOn;
	int insStatus;
	int vnFreq;
	float angleDif[3];
} gimReadouts_t;

extern gimReadouts_t gimReadouts;

//	----------------------------------------------------------------------------
//  operControls_t
//	----------------------------------------------------------------------------

typedef struct {
	float zoom;
	float iris;
	float focus;
	uint32_t stow;
	uint32_t slave;
	uint32_t zmult;
} operControls_t;

extern operControls_t operControls;

//	----------------------------------------------------------------------------
//  operSettings_t
//	----------------------------------------------------------------------------

typedef struct {
	float panGain;
	float tiltGain;
	float rollGain;
	float dynGain;
	float zoomGain;
	float focusGain;
	float zmultGain;
	double geoLat;
	double geoLon;
	float geoAlt;
	uint32_t panRev;
	uint32_t tiltRev;
	uint32_t rollRev;
	uint32_t zoomRev;
	uint32_t irisRev;
	uint32_t focusRev;
	uint32_t dynOn;
	uint32_t zmultOn;
	uint32_t mode;
	uint32_t encFunction;
	uint32_t jzFunction;
	uint32_t geoAid;
	double llaS1[3];
	double llaS2[3];
	double llaS3[3];
	double llaS4[3];
	double llaS5[3];
} operSettings_t;

extern operSettings_t operSettings;

//	----------------------------------------------------------------------------
//  joystickT_t
//	----------------------------------------------------------------------------

typedef struct {
	float jsPan;
	float jsTilt;
	float jsRoll;
	uint32_t button1;
	uint32_t button2;
} joystickT_t;

extern joystickT_t joystickT;

//	----------------------------------------------------------------------------
//  consInput
//	----------------------------------------------------------------------------

extern int consInputRxCount;
extern consInput_t consInput;

//	----------------------------------------------------------------------------
//	operatorDialog
//	----------------------------------------------------------------------------

namespace Ui {
class operatorDialog;
}

//	----------------------------------------------------------------------------
//	operatorDialog
//	----------------------------------------------------------------------------

class operatorDialog : public QDialog
{
	Q_OBJECT

public:
	explicit operatorDialog(QWidget *parent = 0);
	~operatorDialog();

public:
	void init();
	void initLabels();
	void popMenu(int id);
	void popMenu1(int id);
	void exitMenu();
	void settingsFromButtons();
	void makeSliderKnob();
	void makeModeMenu(float xmenu, float ymenu);
	void makeTargetMenu(float xmenu, float ymenu);
	buttonX *makeButton(
			float x,
			float y,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	buttonX *makeButton2(
			float x,
			float y,
			float h,
			float w,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	buttonX *makeButton3(
			int type,
			float x,
			float y,
			float h,
			float w,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	buttonX *makeSlider(
			float x,
			float y,
			float h,
			float w,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	buttonX *makeArc(
			float x,
			float y,
			float r1,
			float r2,
			float a1,
			float a2,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	buttonX *makeRing(
			float x,
			float y,
			float r1,
			float r2,
			int color,
			int id,
			QString t1,
			QString t2,
			QString t3,
			QFont f,
			int group
			);
	void centerText(QGraphicsTextItem *g,QString s);
	void centerText(QGraphicsTextItem *g,QString s,float offset);
	void mapReadout();
	void insReadout();
	void makeMapLos();
	void drawMapLos();
	void makeMapL1();
	void drawMapL1();
	void makeMapL2();
	void drawMapL2();
	void makeGeoPoly();
	void drawGeoPoly();
	int isViz(int id);
	void pushHistory();

//private slots:
	void readouts();
	void timed();
	void greyOut();
private:
	int hoverId;
	int menuID;

private:

	buttonX *xyzButton;
	buttonX *irisButton;
	buttonX *focusButton;
	buttonX *zoomButton;
	buttonX *zmulButton;
	buttonX *menuButton;
	buttonX *modeButton;
	buttonX *aidButton;
	buttonX *alarmButton;
	buttonX *insButton;
	buttonX *geoAltButton;
	buttonX *stowButton;
	buttonX *wrapButton;
	buttonX *wrapMapButton;
	buttonX *dynButton;
	buttonX *losPanButton;
	buttonX *camButton;
	buttonX *panButton;
	buttonX *tiltButton;
	buttonX *rollButton;
	buttonX *losTiltButton;

	buttonX *wrapPoly01;
	buttonX *wrapPoly02;
	buttonX *wrapMapPoly01;
	buttonX *wrapMapPoly02;
	buttonX *losPanPoly;
	buttonX *losTiltPoly;
	buttonX *zoomPoly;

	buttonX *redButton;
	buttonX *yellowButton;
	buttonX *greenButton;
	buttonX *blueButton;

	buttonX *mapButton;
	buttonX *exitButton;

	buttonX *sliderButton;
	buttonX *sliderButton01;
	buttonX *sliderButton02;
	buttonX *menuBox;
	buttonX *menuButton01;
	buttonX *menuButton02;
	buttonX *menuButton03;
	buttonX *menuButton04;
	buttonX *menuButton05;
	buttonX *menuButton06;
	buttonX *menuButton07;
	buttonX *menuButton08;
	buttonX *menuTBox;
	buttonX *menuTButton01;
	buttonX *menuTButton02;
	buttonX *menuTButton03;
	buttonX *menuTButton04;
	buttonX *shutdownBox;
	buttonX *shutdownButton01;
	buttonX *shutdownButton02;
	buttonX *shutdownButton03;
	buttonX *shutdownButton04;
	buttonX *modemenuBox;
	buttonX *modemenuButton_Rate;
	buttonX *modemenuButton_Slave;
	buttonX *modemenuButton_Geo;
	buttonX *modemenuButton_Outer;
	buttonX *modemenuButton_Stow;
	buttonX *modemenuButton_Standby;
	buttonX *geomenuBox;
	buttonX *geomenuButton_New;
	buttonX *geomenuButton_Prev;
	buttonX *geomenuButton_Alt;
	buttonX *geomenuButton_Targets;
	buttonX *mapButton_Exit;
	buttonX *mapButton_Load;
	buttonX *mapButton_Sat;
	buttonX *mapButton_Select;
	buttonX *mapButton_Hist;
	buttonX *mapButton_Mode;
	buttonX *mapButton_Alt;
	buttonX *mapButton_Aid;
	buttonX *geoTargetButton_01;
	buttonX *geoTargetButton_02;
	buttonX *geoTargetButton_03;
	buttonX *geoTargetButton_04;
	buttonX *geoTargetButton_05;
	buttonX *geoTargetButton_06;
	buttonX *geoTargetButton_07;
	buttonX *geoTargetButton_08;
	buttonX *geoTargetButton_09;
	buttonX *geoTargetButton_10;
	buttonX *geoTargetButton_11;
	buttonX *geoTargetButton_12;
	buttonX *geoTargetButton_13;
	buttonX *geoTargetButton_14;
	buttonX *geoTargetButton_15;
	buttonX *geoTargetButton_16;
	buttonX *geoTargetSButton_01;
	buttonX *geoTargetSButton_02;
	buttonX *geoTargetSButton_03;
	buttonX *geoTargetSButton_04;
	buttonX *geoTargetSButton_05;
	buttonX *acposButton;
	buttonX *acpos1Button;
	buttonX *acpos2Button;
	buttonX *geoTwoPointButton;
	buttonX *geoTargetButton;
	buttonX *geoPassiveButton;
	buttonX *simWaypoint1Button;
	buttonX *simWaypoint2Button;
	buttonX *geoTarget2Button_01;
	buttonX *geoTarget2Button_02;
	buttonX *geoTarget2Button_03;
	buttonX *geoTarget2Button_04;
	buttonX *geoTarget2Button_05;

	Ui::operatorDialog *ui;
	QGraphicsScene *graphScene;

	mPathItem *sliderKnob;
//	mPathItem *mapLos;
	mPathItem *c1;
	mPathItem *c2;
	QGraphicsPolygonItem *mapLos;
	QGraphicsPolygonItem *mapL1;
	QGraphicsPolygonItem *mapL2;
	QGraphicsPolygonItem *geoPanPoly;
	QGraphicsPolygonItem *geoTiltPoly;

	QGraphicsTextItem insText;

	int nTargetHistory;
	buttonX *targetHistory[maxTargetHistory];

};

#endif // OPERATORDIALOG_H
