| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "graphicsitem.h" |
| 22 |
#include <QMovie> |
| 23 |
#include <QDebug> |
| 24 |
#include <QPainter> |
| 25 |
#include <FreeImage.h> |
| 26 |
#include "utils/imageutils.h" |
| 27 |
|
| 28 |
|
| 29 |
GraphicsMovieItem::GraphicsMovieItem(const QString &fileName, const QString &fileSuffix, QGraphicsItem *parent) |
| 30 |
: QGraphicsPixmapItem(fileName, parent) |
| 31 |
, m_qmovie(new QMovie(fileName)) |
| 32 |
// , m_qmovie(nullptr) |
| 33 |
// , m_suffix(fileSuffix) |
| 34 |
// , m_index(0) |
| 35 |
{ |
| 36 |
Q_UNUSED(fileSuffix) |
| 37 |
connect(m_qmovie, &QMovie::frameChanged, this, [ = ]() { |
| 38 |
if (!m_qmovie->currentPixmap().isNull()) { |
| 39 |
setPixmap(m_qmovie->currentPixmap()); |
| 40 |
} |
| 41 |
}); |
| 42 |
start(); //修改为函数调用 |
| 43 |
// if (fileSuffix.toUpper().contains("WEBP")) { |
| 44 |
// m_qmovie = new QMovie(fileName); |
| 45 |
// connect(m_qmovie, &QMovie::frameChanged, this, [ = ]() { |
| 46 |
// if (!m_qmovie->currentPixmap().isNull()) { |
| 47 |
// setPixmap(m_qmovie->currentPixmap()); |
| 48 |
// } |
| 49 |
// }); |
| 50 |
// m_qmovie->start(); |
| 51 |
// } else { |
| 52 |
// using namespace UnionImage_NameSpace; |
| 53 |
// m_movie.setFileName(fileName); |
| 54 |
// m_pTImer = new QTimer(this); |
| 55 |
// connect(m_pTImer, &QTimer::timeout, this, [ = ] { |
| 56 |
// this->setPixmap(QPixmap::fromImage(m_movie.next())); |
| 57 |
// }); |
| 58 |
// m_pTImer->start(100); |
| 59 |
// } |
| 60 |
} |
| 61 |
|
| 62 |
GraphicsMovieItem::~GraphicsMovieItem() |
| 63 |
{ |
| 64 |
prepareGeometryChange(); |
| 65 |
|
| 66 |
stop(); //修改为函数调用 |
| 67 |
m_qmovie->deleteLater(); |
| 68 |
m_qmovie = nullptr; |
| 69 |
// if (m_pTImer) { |
| 70 |
// m_pTImer->stop(); |
| 71 |
// m_pTImer->deleteLater(); |
| 72 |
// } |
| 73 |
} |
| 74 |
|
| 75 |
void GraphicsMovieItem::start() |
| 76 |
{ |
| 77 |
// m_pTImer->start(100); |
| 78 |
m_qmovie->start(); |
| 79 |
} |
| 80 |
|
| 81 |
void GraphicsMovieItem::stop() |
| 82 |
{ |
| 83 |
// m_pTImer->stop(); |
| 84 |
m_qmovie->stop(); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
GraphicsPixmapItem::GraphicsPixmapItem(const QPixmap &pixmap) |
| 89 |
: QGraphicsPixmapItem(pixmap, nullptr) |
| 90 |
{ |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
GraphicsPixmapItem::~GraphicsPixmapItem() |
| 95 |
{ |
| 96 |
prepareGeometryChange(); |
| 97 |
} |
| 98 |
|
| 99 |
void GraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
| 100 |
{ |
| 101 |
Q_UNUSED(option); |
| 102 |
Q_UNUSED(widget); |
| 103 |
|
| 104 |
// const QTransform ts = painter->transform(); |
| 105 |
QGraphicsPixmapItem::paint(painter, option, widget); |
| 106 |
return; |
| 107 |
// if (ts.type() == QTransform::TxScale && ts.m11() < 1) { |
| 108 |
// painter->setRenderHint(QPainter::SmoothPixmapTransform, |
| 109 |
// (transformationMode() == Qt::SmoothTransformation)); |
| 110 |
|
| 111 |
// QPixmap pixmap; |
| 112 |
|
| 113 |
// if (qIsNull(cachePixmap.first - ts.m11())) { |
| 114 |
// pixmap = cachePixmap.second; |
| 115 |
// } else { |
| 116 |
// pixmap = this->pixmap().transformed(painter->transform(), transformationMode()); |
| 117 |
// cachePixmap = qMakePair(ts.m11(), pixmap); |
| 118 |
// } |
| 119 |
|
| 120 |
// pixmap.setDevicePixelRatio(painter->device()->devicePixelRatioF()); |
| 121 |
// painter->resetTransform(); |
| 122 |
// painter->drawPixmap(offset() + QPointF(ts.dx(), ts.dy()), pixmap); |
| 123 |
// painter->setTransform(ts); |
| 124 |
// } else { |
| 125 |
// QGraphicsPixmapItem::paint(painter, option, widget); |
| 126 |
// } |
| 127 |
} |