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
|
// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License version 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
#include <iostream>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqfont.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <tdeglobalsettings.h>
#include "board.h"
#include "estate.h"
#include "player.h"
#include "token.moc"
#define TOKEN_ICONSIZE 32
Token::Token(Player *player, AtlantikBoard *parent, const char *name) : TQWidget(parent, name)
{
setBackgroundMode(NoBackground); // avoid flickering
m_parentBoard = parent;
m_player = player;
connect(m_player, TQT_SIGNAL(changed(Player *)), this, TQT_SLOT(playerChanged()));
m_inJail = m_player->inJail();
m_location = m_player->location();
m_destination = 0;
qpixmap = 0;
b_recreate = true;
// Init icon
m_image = 0;
loadIcon();
setFixedSize(TQSize(TOKEN_ICONSIZE, TOKEN_ICONSIZE + TDEGlobalSettings::generalFont().pointSize()));
}
Token::~Token()
{
delete m_image;
}
Player *Token::player()
{
return m_player;
}
void Token::setLocation(Estate *location)
{
if (m_location != location)
m_location = location;
}
void Token::setDestination(Estate *estateView)
{
if (m_destination != estateView)
m_destination = estateView;
}
void Token::playerChanged()
{
if (m_imageName != m_player->image())
loadIcon();
b_recreate = true;
update();
}
void Token::loadIcon()
{
m_imageName = m_player->image();
delete m_image;
m_image = 0;
if (!m_imageName.isEmpty())
{
TQString filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName);
if (TDEStandardDirs::exists(filename))
m_image = new TQPixmap(filename);
}
if (!m_image)
{
m_imageName = "hamburger.png";
TQString filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName);
if (TDEStandardDirs::exists(filename))
m_image = new TQPixmap(filename);
}
TQWMatrix m;
m.scale(double(TOKEN_ICONSIZE) / m_image->width(), double(TOKEN_ICONSIZE) / m_image->height());
TQPixmap *scaledPixmap = new TQPixmap(TOKEN_ICONSIZE, TOKEN_ICONSIZE);
*scaledPixmap = m_image->xForm(m);
delete m_image;
m_image = scaledPixmap;
}
void Token::paintEvent(TQPaintEvent *)
{
if (b_recreate)
{
delete qpixmap;
qpixmap = new TQPixmap(width(), height());
TQPainter painter;
painter.begin(TQT_TQPAINTDEVICE(qpixmap), this);
if (m_image)
{
painter.setPen(TQt::black);
painter.setBrush(TQt::white);
painter.drawRect(0, 0, TOKEN_ICONSIZE, TOKEN_ICONSIZE);
painter.drawPixmap(0, 0, *m_image);
}
painter.setPen(TQt::black);
painter.setBrush(TQt::black);
painter.drawRect(0, TOKEN_ICONSIZE, width(), TDEGlobalSettings::generalFont().pointSize());
painter.setPen(TQt::white);
painter.setFont(TQFont(TDEGlobalSettings::generalFont().family(), TDEGlobalSettings::generalFont().pointSize(), TQFont::DemiBold));
painter.drawText(1, height()-1, (m_player ? m_player->name() : TQString()));
b_recreate = false;
}
bitBlt(this, 0, 0, qpixmap);
}
void Token::resizeEvent(TQResizeEvent *)
{
b_recreate = true;
}
|