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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
// 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 <tqtooltip.h>
#include <tqpainter.h>
#include <tqtimer.h>
#include <tqwmatrix.h>
#include <tqcursor.h>
#include <kdebug.h>
#include <tdeversion.h>
#include <kdialogbase.h>
#include <tdeglobalsettings.h>
#include <tdelocale.h>
#include <kpixmapeffect.h>
#include <tdepopupmenu.h>
#include <kstandarddirs.h>
#include <kstringhandler.h>
#include <player.h>
#include <estate.h>
#include "estateview.moc"
#include "config.h"
EstateView::EstateView(Estate *estate, EstateOrientation orientation, const TQString &_icon, bool indicateUnowned, bool highliteUnowned, bool darkenMortgaged, bool quartzEffects, TQWidget *parent, const char *name) : TQWidget(parent, name, WResizeNoErase)
{
m_estate = estate;
m_orientation = orientation;
m_indicateUnowned = indicateUnowned;
m_highliteUnowned = highliteUnowned;
m_darkenMortgaged = darkenMortgaged;
m_quartzEffects = quartzEffects;
setBackgroundMode(NoBackground); // avoid flickering
qpixmap = 0;
b_recreate = true;
m_quartzBlocks = 0;
m_recreateQuartz = true;
pe = 0;
updatePE();
icon = new TQPixmap(locate("data", "atlantik/pics/" + _icon));
icon = rotatePixmap(icon);
updateToolTip();
}
void EstateView::updateToolTip()
{
TQToolTip::remove(this);
if ( m_estate )
{
TQString toolTip = m_estate->name();
if ( m_estate->isOwned() )
{
toolTip.append( "\n" + i18n("Owner: %1").arg( m_estate->owner()->name() ) );
if ( m_estate->isMortgaged() )
toolTip.append( "\n" + i18n("Unmortgage Price: %1").arg( m_estate->unmortgagePrice() ) );
else
toolTip.append( "\n" + i18n("Mortgage Value: %1").arg( m_estate->mortgagePrice() ) );
if ( m_estate->canSellHouses() )
toolTip.append( "\n" + i18n("House Value: %1").arg( m_estate->houseSellPrice() ) );
if ( m_estate->canBuyHouses() )
toolTip.append( "\n" + i18n("House Price: %1").arg( m_estate->housePrice() ) );
}
else if ( m_estate->canBeOwned() )
toolTip.append( "\n" + i18n("Price: %1").arg( m_estate->price() ) );
else if ( m_estate->money() )
toolTip.append( "\n" + i18n("Money: %1").arg( m_estate->money() ) );
TQToolTip::add( this, toolTip );
}
}
void EstateView::setViewProperties(bool indicateUnowned, bool highliteUnowned, bool darkenMortgaged, bool quartzEffects)
{
if (m_indicateUnowned != indicateUnowned)
{
m_indicateUnowned = indicateUnowned;
b_recreate = true;
updatePE();
}
if (m_highliteUnowned != highliteUnowned)
{
m_highliteUnowned = highliteUnowned;
b_recreate = true;
}
if (m_darkenMortgaged != darkenMortgaged)
{
m_darkenMortgaged = darkenMortgaged;
b_recreate = true;
}
if (m_quartzEffects != quartzEffects)
{
m_quartzEffects = quartzEffects;
b_recreate = true;
// m_recreateQuartz = true;
}
if (b_recreate || m_recreateQuartz)
update();
}
TQPixmap *EstateView::rotatePixmap(TQPixmap *p)
{
if (p==0 || p->isNull())
return 0;
TQWMatrix m;
switch(m_orientation)
{
case East:
m.rotate(90);
break;
case West:
m.rotate(-90);
break;
case South:
m.rotate(180);
break;
default:;
}
*p = p->xForm(m);
return p;
}
KPixmap *EstateView::rotatePixmap(KPixmap *p)
{
if (p==0 || p->isNull())
return 0;
TQWMatrix m;
switch(m_orientation)
{
case East:
m.rotate(90);
break;
case West:
m.rotate(-90);
break;
case South:
m.rotate(180);
break;
default:;
}
*p = p->xForm(m);
return p;
}
void EstateView::updatePE()
{
// Don't show a when a property is not unowned, cannot be owned at all
// or when the user has configured Atlantik not to show them.
if (m_estate->isOwned() || !m_estate->canBeOwned() || m_indicateUnowned==false)
{
delete pe;
pe = 0;
}
else
{
if (pe==0)
{
// Display a coloured portfolioestate to indicate property is
// for sale
pe = new PortfolioEstate(m_estate, 0, true, this, "board-portfolioestate");
repositionPortfolioEstate();
pe->show();
}
else if (!pe->isVisible())
pe->show();
}
}
void EstateView::estateChanged()
{
updateToolTip();
b_recreate = true;
m_recreateQuartz = true;
update();
updatePE();
}
void EstateView::repositionPortfolioEstate()
{
if (pe!=0)
{
int x = (m_orientation == West ? (width()-2 - pe->width()) : 2);
int y = (m_orientation == North ? (height()-2 - pe->height()) : 2);
pe->setGeometry(x, y, pe->width(), pe->height());
}
}
void EstateView::paintEvent(TQPaintEvent *)
{
m_titleHeight = height()/4;
m_titleWidth = width()/4;
if (m_recreateQuartz)
{
if (m_quartzBlocks)
{
delete m_quartzBlocks;
m_quartzBlocks = 0;
}
if (m_estate->color().isValid())
{
m_quartzBlocks = new KPixmap();
if (m_orientation == North || m_orientation == South)
m_quartzBlocks->resize(25, m_titleHeight-2);
else
m_quartzBlocks->resize(25, m_titleWidth-2);
drawQuartzBlocks(m_quartzBlocks, *m_quartzBlocks, m_estate->color().light(60), m_estate->color());
m_quartzBlocks = rotatePixmap(m_quartzBlocks);
}
m_recreateQuartz = false;
b_recreate = true;
}
if (b_recreate)
{
delete qpixmap;
qpixmap = new TQPixmap(width(), height());
TQColor greenHouse(0, 255, 0);
TQColor redHotel(255, 51, 51);
TQPainter painter;
painter.begin(TQT_TQPAINTDEVICE(qpixmap), this);
painter.setPen(TQt::black);
if (m_darkenMortgaged==true && m_estate->isMortgaged())
painter.setBrush(m_estate->bgColor().light(10));
else if (m_highliteUnowned==true && m_estate->canBeOwned() && !m_estate->isOwned())
painter.setBrush(m_estate->bgColor().light(190));
else
painter.setBrush(m_estate->bgColor());
painter.drawRect(rect());
// Paint icon only when it exists and fits
if (icon!=0 && width() > icon->width() && height() > icon->height())
painter.drawPixmap( (width() - icon->width())/2, (height() - icon->height())/2, *icon);
if (m_estate->color().isValid())
{
KPixmap* quartzBuffer = new KPixmap;
if (m_orientation == North || m_orientation == South)
quartzBuffer->resize(25, m_titleHeight-2);
else
quartzBuffer->resize(m_titleWidth-2, 25);
TQPainter quartzPainter;
quartzPainter.begin(TQT_TQPAINTDEVICE(quartzBuffer), this);
painter.setBrush(m_estate->color());
switch(m_orientation)
{
case North:
painter.drawRect(0, 0, width(), m_titleHeight);
if (m_quartzEffects && m_quartzBlocks)
{
quartzPainter.drawPixmap(0, 0, *m_quartzBlocks);
painter.drawPixmap(1, 1, *quartzBuffer);
}
if (m_estate->houses() > 0)
{
if (m_estate->houses() == 5)
{
// Hotel
painter.setBrush(redHotel);
painter.drawRect(2, 2, (width()/2)-4, (m_titleHeight)-4);
}
else
{
// Houses
painter.setBrush(greenHouse);
int h = (m_titleHeight)-4, w = (m_titleWidth)-4;
for( unsigned int i=0 ; i < m_estate->houses() ; i++ )
painter.drawRect(2+(i*(w+2)), 2, w, h);
}
}
break;
case South:
painter.drawRect(0, height()-(m_titleHeight), width(), m_titleHeight);
if (m_quartzEffects && m_quartzBlocks)
{
quartzPainter.drawPixmap(0, 0, *m_quartzBlocks);
painter.drawPixmap(width()-quartzBuffer->width()-1, height()-m_titleHeight+1, *quartzBuffer);
}
if (m_estate->houses() > 0)
{
if (m_estate->houses() == 5)
{
// Hotel
painter.setBrush(redHotel);
painter.drawRect(2, (3*(m_titleHeight))+2, (width()/2)-4, (m_titleHeight)-4);
}
else
{
// Houses
painter.setBrush(greenHouse);
int h = (m_titleHeight)-4, w = (m_titleWidth)-4;
for( unsigned int i=0 ; i < m_estate->houses() ; i++ )
painter.drawRect(2+(i*(w+2)), (3*(m_titleHeight))+2, w, h);
}
}
break;
case West:
painter.drawRect(0, 0, m_titleWidth, height());
if (m_quartzEffects && m_quartzBlocks)
{
quartzPainter.drawPixmap(0, 0, *m_quartzBlocks);
painter.drawPixmap(1, height()-quartzBuffer->height()-1, *quartzBuffer);
}
if (m_estate->houses() > 0)
{
if (m_estate->houses() == 5)
{
// Hotel
painter.setBrush(redHotel);
painter.drawRect(2, 2, (m_titleWidth)-4, (height()/2)-4);
}
else
{
// Houses
painter.setBrush(greenHouse);
int h = (m_titleHeight)-4, w = (m_titleWidth)-4;
for( unsigned int i=0 ; i < m_estate->houses() ; i++ )
painter.drawRect(2, 2+(i*(h+2)), w, h);
}
}
break;
case East:
painter.drawRect(width()-(m_titleWidth), 0, m_titleWidth, height());
if (m_quartzEffects && m_quartzBlocks)
{
quartzPainter.drawPixmap(0, 0, *m_quartzBlocks);
painter.drawPixmap(width()-quartzBuffer->width()-1, 1, *quartzBuffer);
}
if (m_estate->houses() > 0)
{
if (m_estate->houses() == 5)
{
// Hotel
painter.setBrush(redHotel);
painter.drawRect((3*(m_titleWidth))+2, 2, (m_titleWidth)-4, (height()/2)-4);
}
else
{
// Houses
painter.setBrush(greenHouse);
int h = (m_titleHeight)-4, w = (m_titleWidth)-4;
for( unsigned int i=0 ; i < m_estate->houses() ; i++ )
painter.drawRect((3*(m_titleWidth))+2, 2+(i*(h+2)), w, h);
}
}
break;
}
quartzPainter.end();
delete quartzBuffer;
}
TQFont font = TQFont( TDEGlobalSettings::generalFont().family(), TDEGlobalSettings::generalFont().pointSize(), TQFont::Normal );
painter.setFont(font);
TQString estateName = m_estate->name();
#if defined(TDE_MAKE_VERSION)
#if TDE_VERSION >= TDE_MAKE_VERSION(3,2,0)
if ( m_estate->color().isValid() && ( m_orientation == West || m_orientation == East ) )
estateName = KStringHandler::rPixelSqueeze( m_estate->name(), TQFontMetrics( font ), 3*width()/4 );
else
estateName = KStringHandler::rPixelSqueeze( m_estate->name(), TQFontMetrics( font ), width() );
#endif
#endif
if (m_estate->color().isValid() && m_orientation == West)
painter.drawText( width()/4 + 2, height()/2, estateName );
else
painter.drawText(2, height()/2, estateName );
b_recreate = false;
}
bitBlt(this, 0, 0, qpixmap);
}
void EstateView::resizeEvent(TQResizeEvent *)
{
m_recreateQuartz = true;
b_recreate = true;
TQTimer::singleShot(0, this, TQT_SLOT(slotResizeAftermath()));
}
void EstateView::mousePressEvent(TQMouseEvent *e)
{
if (e->button()==TQt::RightButton && m_estate->isOwned())
{
TDEPopupMenu *rmbMenu = new TDEPopupMenu(this);
rmbMenu->insertTitle(m_estate->name());
if (m_estate->isOwnedBySelf())
{
Player *player = m_estate->owner();
// Mortgage toggle
if (m_estate->isMortgaged())
{
rmbMenu->insertItem(i18n("Unmortgage"), 0);
if (!m_estate->canToggleMortgage() || player->hasDebt())
rmbMenu->setItemEnabled(0, false);
}
else
{
rmbMenu->insertItem(i18n("Mortgage"), 0);
if (!m_estate->canToggleMortgage())
rmbMenu->setItemEnabled(0, false);
}
// Estate construction
if (m_estate->houses()>=4)
rmbMenu->insertItem(i18n("Build Hotel"), 1);
else
rmbMenu->insertItem(i18n("Build House"), 1);
if (!m_estate->canBuyHouses() || player->hasDebt())
rmbMenu->setItemEnabled(1, false);
// Estate destruction
if (m_estate->houses()==5)
rmbMenu->insertItem(i18n("Sell Hotel"), 2);
else
rmbMenu->insertItem(i18n("Sell House"), 2);
if (!(m_estate->canSellHouses()))
rmbMenu->setItemEnabled(2, false);
}
else
{
// Request trade
if (Player *player = m_estate->owner())
rmbMenu->insertItem(i18n("Request Trade with %1").arg(player->name()), 3);
}
TDEPopupMenu *pm = dynamic_cast<TDEPopupMenu *>(rmbMenu);
if (pm) {
connect(pm, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuAction(int)));
}
TQPoint g = TQCursor::pos();
rmbMenu->exec(g);
delete rmbMenu;
}
else if (e->button()==TQt::LeftButton)
emit LMBClicked(m_estate);
}
void EstateView::slotResizeAftermath()
{
repositionPortfolioEstate();
}
void EstateView::slotMenuAction(int item)
{
switch (item)
{
case 0:
emit estateToggleMortgage(m_estate);
break;
case 1:
emit estateHouseBuy(m_estate);
break;
case 2:
emit estateHouseSell(m_estate);
break;
case 3:
emit newTrade(m_estate->owner());
break;
}
}
// Kudos to Gallium <[email protected]> for writing the Quartz KWin style and
// letting me use the ultra slick algorithm!
void EstateView::drawQuartzBlocks(KPixmap *pi, KPixmap &p, const TQColor &c1, const TQColor &c2)
{
TQPainter px;
if (pi==0 || pi->isNull())
return;
px.begin(pi);
KPixmapEffect::gradient(p, c1, c2, KPixmapEffect::HorizontalGradient);
px.fillRect( 2, 1, 3, 3, c1.light(120) );
px.fillRect( 2, 5, 3, 3, c1 );
px.fillRect( 2, 9, 3, 3, c1.light(110) );
px.fillRect( 2, 13, 3, 3, c1 );
px.fillRect( 6, 1, 3, 3, c1.light(110) );
px.fillRect( 6, 5, 3, 3, c2.light(110) );
px.fillRect( 6, 9, 3, 3, c1.light(120) );
px.fillRect( 6, 13, 3, 3, c2.light(130) );
px.fillRect( 10, 5, 3, 3, c1.light(110) );
px.fillRect( 10, 9, 3, 3, c2.light(120) );
px.fillRect( 10, 13, 3, 3, c2.light(150) );
px.fillRect( 14, 1, 3, 3, c1.dark(110) );
px.fillRect( 14, 9, 3, 3, c2.light(120) );
px.fillRect( 14, 13, 3, 3, c1.dark(120) );
px.fillRect( 18, 5, 3, 3, c1.light(110) );
px.fillRect( 18, 13, 3, 3, c1.dark(110) );
px.fillRect( 22, 9, 3, 3, c2.light(120));
px.fillRect( 22, 13, 3, 3, c2.light(110) );
}
|