/***************************************************************************
                          mylampdlg.cpp  -  description
                             -------------------
    begin                : Mon Feb 10 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 "mylampdlg.h"

#include <iostream>

#include <qvariant.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qcolordialog.h>
#include <qcolor.h>
   
MyLampEditDlg::MyLampEditDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
    : LampEditDlg( parent, name, modal, fl )
{
    point = NULL;  
}

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

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

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

    text->setText(i->text(0));
    lensflare->setChecked(i->GetValue("lensflare",i).toInt());
    on->setChecked(i->GetValue("on",i).toInt());
    Headlight->setChecked(i->GetValue("headlight",i).toInt());
    Spotlight->setChecked(i->GetValue("spotlight",i).toInt());

    locx->setText(i->GetValue("x",i));
    locy->setText(i->GetValue("y",i));
    locz->setText(i->GetValue("z",i));
    
    slocx->setText(i->GetValue("sx",i));
    slocy->setText(i->GetValue("sy",i));
    slocz->setText(i->GetValue("sz",i));

    sdiffexpo->setText(i->GetValue("sdexpo",i));
    sdiffcutoff->setText(i->GetValue("sdcut",i));

    sconst->setText(i->GetValue("sconst",i));
    slinear->setText(i->GetValue("slinear",i));
    squadratic->setText(i->GetValue("squadratic",i));

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

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

    strncpy(mybuff,i->GetValue("color_spe",i),8);
    sscanf(mybuff,"%02X%02X%02X",&colorr,&colorg,&colorb);
    mycolor_spe.setRgb(colorr,colorg,colorb);
    if ( mycolor_spe.isValid() )
    {
      QPixmap pix (100,15);
      pix.fill( mycolor_spe );
      color_spe->setPixmap( pix );
    }
    
    qWarning( "MyLampEditDlg::slotGetData(): Geht !" );
}

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

    point->setText(0,text->text());
    
    point->SetValue("lensflare",  lensflare->isChecked() ? "1" : "0");
    point->SetValue("on", on->isChecked() ? "1" : "0");
    point->SetValue("headlight", Headlight->isChecked() ? "1" : "0");
    point->SetValue("spotlight", Spotlight->isChecked() ? "1" : "0");

    point->SetValue("x",locx->text());
    point->SetValue("y",locy->text());
    point->SetValue("z",locz->text());

    point->SetValue("sx",slocx->text());
    point->SetValue("sy",slocy->text());
    point->SetValue("sz",slocz->text());

    point->SetValue("sdexpo",sdiffexpo->text());
    point->SetValue("sdcut",sdiffcutoff->text());

    point->SetValue("sconst",sconst->text());
    point->SetValue("slinear",slinear->text());
    point->SetValue("squadratic",squadratic->text());

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

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

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

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

void MyLampEditDlg::slotEditColorAmb()
{
    QColor color = QColorDialog::getColor(mycolor_amb,this, "color dialog" );
        if ( color.isValid() ) {
            QPixmap pix (100,15) ;
            pix.fill( color );
            color_amb->setPixmap( pix );
            mycolor_amb = color;
        }
    qWarning( "MyLampEditDlg::slotEditColorAmb(): Geht !" );
}

void MyLampEditDlg::slotEditColorDif()
{
    QColor color = QColorDialog::getColor(mycolor_dif,this, "color dialog" );
        if ( color.isValid() ) {
            QPixmap pix (100,15) ;
            pix.fill( color );
            color_dif->setPixmap( pix );
            mycolor_dif = color;
        }
    qWarning( "MyLampEditDlg::slotEditColorDif(): Geht !" );
}

void MyLampEditDlg::slotEditColorSpe()
{
    QColor color = QColorDialog::getColor(mycolor_spe,this, "color dialog" );
        if ( color.isValid() ) {
            QPixmap pix (100,15) ;
            pix.fill( color );
            color_spe->setPixmap( pix );
            mycolor_spe = color;
        }
    qWarning( "MyLampEditDlg::slotEditColorSpe(): Geht !" );
}
