qt5base-lts/tests/manual/gestures/graphicsview/imageitem.cpp
Lucie Gérard 05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00

56 lines
1.2 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "imageitem.h"
#include "gestures.h"
#include <QPainter>
#include <QEvent>
ImageItem::ImageItem(const QImage &image)
{
setImage(image);
}
void ImageItem::setImage(const QImage &image)
{
image_ = image;
pixmap_ = QPixmap::fromImage(image.scaled(400, 400, Qt::KeepAspectRatio));
update();
}
QImage ImageItem::image() const
{
return image_;
}
QRectF ImageItem::boundingRect() const
{
const QSize size = pixmap_.size();
return QRectF(0, 0, size.width(), size.height());
}
void ImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
painter->drawPixmap(0, 0, pixmap_);
}
GestureImageItem::GestureImageItem(const QImage &image)
: ImageItem(image)
{
grabGesture(Qt::PanGesture);
grabGesture(ThreeFingerSlideGesture::Type);
}
bool GestureImageItem::event(QEvent *event)
{
if (event->type() == QEvent::Gesture) {
qDebug("gestureimageitem: gesture triggered");
return true;
}
return ImageItem::event(event);
}
#include "moc_imageitem.cpp"