/***************************************************************************
                          myfogdlg.cpp  -  description
                             -------------------
    begin                : Thu May 8 2003
    copyright            : (C) 2003 by Harald Krippel
    email                : neuro.harald@surfeu.at
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include <myfogdlg.h>

#include <iostream>
#include <qvariant.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qcolordialog.h>
#include <qcolor.h>

MyFogEditDlg::MyFogEditDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
    : FogEditDlg( parent, name, modal, fl )
{
    point = NULL;
}

/*
 *  Destroys the object and frees any allocated resources
 */
MyFogEditDlg::~MyFogEditDlg()
{
    // no need to delete child widgets, Qt does it all for us
}

void MyFogEditDlg::slotGetData()
{
    if(point != NULL)
    {
      slotGetData(point);
    }
}

void MyFogEditDlg::slotGetData(FolderListItem *i)
{
    char mybuff[256];
    unsigned int colorr;
    unsigned int colorg;
    unsigned int colorb;

    point=i;

    text->setText(i->text(0));

    on->setChecked(i->GetValue("on",i).toInt());
    linear->setChecked(i->GetValue("linear",i).toInt());
    exp->setChecked(i->GetValue("exp",i).toInt());
    exp2->setChecked(i->GetValue("exp2",i).toInt());

    dontcare->setChecked(i->GetValue("dontcare",i).toInt());
    fastest->setChecked(i->GetValue("fastest",i).toInt());
    nicest->setChecked(i->GetValue("nicest",i).toInt());

    density->setText(i->GetValue("density",i));
    start->setText(i->GetValue("start",i));
    end->setText(i->GetValue("end",i));


    strncpy(mybuff,i->GetValue("color",i),8);
    sscanf(mybuff,"%02X%02X%02X",&colorr,&colorg,&colorb);
    mycolor.setRgb(colorr,colorg,colorb);
    if ( mycolor.isValid() )
    {
      QPixmap pix (100,15);
      pix.fill( mycolor );
      color->setPixmap( pix );
    }
//    color->setColor(mycolor);

    qWarning( "MyFogEditDlg::slotGetData(): Geht !" );
}

void MyFogEditDlg::slotEditData()
{
    char mybuff[256];

    point->setText(0,text->text());

    point->SetValue("on", on->isChecked() ? "1" : "0");
    point->SetValue("linear", linear->isChecked() ? "1" : "0");
    point->SetValue("exp", exp->isChecked() ? "1" : "0");
    point->SetValue("exp2", exp2->isChecked() ? "1" : "0");

    point->SetValue("dontcare", dontcare->isChecked() ? "1" : "0");
    point->SetValue("fastest", fastest->isChecked() ? "1" : "0");
    point->SetValue("nicest", nicest->isChecked() ? "1" : "0");

    point->SetValue("density",density->text());
    point->SetValue("start",start->text());
    point->SetValue("end",end->text());

    sprintf(mybuff,"%02X%02X%02X",mycolor.red(),mycolor.green(),mycolor.blue());
    point->SetValue("color",mybuff);

qWarning( "MyFogEditDlg::slotEditData(): Geht !" );
    point->updategl();
}

void MyFogEditDlg::slotEditColor()
{
    QColor tmpcolor = QColorDialog::getColor(mycolor,this, "color dialog" );
        if ( tmpcolor.isValid() ) {
            QPixmap pix (100,15) ;
            pix.fill( tmpcolor );
            color->setPixmap( pix );
            mycolor = tmpcolor;
        }
    qWarning( "MyFogEditDlg::slotEditColor(): Geht !" );
}
