summaryrefslogtreecommitdiffstats
path: root/libksirtet/lib/pline.cpp
blob: 3afb8eff540011e6651f008cea1c86347ad0243c (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
#include "pline.h"
#include "pline.moc"

#include <tqfont.h>
#include <tqpushbutton.h>
#include <klocale.h>
#include "defines.h"

#define THIN_BORDER 4

MeetingLine::MeetingLine(bool isOwner, bool serverIsReader, bool serverLine,
						 TQWidget *parent, const char *name)
: TQFrame(parent, name)
{
	setFrameStyle(Panel | (serverLine ? Raised : Plain));

	// Top tqlayout
	hbl = new TQHBoxLayout(this, THIN_BORDER + frameWidth());

	/* TriCheckBox */
	tcb = new MeetingCheckBox(MeetingCheckBox::Ready, isOwner, serverIsReader,
                              this);
	if ( !XOR(isOwner, serverIsReader) ) tcb->setEnabled(FALSE);
	else connect(tcb, TQT_SIGNAL(changed(int)), TQT_SLOT(_typeChanged(int)));
	hbl->addWidget(tcb);

    /* Name */
	lname = new TQLabel(" ", this);
	lname->setAlignment(AlignCenter);
	lname->setFrameStyle(TQFrame::Panel | TQFrame::Sunken);
	lname->setLineWidth(2);
	lname->setMidLineWidth(3);
    TQFont f = lname->font();
    f.setBold(TRUE);
    lname->setFont(f);
	lname->setFixedSize(lname->fontMetrics().maxWidth()*NAME_MAX_LENGTH,
						lname->sizeHint().height());
	hbl->addWidget(lname);
	hbl->addStretch(1);

	// Nb humans
	labH = new TQLabel(this);
	hbl->addWidget(labH);

	// Nb AIs
	labAI = new TQLabel(this);
	hbl->addWidget(labAI);

	// talker
	qle = new TQLineEdit(this);
	qle->setMaxLength(TALKER_MAX_LENGTH);
	qle->setFont( TQFont("fixed", 12, TQFont::Bold) );
	qle->setFixedSize(qle->fontMetrics().maxWidth()*TALKER_MAX_LENGTH,
					  qle->sizeHint().height());
	connect(qle, TQT_SIGNAL(textChanged(const TQString &)),
			TQT_SLOT(_textChanged(const TQString &)));
	qle->setEnabled(isOwner);
	hbl->addWidget(qle);
}

void MeetingLine::setData(const ExtData &ed)
{
	bds = ed.bds;
	uint nbh = 0, nba = 0;
	for (uint i=0; i<bds.count(); i++) {
		if ( bds[i].type==PlayerComboBox::Human ) nbh++;
		else if ( bds[i].type==PlayerComboBox::AI ) nba++;
	}
	labH->setText(i18n("Hu=%1").tqarg(nbh));
	labAI->setText(i18n("AI=%1").tqarg(nba));
 	lname->setText(bds[0].name);
	setType(ed.type);
	setText(ed.text);
}

void MeetingLine::data(ExtData &ed) const
{
	ed.bds  = bds;
	ed.type = tcb->type();
	ed.text = text();
}

/*****************************************************************************/
PlayerLine::PlayerLine(PlayerComboBox::Type type, const TQString &txt,
					   bool humanSetting, bool AISetting,
					   bool canBeEmpty, bool acceptAI,
					   TQWidget *parent, const char *name)
: TQFrame(parent, name), hs(humanSetting), as(AISetting)
{
	setFrameStyle(Panel | Raised);

	// Top tqlayout
	TQHBoxLayout *hbl;
	hbl = new TQHBoxLayout(this, THIN_BORDER + frameWidth());

	/* CheckBox */
	pcb = new PlayerComboBox(type, canBeEmpty, acceptAI, this);
	connect(pcb, TQT_SIGNAL(changed(int)), TQT_SLOT(typeChangedSlot(int)));
	hbl->addWidget(pcb);

    /* Name */
	edit = new TQLineEdit(txt, this);
	edit->setMaxLength(NAME_MAX_LENGTH);
	edit->setFixedSize(edit->fontMetrics().maxWidth()*(NAME_MAX_LENGTH+2),
					   edit->sizeHint().height());
	hbl->addWidget(edit);

	/* settings button */
	setting = new TQPushButton(i18n("Settings"), this);
	connect(setting, TQT_SIGNAL(clicked()), TQT_SLOT(setSlot()));
	hbl->addWidget(setting);

	typeChangedSlot(type);
}

void PlayerLine::typeChangedSlot(int t)
{
	edit->setEnabled(type()!=PlayerComboBox::None);
	setting->setEnabled( (type()==PlayerComboBox::Human && hs)
						 || (type()==PlayerComboBox::AI && as) );
	emit typeChanged(t);
}

void PlayerLine::setSlot()
{
	if ( type()==PlayerComboBox::Human ) emit setHuman();
	else emit setAI();
}

/*****************************************************************************/
GWidgetList::GWidgetList(uint interval, TQWidget *parent, const char * name)
	: TQWidget(parent, name), vbl(this, interval)
{
	widgets.setAutoDelete(TRUE);
}

void GWidgetList::append(TQWidget *wi)
{
	vbl.addWidget(wi);
	wi->show();
	widgets.append(wi);
}

void GWidgetList::remove(uint i)
{
	widgets.remove(i);
}