-
Notifications
You must be signed in to change notification settings - Fork 1
/
qgraphicsmusclegroup.cpp
44 lines (34 loc) · 1.47 KB
/
qgraphicsmusclegroup.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
#include "qgraphicsmusclegroup.h"
#include <QGraphicsSceneMouseEvent>
#include <QPen>
void QGraphicsMuscleGroup::addPathItem(QGraphicsPathItem *item) {
addToGroup(item);
shapePath += item->path();
}
QGraphicsMuscleGroup::QGraphicsMuscleGroup(int _bits):muscleGroupBits(_bits),baseColor(Qt::red) {
hoverColor = Qt::blue;
setAcceptHoverEvents(true);
}
int QGraphicsMuscleGroup::bits() const { return muscleGroupBits; }
void QGraphicsMuscleGroup::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
setColor(hoverColor);
}
void QGraphicsMuscleGroup::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
setColor(baseColor);
}
void QGraphicsMuscleGroup::setBaseColor(QColor _baseColor) { baseColor = _baseColor; }
void QGraphicsMuscleGroup::setHoverColor(QColor _hoverColor) { hoverColor = _hoverColor; }
void QGraphicsMuscleGroup::setColor(QColor color) {
QList<QGraphicsItem *> children = childItems();
foreach (QGraphicsItem *child, children) {
QGraphicsPathItem *pathItem = dynamic_cast<QGraphicsPathItem *>(child);
if (pathItem!=nullptr) {
pathItem->setPen(QPen(color, 10.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
pathItem->setBrush(color);
}
}
}
QPainterPath QGraphicsMuscleGroup::shape() const { return shapePath; }
void QGraphicsMuscleGroup::mousePressEvent(QGraphicsSceneMouseEvent *evt) {
emit pressed(muscleGroupBits, evt->modifiers().testFlag(Qt::ShiftModifier));
}