summaryrefslogtreecommitdiffstats
path: root/knights/dlg_challenge.cpp
blob: 2df0b4316b8e4e2eaa8ea4e03433449dc97ee146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***************************************************************************
                          dlg_challenge.cpp  -  description
                             -------------------
    begin                : Sun Jan 20 2002
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqregexp.h>
#include "dlg_challenge.moc"

dlg_challenge::dlg_challenge(TQWidget *parent, const char *name, resource *Rsrc ) :
	KDialogBase(	parent,
								name,
								FALSE,
								i18n("You've Been Challenged:"),
								User1|User2,
								Ok,
								TRUE,
								i18n("Accept"),
								i18n("Decline") )
{
	Resource = Rsrc;

	BOX_Parent = makeVBoxMainWidget();

	LABEL_Headline = new TQLabel( BOX_Parent );
	COMBO_Rated = new KComboBox( BOX_Parent );
	BOX_Time = new TQHBox( BOX_Parent );
		BOX_White = new TQGroupBox( 2, Qt::Horizontal, "-", BOX_Time );
			BOX_WhiteBase = new TQSpinBox( BOX_White );
			LABEL_WhiteBase = new TQLabel( BOX_White );
			BOX_WhiteInc = new TQSpinBox( BOX_White );
			LABEL_WhiteInc = new TQLabel( BOX_White );
		BOX_Black = new TQGroupBox( 2, Qt::Horizontal, "-", BOX_Time );
			BOX_BlackBase = new TQSpinBox( BOX_Black );
			LABEL_BlackBase = new TQLabel( BOX_Black );
			BOX_BlackInc = new TQSpinBox( BOX_Black );
			LABEL_BlackInc = new TQLabel( BOX_Black );
	BUTTON_TimeOdds = new TQCheckBox( i18n("Time Odds Match"),BOX_Parent );

	LABEL_Headline->setAlignment( TQt::AlignCenter );
	COMBO_Rated->setEditable( FALSE );
	COMBO_Rated->insertItem( i18n("Unrated"), 0 );
	COMBO_Rated->insertItem( i18n("Rated"), 1 );

	BOX_WhiteBase->setMinValue( 0 );
	BOX_WhiteInc->setMinValue( 0 );
	BOX_WhiteBase->setMaxValue( 300 );
	BOX_WhiteInc->setMaxValue( 300 );
	BOX_WhiteBase->setSuffix( i18n(" min.") );
	BOX_WhiteInc->setSuffix( i18n(" sec.") );
	LABEL_WhiteBase->setText( i18n( "Base Time" ) );
	LABEL_WhiteInc->setText( i18n( "Increment" ) );

	BOX_BlackBase->setMinValue( 0 );
	BOX_BlackInc->setMinValue( 0 );
	BOX_BlackBase->setMaxValue( 300 );
	BOX_BlackInc->setMaxValue( 300 );
	BOX_BlackBase->setSuffix( i18n(" min.") );
	BOX_BlackInc->setSuffix( i18n(" sec.") );
	LABEL_BlackBase->setText( i18n( "Base Time" ) );
	LABEL_BlackInc->setText( i18n( "Increment" ) );

	showButton( User1, TRUE );
	showButton( User2, TRUE );
	enableButton( User1, TRUE );
	enableButton( User2, TRUE );
	show();
}

dlg_challenge::~dlg_challenge()
{
}

void dlg_challenge::setValues( const TQString &string, const TQString &local )
{
	/* we only need the first line, strip the rest */
	TQString myString( string.section('\n', 0, 0) );
	TQStringList list;

	/*remove all the white space between the rating brackets*/
	myString.replace( TQRegExp("\\(\\s"), "(" );
	myString.replace( TQRegExp("\\s\\)"), ")" );
	
	list = TQStringList::split( TQChar(' '), myString, FALSE );
	list[7].replace(TQRegExp("\\."), "");
	if( list[0] == local )
	{
		localRating = list[1];
		otherPlayer = list[2];
		otherRating = list[3];
	}
	else
	{
		otherPlayer = list[0];
		otherRating = list[1];
		localRating = list[3];
	}
	LABEL_Headline->setText( i18n("%1 %2 vs. %3 %4\nin a %5 match.")
		.arg(local).arg(localRating).arg(otherPlayer).arg(otherRating).arg(list[5]) );
	if( list[4].lower() == "rated" )
	{	
		COMBO_Rated->setCurrentItem(1);
	}
	else
	{
		COMBO_Rated->setCurrentItem(0);
	}
	BOX_WhiteBase->setValue( list[6].toInt() );
	BOX_WhiteInc->setValue( list[7].toInt() );
	BOX_BlackBase->setValue( list[6].toInt() );
	BOX_BlackInc->setValue( list[7].toInt() );
	BOX_White->setTitle( i18n("Time Controls") );
	BOX_Black->setTitle( i18n("Time Controls") );
//	BOX_Black->setEnabled( FALSE );
//	BUTTON_TimeOdds->setChecked( FALSE );

	connect( COMBO_Rated, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BOX_WhiteBase, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BOX_WhiteInc, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BOX_BlackBase, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BOX_BlackInc, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BUTTON_TimeOdds, TQT_SIGNAL( stateChanged(int) ), this, TQT_SLOT( slot_changed(int) ) );
	connect( BUTTON_TimeOdds, TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( slot_timeOdds(bool) ) );
}

TQString dlg_challenge::values( void )
{
	TQString match;
	match = TQString("match %1").arg(otherPlayer);
	if( COMBO_Rated->currentItem() == 0 )
		match += " unrated";
	else
		match += " rated";
	match += TQString(" %1 %1").arg(BOX_WhiteBase->value()).arg(BOX_WhiteInc->value());
	if( BUTTON_TimeOdds->isChecked() )
		match += TQString(" %1 %1").arg(BOX_BlackBase->value()).arg(BOX_BlackInc->value());
	return match;
}

void dlg_challenge::slot_changed( int )
{
	setButtonText( User1, i18n("Counter Offer") );
}

void dlg_challenge::slot_timeOdds( bool state )
{
	BOX_Black->setEnabled( state );
}