/***************************************************************************
                          myguiinputdlg.cpp  -  description
                             -------------------
    begin                : Wed Jun 23 2004
    copyright            : (C) 2004 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 "myguiinputdlg.h"

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

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

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

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

void MyGUIInputEditDlg::slotGetData(FolderListItem *i)
{
    int myplace=0;
    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());

    locx->setText(i->GetValue("x",i));
    locy->setText(i->GetValue("y",i));
//    locz->setText(i->GetValue("z",i));

    // place
    myplace = i->GetValue("place",i).toInt();

    switch (myplace)
    {
      case 0:
          upperleft->setChecked( TRUE );
      break;
      case 1:
          upperright->setChecked( TRUE );
      break;
      case 2:
          lowerright->setChecked( TRUE );
      break;
      case 3:
          lowerleft->setChecked( TRUE );
      break;
      case 4:
          center->setChecked( TRUE );
      break;
    }

    maxx->setText(i->GetValue("maxx",i));
    maxy->setText(i->GetValue("maxy",i));

    label->setText(i->GetValue("label",i));

    strncpy(mybuff,i->GetValue("colorlabel",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 );
      colorlabel->setPixmap( pix );
    }

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

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

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

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

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

    // myplace
    if(upperleft->isChecked())
      point->SetValue("place","0");
    if(upperright->isChecked())
      point->SetValue("place","1");
    if(lowerright->isChecked())
      point->SetValue("place","2");
    if(lowerleft->isChecked())
      point->SetValue("place","3");
    if(center->isChecked())
      point->SetValue("place","4");

    point->SetValue("maxx",maxx->text());
    point->SetValue("maxy",maxy->text());

    point->SetValue("label",label->text());

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

    point->updategl();

    qWarning( "MyGUIInputEditDlg::slotEditData(): Geht !" );
}

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