/***************************************************************************
                          kcakeview.cpp  -  description
                             -------------------
    begin                : Die Nov 19 10:27:05 CET 2002
    copyright            : (C) 2002 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 files for Qt
#include <qprinter.h>
#include <qpainter.h>
#include <qsplitter.h>
#include <qworkspace.h>
#include <qvbox.h>
#include <qlabel.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qobjectlist.h>
#include <qpopupmenu.h>
#include <qheader.h>
#include <qregexp.h>
#include <qmultilineedit.h>
#include <qlayout.h>
#include <qcheckbox.h>
#include <qtabdialog.h>
#include <qdom.h>

// application specific includes
#include "kcakeview.h"
#include "qcakedoc.h"
#include "qcake.h"
#include "listviews.h"
#include "glcontrol.h"


#include <iostream>


KCakeView::KCakeView(QWidget *parent, const char *name) : QVBox(parent, name)
{

    int mindex=0;
    gl = NULL;
    folderitem = NULL;
    tmpItem = NULL;
    
    doc= NULL;
//  setBackgroundMode(PaletteBase);
   m_pMainSplitter = new QSplitter( Qt::Horizontal, this, "MainSplitter" );
   m_pTreeEditSplitter = new QSplitter( Qt::Vertical, m_pMainSplitter,
                                        "TreeEditSplitter" );


    folders = new QListView( m_pTreeEditSplitter );
    folders->setSorting( -1 );
    folders->header()->setClickEnabled( FALSE );
    folders->addColumn( "Game" );
    folders->addColumn( "Type" );
    folders->addColumn( "ID" );
    
//    setupFolders();
    folders->setRootIsDecorated( TRUE );
//    folders->show( );

// Stack fuer Dialogboxen erzeugen
    stack = new QWidgetStack( m_pTreeEditSplitter );
    stack->setMinimumSize( 260, 360 );
    

//*****************************************************************************
//  Lamp Dialog
     MyLampEditDlg *LampEdit = new MyLampEditDlg();
//*****************************************************************************
//  Camera Dialog
     MyCameraEditDlg *CameraEdit = new MyCameraEditDlg();
//*****************************************************************************
//  Object Dialog
     MyObjEditDlg *ObjEdit = new MyObjEditDlg();
//*****************************************************************************
//  PartSys Dialog
     MyPartSysEditDlg *PartSysEdit = new MyPartSysEditDlg();
//*****************************************************************************
//  WaveSys Dialog
     MyWaveSysEditDlg *WaveSysEdit = new MyWaveSysEditDlg();
//*****************************************************************************
//  Fire Dialog
     MyFireEditDlg *FireEdit = new MyFireEditDlg();
//*****************************************************************************
//  Fog Dialog
     MyFogEditDlg *FogEdit = new MyFogEditDlg();
//*****************************************************************************
//  Scene Dialog
     MySceneEditDlg *SceneEdit = new MySceneEditDlg();
//*****************************************************************************
//  Scene Dialog
     MyPlayerEditDlg *PlayerEdit = new MyPlayerEditDlg();
//*****************************************************************************
//  Barrier Dialog
     MyBarrierEditDlg *BarrierEdit = new MyBarrierEditDlg();
//*****************************************************************************
//  Body Dialog
     MyBodyEditDlg *BodyEdit = new MyBodyEditDlg();
//*****************************************************************************
//  Sky Dialog
     MySkyEditDlg *SkyEdit = new MySkyEditDlg();
//*****************************************************************************
//  SPL Dialog
     MySplEditDlg *SplEdit = new MySplEditDlg();
//*****************************************************************************
//  SOUND Dialog
     MySoundEditDlg *SoundEdit = new MySoundEditDlg();
//*****************************************************************************
//  GUITEXT Dialog
     MyGUITextEditDlg *GUITextEdit = new MyGUITextEditDlg();
//*****************************************************************************
//  GUIBUTTON Dialog
     MyGUIButtonEditDlg *GUIButtonEdit = new MyGUIButtonEditDlg();
//*****************************************************************************
//  GUIOSBUTTON Dialog
     MyGUIOSButtonEditDlg *GUIOSButtonEdit = new MyGUIOSButtonEditDlg();
//*****************************************************************************
//  GUIINPUT Dialog
     MyGUIInputEditDlg *GUIInputEdit = new MyGUIInputEditDlg();
//*****************************************************************************
//  NETWORK Dialog
     MyNetworkEditDlg *NetworkEdit = new MyNetworkEditDlg();
//*****************************************************************************
//  GLOBAL Dialog
     MyGlobalEditDlg *GlobalEdit = new MyGlobalEditDlg();
//*****************************************************************************
//  TERRAIN Dialog
     MyTerrainEditDlg *TerrainEdit = new MyTerrainEditDlg();
//*****************************************************************************
//  SHADER Dialog
     MyShaderEditDlg *ShaderEdit = new MyShaderEditDlg();
//*****************************************************************************
//  CURSOR Dialog
     MyCursorEditDlg *CursorEdit = new MyCursorEditDlg();
//*****************************************************************************
//  Default Dialog
     DefaultDlg *DefaultEdit = new DefaultDlg();
//*****************************************************************************
// Anfügen & Anzeigen
//    stack->addWidget(ggame_t,0);
    stack->addWidget(LampEdit,1);
    stack->addWidget(CameraEdit,2);
    stack->addWidget(ObjEdit,3);
    stack->addWidget(FireEdit,4);
    stack->addWidget(PartSysEdit,5);
    stack->addWidget(WaveSysEdit,6);
    stack->addWidget(FogEdit,7);
    stack->addWidget(SceneEdit,8);
    stack->addWidget(PlayerEdit,9);
    stack->addWidget(BarrierEdit,10);
    stack->addWidget(BodyEdit,11);
    stack->addWidget(SkyEdit,12);
//    stack->addWidget(PslEdit,13);
    stack->addWidget(SoundEdit,14);
    stack->addWidget(GUITextEdit,15);
    stack->addWidget(GUIButtonEdit,16);
    stack->addWidget(GUIInputEdit,17);
    stack->addWidget(GUIOSButtonEdit,18);
    stack->addWidget(NetworkEdit,19);
    stack->addWidget(SplEdit,20);
    stack->addWidget(GlobalEdit,21);
    stack->addWidget(TerrainEdit,22);
    stack->addWidget(ShaderEdit,23);
    stack->addWidget(CursorEdit,24);
    stack->addWidget(DefaultEdit,40);
    stack->raiseWidget(40);
//---------------------------------------------------
    QVBox *vbox = new QVBox( m_pMainSplitter );
    vbox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
    vbox->setMargin( 1 );
    vbox->setLineWidth( 1 );
    workspace = new QWorkspace( vbox );
    workspace->setBackgroundMode( PaletteMid );

//**********all*SCENE*0**********
    mindex=0;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
    menu[mindex]->insertItem( "add Object" );
    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add BARRIER",this,SLOT(slotAddBarrier()) );
    menu[mindex]->insertItem( "add BODY",this,SLOT(slotAddBody()) );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );
    
//*********LAMP*1************

    mindex=1;
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********CAMERA*2************

    mindex=2;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********OBJECT*3************

    mindex=3;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********FIRE*4*************

    mindex=4;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********PARTSYS*5*************

    mindex=5;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********WAVESYS*6*************

    mindex=6;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********FOG*7*************

    mindex=7;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********INTRO*8*************

    mindex=8;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********PLAYER*9************

    mindex=9;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//***********SCENE*10**********
    mindex=10;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add BARRIER",this,SLOT(slotAddBarrier()) );
    menu[mindex]->insertItem( "add BODY",this,SLOT(slotAddBody()) );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
    menu[mindex]->insertItem( "add LAMP",this,SLOT(slotAddLamp()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//***********Level*11**********
    mindex=11;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********BARRIER*12************

    mindex=12;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );


//********PSL*13*************

    mindex=13;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );



//********END*14*************

    mindex=14;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//********OPTION*15*************

    mindex=15;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********BODY*16************

    mindex=16;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********SKY*17************

    mindex=17;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********HISCORE*18************

    mindex=18;
    menu[mindex] = new QPopupMenu( this );
    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********SOUND*19************

    mindex=19;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
    menu[mindex]->insertItem( "add Object" );
    menu[mindex]->insertItem( "clear Object" );
    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********SPL*20************

    mindex=20;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********GLOBAL*21************

    mindex=21;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********TERRAIN*22************

    mindex=22;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********SHADER*23************

    mindex=23;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********CURSOR*24************

    mindex=24;
    menu[mindex] = new QPopupMenu( this );
//    menu[mindex]->insertItem( "add Scene",this,SLOT(slotAddScene()) );
//    menu[mindex]->insertItem( "load Object",this,SLOT(slotLoadObject()) );
//    menu[mindex]->insertItem( "add Object" );
//    menu[mindex]->insertItem( "clear Object" );
//    menu[mindex]->insertItem( "add FIRE",this,SLOT(slotAddFire()) );
//    menu[mindex]->insertItem( "add PARTSYS",this,SLOT(slotAddPartSys()) );
//    menu[mindex]->insertItem( "add WAVESYS",this,SLOT(slotAddWaveSys()) );
//    menu[mindex]->insertItem( "add CAMERA",this,SLOT(slotAddCamera()) );
//    menu[mindex]->insertItem( "view CAMERA",this,SLOT(slotViewCamera()) );
//    menu[mindex]->insertItem( "add FOG",this,SLOT(slotAddFog()) );
//    menu[mindex]->insertItem( "add PLAYER",this,SLOT(slotAddPlayer()) );
//    menu[mindex]->insertItem( "add SKY",this,SLOT(slotAddSky()) );
//    menu[mindex]->insertItem( "add Terrain",this,SLOT(slotAddTerrain()) );
//    menu[mindex]->insertItem( "add Shader",this,SLOT(slotAddShader()) );
//    menu[mindex]->insertItem( "add Cursor",this,SLOT(slotAddCursor()) );
    menu[mindex]->insertItem( "add SPL",this,SLOT(slotAddSpl()) );
//    menu[mindex]->insertItem( "add SOUND",this,SLOT(slotAddSound()) );
//    menu[mindex]->insertItem( "add GUI-Text",this,SLOT(slotAddGUITXT()) );
//    menu[mindex]->insertItem( "add GUI-Input",this,SLOT(slotAddGUIInput()) );
//    menu[mindex]->insertItem( "add GUI-Button",this,SLOT(slotAddGUIButton()) );
//    menu[mindex]->insertItem( "add GUI-OSButton",this,SLOT(slotAddGUIOSButton()) );
//    menu[mindex]->insertItem( "export Scene",this,SLOT(slotExportPlib()) );

//*********default*40************

    menu[40] = new QPopupMenu( this );

//*****************************
    
    connect(folders, SIGNAL( contextMenuRequested( QListViewItem *, const QPoint& , int ) ),
	    this, SLOT( slotRMB( QListViewItem *, const QPoint &, int ) ) );

//**********************
    connect( folders, SIGNAL( selectionChanged( QListViewItem * ) ),
	     this, SLOT( slotFolderChanged( QListViewItem* ) ) );

//************************
}

void KCakeView::slotViewCamera()
{
    qWarning( "Slot ViewCamera  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->viewCamera();
       }
}

void KCakeView::slotLoadObject()
{
    qWarning( "Slot LoadObject  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("OBJECT");
       }          
}

void KCakeView::slotAddTerrain()
{
    qWarning( "Slot AddTerrain  !" );

       if(folderitem != NULL)
       {
          qWarning( "Terrain ok  !" );
          ((FolderListItem *)folderitem)->addObject("TERRAIN");
       }
}

void KCakeView::slotAddBarrier()
{
    qWarning( "Slot AddBarrier  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("BARRIER");
       }
}

void KCakeView::slotAddBody()
{
    qWarning( "Slot AddBody  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("BODY");
       }
}

void KCakeView::slotAddLamp()
{
    qWarning( "Slot AddLamp  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("LAMP");
       }
}

void KCakeView::slotAddFire()
{
    qWarning( "Slot AddFire  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("FIRE");
       }
}

void KCakeView::slotAddPartSys()
{
    qWarning( "Slot AddPartSys  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("PARTSYS");
       }
}

void KCakeView::slotAddWaveSys()
{
    qWarning( "Slot AddWaveSys  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("WAVESYS");
       }
}

void KCakeView::slotAddCamera()
{
    qWarning( "Slot AddCamera  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("CAMERA");
       }
}

void KCakeView::slotAddFog()
{
    qWarning( "Slot AddFog  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("FOG");
       }
}

void KCakeView::slotAddPlayer()
{
    qWarning( "Slot AddPlayer  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("PLAYER");
       }
}

void KCakeView::slotAddSky()
{
    qWarning( "Slot AddSky  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("SKY");
       }
}

void KCakeView::slotAddScene()
{
    qWarning( "Slot AddScene  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("SCENE");
       }
}

void KCakeView::slotAddShader()
{
    qWarning( "Slot AddShader  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("SHADER");
       }
}

void KCakeView::slotAddCursor()
{
    qWarning( "Slot AddCursor  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("CURSOR");
       }
}

void KCakeView::slotAddSpl()
{
    qWarning( "Slot AddSpl  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("SPL");
       }
}

void KCakeView::slotAddSound()
{
    qWarning( "Slot AddSound  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("SOUND");
       }
}

void KCakeView::slotAddGUITXT()
{
    qWarning( "Slot AddGUITXT  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("GUI-TXT");
       }
}

void KCakeView::slotAddGUIInput()
{
    qWarning( "Slot AddGUIInput  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("GUI-INPUT");
       }
}

void KCakeView::slotAddGUIButton()
{
    qWarning( "Slot AddGUIButton  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("GUI-BUTTON");
       }
}

void KCakeView::slotAddGUIOSButton()
{
    qWarning( "Slot AddGUIOSButton  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->addObject("GUI-OSBUTTON");
       }
}

void KCakeView::slotExportPlib()
{
    qWarning( "Slot ExportPlib  !" );

       if(folderitem != NULL)
       {
          qWarning( "Object ok  !" );
          ((FolderListItem *)folderitem)->exportPlib();
       }
}

void KCakeView::slotRMB( QListViewItem *Item, const QPoint & point, int )
{
   if( Item )
   {
      folderitem = Item;

    if(strstr(Item->text(1),"LAMP") != NULL)
    {
      menu[1]->popup( point );
    }
    if(strstr(Item->text(1),"CAMERA") != NULL)
    {
      menu[2]->popup( point );
    }
    if(strstr(Item->text(1),"OBJECT") != NULL)
    {
      menu[3]->popup( point );
    }
    if(strstr(Item->text(1),"FIRE") != NULL)
    {
      menu[4]->popup( point );
    }
    if(strstr(Item->text(1),"PARTSYS") != NULL)
    {
      menu[5]->popup( point );
    }
    if(strstr(Item->text(1),"WAVESYS") != NULL)
    {
      menu[6]->popup( point );
    }
    if(strstr(Item->text(1),"FOG") != NULL)
    {
      menu[7]->popup( point );
    }
    if(strstr(Item->text(1),"INTRO") != NULL)
    {
      menu[8]->popup( point );
    }
    if(strstr(Item->text(1),"PLAYER") != NULL)
    {
      menu[9]->popup( point );
    }
    if(strstr(Item->text(1),"SCENE") != NULL)
    {
      menu[10]->popup( point );
    }
    if(strstr(Item->text(1),"LEVEL") != NULL)
    {
      menu[11]->popup( point );
    }
    if(strstr(Item->text(1),"BARRIER") != NULL)
    {
      menu[12]->popup( point );
    }
/*
    if(strstr(Item->text(1),"PSL") != NULL)
    {
      menu[13]->popup( point );
    }
*/
    if(strstr(Item->text(1),"END") != NULL)
    {
      menu[14]->popup( point );
    }
    if(strstr(Item->text(1),"OPTION") != NULL)
    {
      menu[15]->popup( point );
    }
    if(strstr(Item->text(1),"BODY") != NULL)
    {
      menu[16]->popup( point );
    }
    if(strstr(Item->text(1),"SKY") != NULL)
    {
      menu[17]->popup( point );
    }
    if(strstr(Item->text(1),"HISCORE") != NULL)
    {
      menu[18]->popup( point );
    }
    if(strstr(Item->text(1),"SOUND") != NULL)
    {
      menu[19]->popup( point );
    }
    if(strstr(Item->text(1),"SPL") != NULL)
    {
      menu[20]->popup( point );
    }
    if(strstr(Item->text(1),"GLOBAL") != NULL)
    {
      menu[21]->popup( point );
    }
    if(strstr(Item->text(1),"TERRAIN") != NULL)
    {
      menu[22]->popup( point );
    }
    if(strstr(Item->text(1),"SHADER") != NULL)
    {
      menu[23]->popup( point );
    }
    if(strstr(Item->text(1),"CURSOR") != NULL)
    {
      menu[24]->popup( point );
    }

   }
}


void KCakeView::newWirebox(FolderListItem * i)
{
    if(!(gl))   // no GLWindow
    {
      gl= i->gl = new Glcontrol( workspace, 0 );
      i->gl->setIcon( QPixmap( "data/wirebox.xpm" ) );
      i->gl->setCaption( tr( i->text(0) ) );
      i->gl->resize( 320, 200 );
      i->gl->show();
      i->gl->initFolderListItem(i,g_prjpath);
      i->gl->setFocusScene(i);
      g_gl=  i->gl;
      tmpItem = i;
      g_tmpItem = i;
      i->gl->globj=NULL;
    }
    else
    {
      if (tmpItem != i)    // only it first click on scene !!
      {
         if(!(i->gl))
         {
           i->gl=gl;
         }
         i->gl->switchScene(i);
         tmpItem = i;
         g_tmpItem = i;
      }
    }
}

void KCakeView::initListView(QDomDocument *domdoc, const QString &path)
{
  QDomNode node;
  int a;

  if(g_gl != NULL)
  {
    if ( g_gl->scene != NULL )
    {
      g_gl->puDelete ();
    }
  }


  folders->clear();
  for(a=0; a < MAX_LIST_ITEMS; a++)
  {
    g_ListItem[a] = NULL;
  }
  g_nextid=0;

  mypath=path;
  
  QDomElement docElem = domdoc->documentElement();


      // create the tree view out of the DOM
    node = docElem.firstChild();
    while ( !node.isNull() )
    {
	    if ( node.isElement() && node.nodeName() == "body" )
      {
	      QDomElement body = node.toElement();
	      buildTree( 0, body );
	      break;
	    }
	    node = node.nextSibling();
    }
}

void KCakeView::buildTree( FolderListItem *parentItem, const QDomElement &parentElement )
{
    FolderListItem *thisItem = 0;
    FolderListItem *nextItem = 0;
    unsigned int a=0;
//    char mybuff[256];
     
//    QDomNamedNodeMap *thismap =0;
        
    QDomNode node = parentElement.firstChild();
    while ( !node.isNull() )
    {
    	if ( node.isElement() && node.nodeName()== "outline" )
      {
//        cout << node.toElement().tagName() << endl; // debug
          // add a new list view item for the outline

  	    if ( parentItem == 0 )
        {
	      	thisItem = new FolderListItem( folders, thisItem );
        }
        else
        {
		      thisItem = new FolderListItem( parentItem, thisItem );
        }
	      thisItem->setText( 0, node.toElement().attribute( "text" ) );
	      thisItem->setText( 1, node.toElement().attribute( "type" ) );
	      thisItem->setText( 2, node.toElement().attribute( "tmpid" ) );

        if(g_nextid < node.toElement().attribute( "tmpid" ).toInt() )
        {
          g_nextid = node.toElement().attribute( "tmpid" ).toInt();
        }
         // Creatd ID Numbers  old system
//        sprintf(mybuff,"%ld",g_nextitem);
        g_ListItem[g_nextitem] = thisItem;
        g_nextitem++;
//	      thisItem->setText( 2, mybuff );
        

//        cout << node.toElement().attribute("type") << endl; // debug
//        thismap = node.attributes();
//        cout << node.attributes().count() << endl; // debug

        for(a=0; a< node.attributes().count();a++)
        {
          if(strstr(node.attributes().item(a).nodeName(),"text")==NULL &&
           strstr(node.attributes().item(a).nodeName(),"type")==NULL)
          {
            nextItem = new FolderListItem( thisItem, nextItem );
	          nextItem->setText( 0, node.attributes().item(a).nodeName() );
	          nextItem->setText( 1, node.attributes().item(a).nodeValue() );
          }
        }
        
                            
	        // recursive build of the tree
          buildTree( thisItem, node.toElement() );
	    }
	    node = node.nextSibling();
    }
    g_nextid++;
}

void KCakeView::slotFolderChanged(QListViewItem *i)
{
    if ( !i )
	      return;

    if(strstr(i->text(1),"OPTION") != NULL)
    {
        stack->raiseWidget(40);
    }
    if(strstr(i->text(1),"LAMP") != NULL)
    {
        ((MyLampEditDlg*)stack->widget(1))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyObjEditDlg*)stack->widget(1));
        stack->raiseWidget(1);
        ((FolderListItem *)i)->setFocusLamp();
    }
    if(strstr(i->text(1),"CAMERA") != NULL)
    {
        ((MyCameraEditDlg*)stack->widget(2))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyCameraEditDlg*)stack->widget(2));
        stack->raiseWidget(2);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"OBJECT") != NULL)
    {
        ((MyObjEditDlg*)stack->widget(3))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyObjEditDlg*)stack->widget(3));
        stack->raiseWidget(3);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"FIRE") != NULL)
    {
        ((MyFireEditDlg*)stack->widget(4))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyFireEditDlg*)stack->widget(4));
        stack->raiseWidget(4);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"PARTSYS") != NULL)
    {
        ((MyPartSysEditDlg*)stack->widget(5))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyPartSysEditDlg*)stack->widget(5));
        stack->raiseWidget(5);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"WAVESYS") != NULL)
    {
        ((MyWaveSysEditDlg*)stack->widget(6))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyWaveSysEditDlg*)stack->widget(6));
        stack->raiseWidget(6);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"FOG") != NULL)
    {
        ((MyFogEditDlg*)stack->widget(7))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyFogEditDlg*)stack->widget(7));
        stack->raiseWidget(7);
        ((FolderListItem *)i)->setFocusFog();
    }
    if(strstr(i->text(1),"SCENE") != NULL)
    {
        ((MySceneEditDlg*)stack->widget(8))->slotGetData((FolderListItem *)i);
        newWirebox((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MySceneEditDlg*)stack->widget(8));
        stack->raiseWidget(8);
    }
    if(strstr(i->text(1),"PLAYER") != NULL)
    {
        ((MyFogEditDlg*)stack->widget(9))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyFogEditDlg*)stack->widget(9));
        stack->raiseWidget(9);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"BARRIER") != NULL)
    {
        ((MyBarrierEditDlg*)stack->widget(10))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyBarrierEditDlg*)stack->widget(10));
        stack->raiseWidget(10);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"BODY") != NULL)
    {
        ((MyBodyEditDlg*)stack->widget(11))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyBodyEditDlg*)stack->widget(11));
        stack->raiseWidget(11);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"SKY") != NULL)
    {
        ((MySkyEditDlg*)stack->widget(12))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MySkyEditDlg*)stack->widget(12));
        stack->raiseWidget(12);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"SOUND") != NULL)
    {
        ((MySoundEditDlg*)stack->widget(14))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MySoundEditDlg*)stack->widget(14));
        stack->raiseWidget(14);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"GUI-TXT") != NULL)
    {
        ((MyGUITextEditDlg*)stack->widget(15))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyGUITextEditDlg*)stack->widget(15));
        stack->raiseWidget(15);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"GUI-BUTTON") != NULL)
    {
        ((MyGUIButtonEditDlg*)stack->widget(16))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyGUIButtonEditDlg*)stack->widget(16));
        stack->raiseWidget(16);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"GUI-INPUT") != NULL)
    {
        ((MyGUIInputEditDlg*)stack->widget(17))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyGUIInputEditDlg*)stack->widget(17));
        stack->raiseWidget(17);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"GUI-OSBUTTON") != NULL)
    {
        ((MyGUIOSButtonEditDlg*)stack->widget(18))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyGUIOSButtonEditDlg*)stack->widget(18));
        stack->raiseWidget(18);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"NETWORK") != NULL)
    {
        ((MyNetworkEditDlg*)stack->widget(19))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyNetworkEditDlg*)stack->widget(19));
        stack->raiseWidget(19);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"SPL") != NULL)
    {
        ((MySplEditDlg*)stack->widget(20))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MySplEditDlg*)stack->widget(20));
        stack->raiseWidget(20);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"GLOBAL") != NULL)
    {
        ((MyGlobalEditDlg*)stack->widget(21))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyGlobalEditDlg*)stack->widget(21));
        stack->raiseWidget(21);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"TERRAIN") != NULL)
    {
        ((MyGlobalEditDlg*)stack->widget(22))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyTerrainEditDlg*)stack->widget(22));
        stack->raiseWidget(22);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"SHADER") != NULL)
    {
        ((MyShaderEditDlg*)stack->widget(23))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyShaderEditDlg*)stack->widget(23));
        stack->raiseWidget(23);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"CURSOR") != NULL)
    {
        ((MyCursorEditDlg*)stack->widget(24))->slotGetData((FolderListItem *)i);
        ((FolderListItem *)i)->dialog = ((MyCursorEditDlg*)stack->widget(24));
        stack->raiseWidget(24);
        ((FolderListItem *)i)->setFocus();
    }
    if(strstr(i->text(1),"INTRO") != NULL)
    {
        stack->raiseWidget(40);
    }
    if(strstr(i->text(1),"LEVEL") != NULL)
    {
        stack->raiseWidget(40);
    }
    if(strstr(i->text(1),"HISCORE") != NULL)
    {
        stack->raiseWidget(40);
    }
    if(strstr(i->text(1),"END") != NULL)
    {
        stack->raiseWidget(40);
    }
    
//    cout << i->text(0) << endl; // debug
}


void KCakeView::getListView(QDomDocument *domdoc)
{
    QDomElement root = domdoc->createElement( "opml" );
    domdoc->appendChild( root );

    root.setAttribute( "version", "1.0" );

    // Header
    
    QDomElement head = domdoc->createElement( "head" );
    root.appendChild( head );

    QDomElement title = domdoc->createElement( "title" );
    head.appendChild( title );

    QDomText t = domdoc->createTextNode( "Nonamed.xml" );
    title.appendChild( t );

    // Body
    
    QDomElement body = domdoc->createElement( "body" );
    root.appendChild( body );

    buildDomTree(&body,(FolderListItem *)(folders->firstChild()),domdoc);
}

void KCakeView::buildDomTree( QDomElement *parentElement, FolderListItem *parentItem,QDomDocument *domdoc )
{
    QListViewItem *ichild = parentItem;
    QDomElement outline;

    while(ichild != NULL)
    {
      
        if(ichild->text(1) == "OPTION" ||
         ichild->text(1) == "LAMP" ||
         ichild->text(1) == "CAMERA" ||
         ichild->text(1) == "OBJECT" ||
         ichild->text(1) == "BARRIER" ||
         ichild->text(1) == "BODY" ||
         ichild->text(1) == "PARTSYS" ||
         ichild->text(1) == "WAVESYS" ||
         ichild->text(1) == "FIRE" ||
         ichild->text(1) == "FOG" ||
         ichild->text(1) == "PLAYER" ||
         ichild->text(1) == "SKY" ||
         ichild->text(1) == "TERRAIN" ||
         ichild->text(1) == "SHADER" ||
         ichild->text(1) == "CURSOR" ||
         ichild->text(1) == "SPL" ||
         ichild->text(1) == "SOUND" ||
         ichild->text(1) == "GUI-TXT" ||
         ichild->text(1) == "GUI-INPUT" ||
         ichild->text(1) == "GUI-BUTTON" ||
         ichild->text(1) == "GUI-OSBUTTON" ||
         ichild->text(1) == "GLOBAL" ||
         ichild->text(1) == "NETWORK" ||
         ichild->text(1) == "INTRO" ||
         ichild->text(1) == "LEVEL" ||
         ichild->text(1) == "SCENE" ||
         ichild->text(1) == "HISCORE" ||
         ichild->text(1) == "END")
        {
          outline = domdoc->createElement( "outline" );

          QListViewItem *achild = ichild->firstChild();
          while(achild != NULL)
          {

            if(!(achild->text(1) == "OPTION" ||
            achild->text(1) == "LAMP" ||
            achild->text(1) == "CAMERA" ||
            achild->text(1) == "OBJECT" ||
            achild->text(1) == "BARRIER" ||
            achild->text(1) == "BODY" ||
            achild->text(1) == "PARTSYS" ||
            achild->text(1) == "WAVESYS" ||
            achild->text(1) == "FIRE" ||
            achild->text(1) == "FOG" ||
            achild->text(1) == "PLAYER" ||
            achild->text(1) == "SKY" ||
            achild->text(1) == "TERRAIN" ||
            achild->text(1) == "SHADER" ||
            achild->text(1) == "CURSOR" ||
            achild->text(1) == "SPL" ||
            achild->text(1) == "SOUND" ||
            achild->text(1) == "GUI-TXT" ||
            achild->text(1) == "GUI-INPUT" ||
            achild->text(1) == "GUI-BUTTON" ||
            achild->text(1) == "GUI-OSBUTTON" ||
            achild->text(1) == "GLOBAL" ||
            achild->text(1) == "NETWORK" ||
            achild->text(1) == "INTRO" ||
            achild->text(1) == "LEVEL" ||
            achild->text(1) == "SCENE" ||
            achild->text(1) == "HISCORE" ||
            achild->text(1) == "END"))
            {

              outline.setAttribute( achild->text(0), achild->text(1) );

            }
            achild=achild->nextSibling();
          }
          outline.setAttribute( "tmpid", ichild->text(2) );
          outline.setAttribute( "type", ichild->text(1) );
          outline.setAttribute( "text", ichild->text(0) );
          parentElement->appendChild( outline );
        }
        qWarning( ichild->text(0) + " OK !" );
        buildDomTree(&outline,(FolderListItem *)(ichild->firstChild()),domdoc);
        ichild=ichild->nextSibling();
    }
}

KCakeView::~KCakeView()
{
}


QcakeDoc *KCakeView::getDocument() const
{
/*
  QcakeApp *theApp=(QcakeApp *) parentWidget();

  return theApp->getDocument();
*/
  return doc;
}


void KCakeView::print(QPrinter *pPrinter)
{
  QPainter printpainter;
  printpainter.begin(pPrinter);
	
  // TODO: add your printing code here

  printpainter.end();
}
