/***********************************************************************
**
**   polardialog.cpp
**
**   This file is part of Cumulus
**
************************************************************************
**
**   Copyright (c):  2002 by Eggert Ehmke
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: polardialog.cpp,v 1.10 2003/03/21 21:33:38 eggert Exp $
**
***********************************************************************/

#include "polardialog.h"

PolarDialog::PolarDialog(const Polar* polar, QWidget* parent)
: QDialog (parent, "polardialog", false, Qt::WStyle_StaysOnTop)
{
  showMaximized();
  _polar = const_cast<Polar*>(polar);
  setBackgroundColor (Qt::white);
  setCaption (polar->name());
  acc=new QAccel(this);
  acc->connectItem(acc->insertItem(Key_Up), this, SLOT(slot_keyup()));
  acc->connectItem(acc->insertItem(Key_Down), this, SLOT(slot_keydown()));
  acc->connectItem(acc->insertItem(Key_Up+SHIFT), this, SLOT(slot_shiftkeyup()));
  acc->connectItem(acc->insertItem(Key_Down+SHIFT), this, SLOT(slot_shiftkeydown()));
  acc->connectItem(acc->insertItem(Key_Left), this, SLOT(slot_keyleft()));
  acc->connectItem(acc->insertItem(Key_Right), this, SLOT(slot_keyright()));
  acc->connectItem(acc->insertItem(Key_Space), this, SLOT(slot_keyhome()));
}

PolarDialog::~PolarDialog()
{}

void PolarDialog::slot_keyup()
{
  lift.setMps(lift.getMps()-0.1);
  repaint ();
}

void PolarDialog::slot_keydown()
{
  lift.setMps(lift.getMps()+0.1);
  repaint ();
}

void PolarDialog::slot_shiftkeyup()
{
  mc.setMps(mc.getMps()+0.5);
  repaint ();
}

void PolarDialog::slot_shiftkeydown()
{
  if (mc.getMps() > 0.01)
  {
    mc.setMps(mc.getMps()-0.5);
    repaint ();
  }
}

void PolarDialog::slot_keyleft()
{
  wind.setKph(wind.getKph()+5.0);
  repaint ();
}

void PolarDialog::slot_keyright()
{
  wind.setKph(wind.getKph()-5.0);
  repaint ();
}

void PolarDialog::slot_keyhome()
{
  wind.setKph(0.0);
  lift.setMps(0.0);
  repaint ();
}

void PolarDialog::paintEvent (QPaintEvent*)
{
  _polar->drawPolar(this, wind, lift, mc);
}
