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
|
#include <kdebug.h>
#include <tdelocale.h>
#include <tqlayout.h>
#include <tqtable.h>
#include <tqwidget.h>
#include <tqheader.h>
#include <tqstring.h>
#include "scoreboard.h"
ScoreBoard::ScoreBoard(TQWidget *parent, const char *name)
: TQTable(1, 1, parent, name)
{
vh = verticalHeader();
hh = horizontalHeader();
vh->setLabel(numRows() - 1, i18n("Par"));
hh->setLabel(numCols() - 1, i18n("Total"));
setFocusPolicy(TQ_NoFocus);
setRowReadOnly(0, true);
setRowReadOnly(1, true);
}
void ScoreBoard::newHole(int par)
{
int _numCols = numCols();
insertColumns(_numCols - 1);
hh->setLabel(numCols() - 2, TQString::number(numCols() - 1));
setText(numRows() - 1, numCols() - 2, TQString::number(par));
setColumnWidth(numCols() - 2, 40);
// update total
int tot = 0;
for (int i = 0; i < numCols() - 1; ++i)
tot += text(numRows() - 1, i).toInt();
setText(numRows() - 1, numCols() - 1, TQString::number(tot));
// shrink cell...
setColumnWidth(numCols() - 2, 3);
// and make it big enough for the numbers
adjustColumn(numCols() - 2);
}
void ScoreBoard::newPlayer(const TQString &name)
{
//kdDebug(12007) << "name of new player is " << name << endl;
insertRows(numRows() - 1);
vh->setLabel(numRows() - 2, name);
setRowReadOnly(numRows() - 2, true);
}
void ScoreBoard::setScore(int id, int hole, int score)
{
//kdDebug(12007) << "set score\n";
setText(id - 1, hole - 1, score > 0? TQString::number(score) : TQString(""));
TQString name;
setText(id - 1, numCols() - 1, TQString::number(total(id, name)));
if (hole >= numCols() - 2)
ensureCellVisible(id - 1, numCols() - 1);
else
ensureCellVisible(id - 1, hole - 1);
// shrink cell...
setColumnWidth(hole - 1, 3);
// and make it big enough for the numbers
adjustColumn(hole - 1);
setCurrentCell(id - 1, hole - 1);
}
void ScoreBoard::parChanged(int hole, int par)
{
setText(numRows() - 1, hole - 1, TQString::number(par));
// update total
int tot = 0;
for (int i = 0; i < numCols() - 1; ++i)
tot += text(numRows() - 1, i).toInt();
setText(numRows() - 1, numCols() - 1, TQString::number(tot));
}
int ScoreBoard::total(int id, TQString &name)
{
int tot = 0;
for (int i = 0; i < numCols() - 1; i++)
tot += text(id - 1, i).toInt();
name = vh->label(id - 1);
//kdDebug(12007) << "tot is " << tot << endl;
return tot;
}
#include "scoreboard.moc"
|