/***************************************************************************
                          listviews.cpp  -  description
                             -------------------
    begin                : Mon Mär 3 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 "listviews.h"
#include "glcontrol.h"
//#include <qobjectlist.h>
#include <qpopupmenu.h>

// Dialogboxes
#include <mylampdlg.h>
#include <myobjdlg.h>
#include <mycameradlg.h>
#include <myfiredlg.h>
#include <mypartsysdlg.h>
#include <mywavesysdlg.h>
#include <myfogdlg.h>
#include <myplayerdlg.h>
#include <mybarrierdlg.h>
#include <mybodydlg.h>
#include <myskydlg.h>
#include <mysounddlg.h>
#include <myguitxtdlg.h>
#include <myguibuttondlg.h>
#include <myguiosbuttondlg.h>
#include <myguiinputdlg.h>
#include <myterraindlg.h>
#include <myshaderdlg.h>
#include <mycursordlg.h>
#include <cursor3d.h>

FolderListItem::FolderListItem( QListView * parent )
  :QListViewItem( parent )
{
      gl         = NULL;
      objtrans   = NULL;
      light      = NULL;
      fire       = NULL;
      dialog     = NULL;
      wavesys    = NULL;
      dialog     = NULL;
      player     = NULL;
      barrier    = NULL;
      body       = NULL;
      sky        = NULL;
      splprog    = NULL;
      guitext    = NULL;
      guibutton  = NULL;
      guiosbutton= NULL;
      guiinput   = NULL;
      sound      = NULL;
      client     = NULL;
      tribarrier = NULL;      
      usercam    = NULL;
      gshader    = NULL;
      cursor     = NULL;
      
      groundcollision=0;
      collision = 0;
      
}

FolderListItem::FolderListItem( FolderListItem * parent )
  :QListViewItem( parent )
{
      gl         = NULL;
      objtrans   = NULL;
      light      = NULL;
      fire       = NULL;
      dialog     = NULL;
      wavesys    = NULL;
      dialog     = NULL;
      player     = NULL;
      barrier    = NULL;
      body       = NULL;
      sky        = NULL;
      splprog    = NULL;
      guitext    = NULL;
      guibutton  = NULL;
      guiosbutton= NULL;
      guiinput   = NULL;
      sound      = NULL;
      client     = NULL;
      tribarrier = NULL;
      usercam    = NULL;
      gshader    = NULL;
      cursor     = NULL;

      groundcollision=0;
      collision = 0;
}

FolderListItem::FolderListItem( QListView * parent, FolderListItem * after )
  :QListViewItem( parent , after )  
{
      gl         = NULL;
      objtrans   = NULL;
      light      = NULL;
      fire       = NULL;
      dialog     = NULL;
      wavesys    = NULL;
      dialog     = NULL;
      player     = NULL;
      barrier    = NULL;
      body       = NULL;
      sky        = NULL;
      splprog    = NULL;
      guitext    = NULL;
      guibutton  = NULL;
      guiosbutton= NULL;
      guiinput   = NULL;
      sound      = NULL;
      client     = NULL;
      tribarrier = NULL;
      usercam    = NULL;
      gshader    = NULL;
      cursor     = NULL;

      groundcollision=0;
      collision = 0;
}

FolderListItem::FolderListItem( FolderListItem * parent, FolderListItem * after )
  :QListViewItem( parent , after )
{
      gl         = NULL;
      objtrans   = NULL;
      light      = NULL;
      fire       = NULL;
      dialog     = NULL;
      wavesys    = NULL;
      dialog     = NULL;
      player     = NULL;
      barrier    = NULL;
      body       = NULL;
      sky        = NULL;
      splprog    = NULL;
      guitext    = NULL;
      guibutton  = NULL;
      guiosbutton= NULL;
      guiinput   = NULL;
      sound      = NULL;
      client     = NULL;
      tribarrier = NULL;
      usercam    = NULL;
      gshader    = NULL;
      cursor     = NULL;

      groundcollision=0;
      collision = 0;
}



void FolderListItem::updategl()
{
    if(strstr(this->text(1),"LAMP") != NULL)
    {
            qWarning(  "update light " );

            // Lensflare  
            if(gl != NULL)
            {
              gl->setFocusLamp(this);
            }
    }
    
    if(strstr(this->text(1),"FIRE") != NULL)
    {
      if(objtrans != NULL && fire != NULL)
      {
            qWarning(  "update fire " );

            if(gl != NULL)
            {
              gl->setFocusFire(this);
            }
      }
    }    
    if(strstr(this->text(1),"OBJECT") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update OBJECT " );
            if(gl != NULL)
            {
              gl->setFocusObject(this);
            }
      }
    }
    if(strstr(this->text(1),"BARRIER") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update BARRIER " );
            if(gl != NULL)
            {
              gl->setFocusBarrier(this);
            }
      }
    }
    if(strstr(this->text(1),"BODY") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update BODY " );
            if(gl != NULL)
            {
              gl->setFocusBody(this);
            }
      }
    }
    if(strstr(this->text(1),"PARTSYS") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update PARTSYS " );
            if(gl != NULL)
            {
              gl->setFocus(this);
            }
      }
    }
    if(strstr(this->text(1),"WAVESYS") != NULL)
    {
      if(objtrans != NULL && wavesys != NULL)
      {
            qWarning(  "update WAVESYS " );
            if(gl != NULL)
            {
              gl->setFocusWaveSys(this);
            }
      }
    }
    if(strstr(this->text(1),"CAMERA") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update CAMERA " );
            if(gl != NULL)
            {
              gl->setFocusCamera(this);
            }
      }
    }

    if(strstr(this->text(1),"FOG") != NULL)
    {
            qWarning(  "update FOG " );
            if(gl != NULL)
            {
              gl->setFocusFog(this);
            }
    }

    if(strstr(this->text(1),"PLAYER") != NULL)
    {
      if(objtrans != NULL )
      {
            qWarning(  "update PLAYER " );
            if(gl != NULL)
            {
              gl->setFocusPlayer(this);
            }
      }
    }

    if(strstr(this->text(1),"SKY") != NULL)
    {
      if(sky != NULL )
      {
            qWarning(  "update SKY " );
            if(gl != NULL)
            {
              gl->setFocusSky(this);
            }
      }
    }

    if(strstr(this->text(1),"TERRAIN") != NULL)
    {
      if(terrain != NULL )
      {
            qWarning(  "update Terrain " );
            if(gl != NULL)
            {
              gl->setFocusTerrain(this);
            }
      }
    }

    if(strstr(this->text(1),"SCENE") != NULL)
    {
            qWarning(  "update SCENE " );
            if(gl != NULL)
            {
              gl->setFocusScene(this);
            }
    }

    if(strstr(this->text(1),"SOUND") != NULL)
    {
            qWarning(  "update SOUND " );
            if(gl != NULL)
            {
              gl->setFocusSound(this);
            }
    }
    
    if(strstr(this->text(1),"SPL") != NULL)
    {
            qWarning(  "update SPL " );
            if(gl != NULL)
            {
              gl->setFocusSPL(this);
            }
    }

    if(strstr(this->text(1),"SHADER") != NULL)
    {
            qWarning(  "update SHADER " );
            if(gl != NULL)
            {
              gl->setFocusShader(this);
            }
    }

    if(strstr(this->text(1),"CURSOR") != NULL)
    {
            qWarning(  "update CURSOR " );
            if(gl != NULL)
            {
              gl->setFocusCursor(this);
            }
    }

    if(strstr(this->text(1),"GUI-TXT") != NULL)
    {
            qWarning(  "update GUI-TXT " );
            if(gl != NULL)
            {
              gl->setFocusGUIText(this);
            }
    }

    if(strstr(this->text(1),"GUI-INPUT") != NULL)
    {
            qWarning(  "update GUI-INPUT " );
            if(gl != NULL)
            {
              gl->setFocusGUIInput(this);
            }
    }

    if(strstr(this->text(1),"GUI-BUTTON") != NULL)
    {
            qWarning(  "update GUI-BUTTON " );
            if(gl != NULL)
            {
              gl->setFocusGUIButton(this);
            }
    }

    if(strstr(this->text(1),"GUI-OSBUTTON") != NULL)
    {
            qWarning(  "update GUI-OSBUTTON " );
            if(gl != NULL)
            {
              gl->setFocusGUIOSButton(this);
            }
    }

}

void FolderListItem::updateDialog()
{
      if(dialog != NULL)
      {
         if(strstr(this->text(1),"LAMP") != NULL)  
         {
            qWarning(  "update Dialog Lamp " );
            ((MyLampEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"OBJECT") != NULL)  
         {
            qWarning(  "update Dialog OBJECT " );
            ((MyObjEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"CAMERA") != NULL)
         {
            qWarning(  "update Dialog CAMERA " );
            ((MyCameraEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"FIRE") != NULL) 
         {
            qWarning(  "update Dialog Fire " );
            ((MyFireEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"PARTSYS") != NULL)
         {
            qWarning(  "update Dialog PartSys " );
            ((MyPartSysEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"WAVESYS") != NULL)
         {
            qWarning(  "update Dialog WaveSys " );
            ((MyWaveSysEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"FOG") != NULL)
         {
            qWarning(  "update Dialog Fog " );
            ((MyFogEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"PLAYER") != NULL)
         {
            qWarning(  "update Dialog PLAYER " );
            ((MyPlayerEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"BARRIER") != NULL)
         {
            qWarning(  "update Dialog BARRIER " );
            ((MyBarrierEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"BODY") != NULL)
         {
            qWarning(  "update Dialog BODY " );
            ((MyBodyEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"SKY") != NULL)
         {
            qWarning(  "update Dialog SKY " );
            ((MySkyEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"TERRAIN") != NULL)
         {
            qWarning(  "update Dialog TERRAIN " );
            ((MyTerrainEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"SPL") != NULL)
         {
            qWarning(  "update Dialog SPL " );
            ((MyShaderEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"SHADER") != NULL)
         {
            qWarning(  "update Dialog SHADER " );
            ((MyShaderEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"SOUND") != NULL)
         {
            qWarning(  "update Dialog SOUND " );
            ((MySoundEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"CURSOR") != NULL)
         {
            qWarning(  "update Dialog CURSOR " );
            ((MyCursorEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"GUI-TXT") != NULL)
         {
            qWarning(  "update Dialog GUI-TXT " );
            ((MyGUITextEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"GUI-BUTTON") != NULL)
         {
            qWarning(  "update Dialog GUI-BUTTON " );
            ((MyGUIButtonEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"GUI-OSBUTTON") != NULL)
         {
            qWarning(  "update Dialog GUI-OSBUTTON " );
            ((MyGUIOSButtonEditDlg*)dialog)->slotGetData(this);
         }
         if(strstr(this->text(1),"GUI-INPUT") != NULL)
         {
            qWarning(  "update Dialog GUI-INPUT " );
            ((MyGUIInputEditDlg*)dialog)->slotGetData(this);
         }
         updategl();
      }

}

QString FolderListItem::GetValue(const QString & item )
{

    if ( !this )
	      return("");

    QListViewItem *ichild = this->firstChild();

    while(ichild != NULL)
    {
      if(ichild->text(0) == item)
      {
//        qWarning( item + " OK !" );
        return(ichild->text(1));
      }
      ichild=ichild->nextSibling();
    }
    qWarning( item + " nicht gefunden !" );
    return("");
}

QString FolderListItem::GetValue(const QString & item,FolderListItem *i)
{

    if ( !i )
	      return("");

    QListViewItem *ichild = i->firstChild();

    while(ichild != NULL)
    {
      if(ichild->text(0) == item)
      {
//        qWarning( item + " OK !" );
        return(ichild->text(1));
      }
      ichild=ichild->nextSibling();
    }
    qWarning( item + " nicht gefunden !" );
    return("");
}

void FolderListItem::SetValue(const QString & item, const QString & value)
{

    if ( !this )
	      return;

    QListViewItem *ichild = this->firstChild();

    while(ichild != NULL)
    {
      if(ichild->text(0) == item)
      {
//        qWarning( item + " OK !" );
        ichild->setText(1,value);
        return;
      }
      ichild=ichild->nextSibling();
    }
    qWarning( item + " nicht gefunden !" );
    return;
}
void FolderListItem::SetValue(const QString & item, const QString & value, FolderListItem *i)
{

    if ( !i )
	      return;

    QListViewItem *ichild = i->firstChild();

    while(ichild != NULL)
    {
      if(ichild->text(0) == item)
      {
//        qWarning( item + " OK !" );
        ichild->setText(1,value);
        return;
      }
      ichild=ichild->nextSibling();
    }
    qWarning( item + " nicht gefunden !" );
    return;
}




void FolderListItem::addObject(const QString & type)
{
    char mybuff[256];
    FolderListItem *Item;

    qWarning( "addObject " + type );
     FolderListItem *thisItem=new  FolderListItem(this);
     thisItem->setText( 0, "Nonamed");
     thisItem->setText( 1, type );
     sprintf(mybuff,"%ld",g_nextid);
     g_nextid++;
     thisItem->setText( 2, mybuff);
     g_ListItem[g_nextitem] = thisItem;
     g_nextitem++;
     
     if( type == "SCENE")
     {
         thisItem->setText( 0, "Scene X");

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "wgx");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "wgy");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "wgz");
         Item->setText( 1, "-9.81" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cgplane");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "color_back");
         Item->setText( 1, "FFFFFF" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );
     }
     
     if(gl)
     {
       
       if( type == "LAMP")
       {
         thisItem->setText( 0, "Lamp 1");
         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sdexpo");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sdcut");
         Item->setText( 1, "90" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sconst");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "slinear");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "squadratic");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "color_amb");
         Item->setText( 1, "FFFFFF" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "color_dif");
         Item->setText( 1, "FFFFFF" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "color_spe");
         Item->setText( 1, "FFFFFF" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "lensflare");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "headlight");
         Item->setText( 1, "0" );
         
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "spotlight");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sx");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sy");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "number");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );
       }
       
       if( type == "OBJECT")
       {

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "barrier");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->loadObject(thisItem, objtrans);
       }
       

       if( type == "CAMERA")
       {

         thisItem->setText( 0, "Camera");

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "dx");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "dy");
         Item->setText( 1, "0" );
         
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "dz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "fovw");
         Item->setText( 1, "60" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "fovh");
         Item->setText( 1, "60" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "near");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "far");
         Item->setText( 1, "100" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "bind");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camego");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cam2d");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camfix");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camrotw");
         Item->setText( 1, "-90.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camhight");
         Item->setText( 1, "5.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camradius");
         Item->setText( 1, "-10.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "onkey");
         Item->setText( 1, "a" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "camera.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addCamera(thisItem, objtrans);
       }

       if( type == "FIRE")
       {
         thisItem->setText( 0, "Fire");
         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "radius");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "height");
         Item->setText( 1, "5" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "speed");
         Item->setText( 1, "2" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "hotcolor");
         Item->setText( 1, "FF3319" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );
         
         gl->addFire(thisItem, objtrans);         
       }
       if( type == "PARTSYS")
       {
         thisItem->setText( 0, "Particle System");
         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addPartSys(thisItem, objtrans);
       }
       if( type == "WAVESYS")
       {
         thisItem->setText( 0, "Wave System");
         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "size");
         Item->setText( 1, "100" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "texsx");
         Item->setText( 1, "3" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "texsy");
         Item->setText( 1, "3" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "wspeed");
         Item->setText( 1, "10" );
         
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "envmap");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addWaveSys(thisItem, objtrans);
       }
       if( type == "FOG")
       {
         thisItem->setText( 0, "Fog");
//         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "density");
         Item->setText( 1, "0.02" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "linear");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "exp");
         Item->setText( 1, "1" );
         
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "exp2");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "start");
         Item->setText( 1, "2" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "end");
         Item->setText( 1, "100" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "color");
         Item->setText( 1, "FFFFFF" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "dontcare");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "fastest");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "nicest");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );


         gl->addFog(thisItem);
       }
       
       if( type == "PLAYER")
       {

         thisItem->setText( 0, "Player");
         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "online");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "rotsp");
         Item->setText( 1, "100" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "transp");
         Item->setText( 1, "20" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "fmax2");
         Item->setText( 1, "2" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbforward");
         Item->setText( 1, "w" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbback");
         Item->setText( 1, "s" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbleft");
         Item->setText( 1, "a" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbright");
         Item->setText( 1, "d" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbd");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "joystick");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "ax1");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "ay1");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "ax2");
         Item->setText( 1, "3" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "ay2");
         Item->setText( 1, "4" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maus");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "network");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camego");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cam2d");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camfix");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamrotadd");
         Item->setText( 1, "4" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamrotsub");
         Item->setText( 1, "6" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamradadd");
         Item->setText( 1, "5" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamradsub");
         Item->setText( 1, "8" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamheightadd");
         Item->setText( 1, "+" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "kbcamheightsub");
         Item->setText( 1, "-" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camrotw");
         Item->setText( 1, "-90.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camhight");
         Item->setText( 1, "5.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "camradius");
         Item->setText( 1, "-10.0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addPlayer(thisItem, objtrans);
       }
       
       if( type == "BARRIER")
       {

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "viewbox");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addBarrier(thisItem, objtrans);
       }

       if( type == "BODY")
       {

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "online");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "mass");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "lvx");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "lvy");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "lvz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "avx");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "avy");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "avz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "box");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cylinder");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sphere");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "viewbox");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addBody(thisItem, objtrans);
       }

       if( type == "SKY")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sunroth");
         Item->setText( 1, "40" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "sunrotv");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "moonroth");
         Item->setText( 1, "65" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "moonrotv");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl1on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl2on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl3on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl1h");
         Item->setText( 1, "2000" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl2h");
         Item->setText( 1, "3000" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl3h");
         Item->setText( 1, "1000" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl1s");
         Item->setText( 1, "50" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl2s");
         Item->setText( 1, "20" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl3s");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl1d");
         Item->setText( 1, "50" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl2d");
         Item->setText( 1, "20" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "cl3d");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addSky(thisItem, objtrans);
       }

       if( type == "TERRAIN")
       {

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "tuxedo.ac" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "barrier");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addTerrain(thisItem, objtrans);
       }

       if( type == "SPL")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "nonamed.spl" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addSpl(thisItem, objtrans);
       }

       if( type == "SHADER")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "vfile");
         Item->setText( 1, "nonamed.spl" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "ffile");
         Item->setText( 1, "nonamed.spl" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addShader(thisItem, objtrans);
       }

       if( type == "SOUND")
       {

         addCoord(thisItem);

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "path");
         Item->setText( 1, "data" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "file");
         Item->setText( 1, "nonamed.wav" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "play");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "loop");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "relativexyz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "viewbox");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "rate");
         Item->setText( 1, "44100" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "stereo");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "bps");
         Item->setText( 1, "16" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "volume");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addSound(thisItem, objtrans);
       }

       if( type == "CURSOR")
       {
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "mx");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "my");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "type");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "z");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addCursor(thisItem);
       }

       if( type == "GUI-TXT")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "place");
         Item->setText( 1, "4" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "label");
         Item->setText( 1, "text" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "colorlabel");
         Item->setText( 1, "FFFFFF" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addGUITXT(thisItem);
       }

       if( type == "GUI-INPUT")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "place");
         Item->setText( 1, "4" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxx");
         Item->setText( 1, "90" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxy");
         Item->setText( 1, "30" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "label");
         Item->setText( 1, "text" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "colorlabel");
         Item->setText( 1, "FFFFFF" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );
         
         gl->addGUIInput(thisItem);
       }

       if( type == "GUI-BUTTON")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "place");
         Item->setText( 1, "4" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxx");
         Item->setText( 1, "90" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxy");
         Item->setText( 1, "30" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "legend");
         Item->setText( 1, "nonamed" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "colorlabel");
         Item->setText( 1, "FFFFFF" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addGUIButton(thisItem);
       }

       if( type == "GUI-OSBUTTON")
       {

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "10" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "place");
         Item->setText( 1, "4" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxx");
         Item->setText( 1, "90" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "maxy");
         Item->setText( 1, "30" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "legend");
         Item->setText( 1, "nonamed" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "colorlabel");
         Item->setText( 1, "FFFFFF" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tmpid");
         Item->setText( 1, mybuff );

         gl->addGUIOSButton(thisItem);
       }
     }
}

void  FolderListItem::addCoord(FolderListItem *thisItem)
{
         FolderListItem *Item=new  FolderListItem(thisItem);
         Item->setText( 0, "on");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "x");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "y");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "z");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "trax");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "tray");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "traz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "scax");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "scay");
         Item->setText( 1, "1" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "scaz");
         Item->setText( 1, "1" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "rotx");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "roty");
         Item->setText( 1, "0" );
         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "rotz");
         Item->setText( 1, "0" );

         Item=new  FolderListItem(thisItem);
         Item->setText( 0, "number");
         Item->setText( 1, "1" );
}

void FolderListItem::setFocus()
{
  if(gl != NULL)
  {
    gl->setFocus(this);
  }  
}

void FolderListItem::setFocusLamp()
{
  if(gl != NULL)
  {
    gl->setFocusLamp(this);
  }
}

void FolderListItem::setFocusFog()
{
  if(gl != NULL)
  {
    gl->setFocusFog(this);
  }
}

void FolderListItem::viewCamera()
{
  if(gl != NULL)
  {
    gl->viewCamera(this);
  }
}

void FolderListItem::exportPlib()
{
  if(gl != NULL)
  {
    ssgSaveSSG("Scene1.ssg",gl->scene);
  }
}

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