imagemousearea.cpp 535 Bytes
Newer Older
1 2 3
#include "imagemousearea.h"
#include <QImage>

4
ImageMouseArea::ImageMouseArea(QQuickItem *parent) : QQuickItem(parent) {
5 6 7 8
    setAcceptedMouseButtons(Qt::LeftButton);
    setClip(true);
}

9
bool ImageMouseArea::contains(const QPointF &point) const {
10
    auto newString = m_imageName;
11
    QImage image(newString.replace("file://", ""));
12

13
    return image.rect().contains(point.toPoint()) && qAlpha(image.pixel(point.toPoint())) > 0;
14 15
}

16
void ImageMouseArea::mousePressEvent(QMouseEvent *event) {
17 18 19
    emit clicked();
    event->accept();
}