This commit is contained in:
Gary Wang 2019-09-30 13:11:43 +08:00
parent d106d9beee
commit 89c21bc90b
5 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,7 @@ BottomButtonGroup::BottomButtonGroup(QWidget *parent)
"QPushButton {" "QPushButton {"
"background-color:rgba(225,255,255,0);" "background-color:rgba(225,255,255,0);"
"color: white;" "color: white;"
"border-style: none;"
"}"); "}");
auto newBtn = [](QString text) -> QPushButton * { auto newBtn = [](QString text) -> QPushButton * {

View File

@ -6,6 +6,8 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QUrl> #include <QUrl>
#include <QGraphicsSvgItem> #include <QGraphicsSvgItem>
#include <QMovie>
#include <QLabel>
GraphicsScene::GraphicsScene(QObject *parent) GraphicsScene::GraphicsScene(QObject *parent)
: QGraphicsScene(parent) : QGraphicsScene(parent)
@ -42,3 +44,16 @@ void GraphicsScene::showSvg(const QString &filepath)
m_theThing = svgItem; m_theThing = svgItem;
this->setSceneRect(m_theThing->boundingRect()); this->setSceneRect(m_theThing->boundingRect());
} }
void GraphicsScene::showGif(const QString &filepath)
{
this->clear();
QMovie * movie = new QMovie(filepath);
QLabel * label = new QLabel;
label->setStyleSheet("background-color:white;");
label->setMovie(movie);
this->addWidget(label);
movie->start();
m_theThing = this->addRect(QRect(QPoint(0, 0), movie->scaledSize()));
this->setSceneRect(m_theThing->boundingRect());
}

View File

@ -13,6 +13,7 @@ public:
void showImage(const QPixmap &pixmap); void showImage(const QPixmap &pixmap);
void showText(const QString &text); void showText(const QString &text);
void showSvg(const QString &filepath); void showSvg(const QString &filepath);
void showGif(const QString &filepath);
private: private:
QGraphicsItem * m_theThing; QGraphicsItem * m_theThing;

View File

@ -40,6 +40,11 @@ void GraphicsView::showSvg(const QString &filepath)
scene()->showSvg(filepath); scene()->showSvg(filepath);
} }
void GraphicsView::showGif(const QString &filepath)
{
scene()->showGif(filepath);
}
GraphicsScene *GraphicsView::scene() const GraphicsScene *GraphicsView::scene() const
{ {
return qobject_cast<GraphicsScene*>(QGraphicsView::scene()); return qobject_cast<GraphicsScene*>(QGraphicsView::scene());
@ -138,6 +143,8 @@ void GraphicsView::dropEvent(QDropEvent *event)
if (filePath.endsWith(".svg")) { if (filePath.endsWith(".svg")) {
showSvg(filePath); showSvg(filePath);
} else if (filePath.endsWith(".gif")) {
showGif(filePath);
} else { } else {
QImageReader imageReader(filePath); QImageReader imageReader(filePath);
QImage::Format imageFormat = imageReader.imageFormat(); QImage::Format imageFormat = imageReader.imageFormat();

View File

@ -12,6 +12,7 @@ public:
void showImage(const QPixmap &pixmap); void showImage(const QPixmap &pixmap);
void showText(const QString &text); void showText(const QString &text);
void showSvg(const QString &filepath); void showSvg(const QString &filepath);
void showGif(const QString &filepath);
GraphicsScene * scene() const; GraphicsScene * scene() const;
void setScene(GraphicsScene *scene); void setScene(GraphicsScene *scene);