summaryrefslogtreecommitdiffstats
path: root/weather/pixmapbutton.cpp
blob: 6ec8be586e84243a722d074dfb3d6aab37f5ef04 (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
#include "pixmapbutton.h"

// PixmapButton

PixmapButton::PixmapButton(qreal minSize, const QPixmap &pixmap, QGraphicsItem *parent)
        : QGraphicsPixmapItem(pixmap, parent)
        , m_minSize(minSize)
{
    setShapeMode(BoundingRectShape);
}

void PixmapButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event);
    emit clicked();
}

QPainterPath PixmapButton::shape() const
{
    return QGraphicsItem::shape();
}

QRectF PixmapButton::boundingRect() const
{
    QRectF result(QGraphicsPixmapItem::boundingRect());
    qreal hMargin = m_minSize < result.width() ? 0 : (m_minSize - result.width()) / 2;
    qreal vMargin = m_minSize < result.height() ? 0 : (m_minSize - result.height()) / 2;
    result.adjust(-hMargin, -vMargin, hMargin, vMargin);
    return result;
}