#include <klocale.h>
/****************************************************************************
** Form implementation generated from reading ui file './scores.ui'
**
** Created: Sun Sep 30 01:30:41 2001
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "scores.moc"
#include "scores.h"

#include <qgroupbox.h>
#include <qheader.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>

/* 
 *  Constructs a HighScores which is a child of 'parent', with the 
 *  name 'name' and widget flags set to 'f' 
 */
HighScores::HighScores( QWidget* parent,  const char* name, WFlags fl ) : QWidget( parent, name, fl )
{
config = kapp->config();


    if ( !name )
	setName( "HighScores" );
    resize( 349, 331 ); 
    setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)5, sizePolicy().hasHeightForWidth() ) );
    setCaption( i18n( "The Highest Scores..." ) );
    setAutoMask( FALSE );
    HighScoresLayout = new QGridLayout( this ); 
    HighScoresLayout->setSpacing( 6 );
    HighScoresLayout->setMargin( 11 );

    GroupBox1 = new QGroupBox( this, "GroupBox1" );
    GroupBox1->setLineWidth( 2 );
    GroupBox1->setTitle( QString::null );
    GroupBox1->setColumnLayout(0, Qt::Vertical );
    GroupBox1->layout()->setSpacing( 0 );
    GroupBox1->layout()->setMargin( 0 );
    GroupBox1Layout = new QGridLayout( GroupBox1->layout() );
    GroupBox1Layout->setAlignment( Qt::AlignTop );
    GroupBox1Layout->setSpacing( 6 );
    GroupBox1Layout->setMargin( 11 );

    TabWidget3 = new QTabWidget( GroupBox1, "TabWidget3" );
    TabWidget3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, TabWidget3->sizePolicy().hasHeightForWidth() ) );
    TabWidget3->setAutoMask( FALSE );
    TabWidget3->setTabPosition( QTabWidget::Top );
    TabWidget3->setTabShape( QTabWidget::Rounded );

    tab = new QWidget( TabWidget3, "tab" );
    tabLayout = new QGridLayout( tab ); 
    tabLayout->setSpacing( 6 );
    tabLayout->setMargin( 11 );

    scoringEasy = new QListView( tab, "scoringEasy" );
    scoringEasy->addColumn( i18n( "Name      " ) );
    scoringEasy->header()->setClickEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->header()->setResizeEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->addColumn( i18n( "Solved" ) );
    scoringEasy->header()->setClickEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->header()->setResizeEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->addColumn( i18n( "Total messes" ) );
    scoringEasy->header()->setClickEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->header()->setResizeEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->addColumn( i18n( "Total guesses" ) );
    scoringEasy->header()->setClickEnabled( FALSE, scoringEasy->header()->count() - 1 );
    scoringEasy->header()->setResizeEnabled( FALSE, scoringEasy->header()->count() - 1 );
	
	 /***** Scoring *****/
    QListViewItem * eItem = new QListViewItem( scoringEasy, 0 );
	 config->setGroup("Easy_scores");
	 readName[0]=config->readEntry("name0", "");
	 readSolved[0]=config->readEntry("solved0","");
	 readRounds[0]=config->readEntry("rounds0","");
	 readTotal[0]=config->readEntry("guesses0","");
	 config->sync();
    eItem->setText( 0, readName[0]    );
    eItem->setText( 1, readSolved[0]  );
    eItem->setText( 2, readRounds[0] );
    eItem->setText( 3, readTotal[0]     );

   for (int i=1; i<=9; ++i)
	{
	config->setGroup("Easy_scores");
	readName[i]=config->readEntry(varnames.sprintf("name%i",i),"");
	readSolved[i]=config->readEntry(varsolved.sprintf("solved%i",i),"");
	readRounds[i]=config->readEntry(varrounds.sprintf("rounds%i",i),"");
	readTotal[i]=config->readEntry(vartotal.sprintf("guesses%i",i),"");
	config->sync();

   eItem = new QListViewItem( scoringEasy, eItem );
   eItem->setText( 0, readName[i]    );
   eItem->setText( 1, readSolved[i]  );
   eItem->setText( 2, readRounds[i] );
   eItem->setText( 3, readTotal[i]     );
	}
		
	scoringEasy->setSorting (4, false); //this makes think the QListView, that there actually IS another column and it sorts by it :)

   tabLayout->addWidget( scoringEasy, 0, 0 );
   TabWidget3->insertTab( tab, i18n( "Easy" ) );

    tab_2 = new QWidget( TabWidget3, "tab_2" );
    tabLayout_2 = new QGridLayout( tab_2 ); 
    tabLayout_2->setSpacing( 6 );
    tabLayout_2->setMargin( 11 );

    scoringMedium = new QListView( tab_2, "scoringMedium" );
    scoringMedium->addColumn( i18n( "Name      " ) );
    scoringMedium->header()->setClickEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->header()->setResizeEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->addColumn( i18n( "Solved" ) );
    scoringMedium->header()->setClickEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->header()->setResizeEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->addColumn( i18n( "Total messes" ) );
    scoringMedium->header()->setClickEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->header()->setResizeEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->addColumn( i18n( "Total guesses" ) );
    scoringMedium->header()->setClickEnabled( FALSE, scoringMedium->header()->count() - 1 );
    scoringMedium->header()->setResizeEnabled( FALSE, scoringMedium->header()->count() - 1 );

    QListViewItem * mItem = new QListViewItem( scoringMedium, 0 );
	 config->setGroup("Medium_scores");
	 readName[0]=config->readEntry("name0", "");
	 readSolved[0]=config->readEntry("solved0","");
	 readRounds[0]=config->readEntry("rounds0","");
	 readTotal[0]=config->readEntry("guesses0","");
	 config->sync();
    mItem->setText( 0, readName[0]    );
    mItem->setText( 1, readSolved[0]  );
    mItem->setText( 2, readRounds[0] );
    mItem->setText( 3, readTotal[0]     );

   for (int i=1; i<=9; ++i)
	{
	config->setGroup("Medium_scores");
	readName[i]=config->readEntry(varnames.sprintf("name%i",i),"");
	readSolved[i]=config->readEntry(varsolved.sprintf("solved%i",i),"");
	readRounds[i]=config->readEntry(varrounds.sprintf("rounds%i",i),"");
	readTotal[i]=config->readEntry(vartotal.sprintf("guesses%i",i),"");
	config->sync();

   mItem = new QListViewItem( scoringMedium, mItem );
   mItem->setText( 0, readName[i]    );
   mItem->setText( 1, readSolved[i]  );
   mItem->setText( 2, readRounds[i] );
   mItem->setText( 3, readTotal[i]     );
	}

	scoringMedium->setSorting (4, false);

	
    tabLayout_2->addWidget( scoringMedium, 0, 0 );
    TabWidget3->insertTab( tab_2, i18n( "Medium" ) );

    tab_3 = new QWidget( TabWidget3, "tab_3" );
    tabLayout_3 = new QGridLayout( tab_3 ); 
    tabLayout_3->setSpacing( 6 );
    tabLayout_3->setMargin( 11 );

    scoringHard = new QListView( tab_3, "scoringHard" );
    scoringHard->addColumn( i18n( "Name      " ) );
    scoringHard->header()->setClickEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->header()->setResizeEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->addColumn( i18n( "Solved" ) );
    scoringHard->header()->setClickEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->header()->setResizeEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->addColumn( i18n( "Total messes" ) );
    scoringHard->header()->setClickEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->header()->setResizeEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->addColumn( i18n( "Total guesses" ) );
    scoringHard->header()->setClickEnabled( FALSE, scoringHard->header()->count() - 1 );
    scoringHard->header()->setResizeEnabled( FALSE, scoringHard->header()->count() - 1 );

    QListViewItem * hItem = new QListViewItem( scoringHard, 0 );
	 config->setGroup("Hard_scores");
	 readName[0]=config->readEntry("name0", "");
	 readSolved[0]=config->readEntry("solved0","");
	 readRounds[0]=config->readEntry("rounds0","");
	 readTotal[0]=config->readEntry("guesses0","");
	 config->sync();
    hItem->setText( 0, readName[0]    );
    hItem->setText( 1, readSolved[0]  );
    hItem->setText( 2, readRounds[0] );
    hItem->setText( 3, readTotal[0]     );

   for (int i=1; i<=9; ++i)
	{
	config->setGroup("Hard_scores");
	readName[i]=config->readEntry(varnames.sprintf("name%i",i),"");
	readSolved[i]=config->readEntry(varsolved.sprintf("solved%i",i),"");
	readRounds[i]=config->readEntry(varrounds.sprintf("rounds%i",i),"");
	readTotal[i]=config->readEntry(vartotal.sprintf("guesses%i",i),"");
	config->sync();

   hItem = new QListViewItem( scoringHard, hItem );
   hItem->setText( 0, readName[i]    );
   hItem->setText( 1, readSolved[i]  );
   hItem->setText( 2, readRounds[i] );
   hItem->setText( 3, readTotal[i]     );
	}

	/***** End scoring *****/
	
	scoringHard->setSorting (4, false);

    tabLayout_3->addWidget( scoringHard, 0, 0 );
    TabWidget3->insertTab( tab_3, i18n( "Hard" ) );

    GroupBox1Layout->addWidget( TabWidget3, 0, 0 );

    Layout2 = new QGridLayout; 
    Layout2->setSpacing( 6 );
    Layout2->setMargin( 0 );
    QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
    Layout2->addItem( spacer, 0, 0 );

    closeButton = new QPushButton( GroupBox1, "closeButton" );
    closeButton->setText( i18n( "Close" ) );

    Layout2->addWidget( closeButton, 0, 1 );

    GroupBox1Layout->addLayout( Layout2, 1, 0 );

    HighScoresLayout->addWidget( GroupBox1, 0, 0 );

    // signals and slots connections
    connect( closeButton, SIGNAL( clicked() ), this, SLOT( slot_ok() ) );

}

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

void HighScores::slot_ok()
{
	close();
}
