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
|
/*
* Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Header include
#include "EffectItem.h"
// Sigmod includes
#include <sigmod/MapEffect.h>
// Qt includes
#include <QtGui/QPainter>
// Standard includes
#include <climits>
using namespace Sigmod;
using namespace Sigmodr::Widgets;
EffectItem::EffectItem(Sigmod::Map* map, MapEffect* effect, QGraphicsScene* parent) :
MapItem(map, parent),
m_effect(effect)
{
connect(m_effect, SIGNAL(changed()), this, SLOT(effectChanged()));
connect(m_effect, SIGNAL(error(QString)), this, SLOT(effectChanged()));
setOpacity(.5);
setZValue(INT_MAX);
m_tag->setText(QString::number(m_effect->id()));
effectChanged();
}
QRectF EffectItem::boundingRect() const
{
QPainterPath path = m_effect->area();
if (path.isEmpty())
return QRect(0, 0, 32, 32);
return m_effect->area().boundingRect();
}
void EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
painter->setBrush(QBrush(Qt::red));
painter->setPen(QPen(Qt::black, 2));
QPainterPath path = m_effect->area();
if (path.isEmpty())
painter->drawRect(0, 0, 32, 32);
else
painter->drawPath(path);
MapItem::paint(painter, option, widget);
}
int EffectItem::type() const
{
return Type;
}
void EffectItem::moveTo(const QPoint& point)
{
m_effect->setPosition(point);
}
void EffectItem::effectChanged()
{
setPos(m_effect->position());
resetLabel();
update();
}
void EffectItem::resetLabel()
{
m_label->setText(m_effect->name());
QSizeF size = m_label->boundingRect().size() / 2 - boundingRect().size() / 2;
m_label->setPos(-size.width(), -size.height());
}
|