-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathAbilityCell.cpp
80 lines (68 loc) · 2.06 KB
/
AbilityCell.cpp
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
#include "AbilityCell.h"
#include "Panel.h"
#include "Ability.h"
#include "Sprite.h"
using namespace qge;
AbilityCell::AbilityCell(int width, int height, Ability *ability):
picture_(new QGraphicsPixmapItem()),
background_(new Panel()),
ability_(ability)
{
picture_->setParentItem(background_->getGraphicsItem());
background_->setWidth(width);
background_->setHeight(height);
connect(background_.get(),&Panel::clicked,this,&AbilityCell::onClicked_);
draw_();
}
/// Sets the Ability that the AbilityCell should be visualizing.
void AbilityCell::setAbility(Ability *ability)
{
ability_ = ability;
draw_();
}
/// Returns the Ability of the AbilityCell.
Ability *AbilityCell::ability()
{
return ability_;
}
/// Sets the width and height of the AbilityCell.
void AbilityCell::setSize(int width, int height)
{
background_->setWidth(width);
background_->setHeight(height);
}
/// Sets the background color of the AbilityCell.
/// This works exactly the same as ItemCell::setBackgroundColor().
void AbilityCell::setBackgroundColor(const QColor &color)
{
background_->setBackgroundColor(color);
}
/// Sets the background of the AbilityCell to a QPixmap.
/// @see setBackgroundColor()
void AbilityCell::setBackgroundPixmap(const QPixmap &pixmap)
{
background_->setBackgroundPixmap(pixmap);
}
QGraphicsItem *AbilityCell::getGraphicsItem()
{
return background_->getGraphicsItem();
}
/// Executed when the AbilityCell is clicked.
/// Will simply emit clicked().
void AbilityCell::onClicked_(Panel *panel, QPointF pos, int button)
{
emit clicked(this,button);
}
/// Draws the AbilityCell in its current state.
void AbilityCell::draw_()
{
// draw default icon
double width = background_->width();
double height = background_->height();
picture_->setPixmap(QPixmap(":/resources/graphics/misc/defaultEntity.png").scaled(width-20,height-20));
picture_->setPos(10,10);
// overwrite with ability's icon if has ability
if (ability_ != nullptr){
picture_->setPixmap(ability_->icon().scaled(width-20,height-20));
}
}