summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/citizenquartz/clockbutton.cpp
blob: 7b8689194b7124949222ffc47d50b00dac1d157d (plain)
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
#include "clockbutton.h"

#include <QPainter>

ClockButton::ClockButton(const QString &name, QGraphicsItem *parent) : QGraphicsItem(parent)
{
    setObjectName(name);
    setToolTip(name);
    setAcceptedMouseButtons(Qt::LeftButton);
}

QRectF ClockButton::boundingRect() const
{
    return QRectF(-10.0, -10.0, 20.0, 20.0);
}

QPainterPath ClockButton::shape() const
{
    QPainterPath path;
    path.addRoundedRect(boundingRect(), 15.0, 15.0, Qt::RelativeSize);

    return path;
}

void ClockButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    painter->setBrush(Qt::black);
    painter->drawPath(shape());
}

void ClockButton::mousePressEvent(QGraphicsSceneMouseEvent *)
{
    emit pressed();
}

void ClockButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    emit released();
}