mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
update qqt gif widget, tested in gif test dialog
This commit is contained in:
parent
2c890b5869
commit
639f086896
@ -1,5 +1,25 @@
|
||||
#include "qqtgifwidget.h"
|
||||
|
||||
QQtGifWidget::QQtGifWidget ( QWidget* parent ) : QWidget ( parent )
|
||||
QQtGifWidget::QQtGifWidget ( QWidget* parent ) : QQtWidget ( parent )
|
||||
{
|
||||
m_movie = new QMovie ( this );
|
||||
m_frameTimer = new QTimer ( this );
|
||||
m_frameTimer->setSingleShot ( false );
|
||||
connect ( m_frameTimer, SIGNAL ( timeout() ),
|
||||
this, SLOT ( slotFramePlayback() ) );
|
||||
}
|
||||
|
||||
void QQtGifWidget::setGifFile ( QString gifFile )
|
||||
{
|
||||
m_movie->setFileName ( gifFile );
|
||||
m_movie->start();
|
||||
m_frameTimer->setInterval ( m_movie->speed() );
|
||||
m_frameTimer->start();
|
||||
/*100ms*/
|
||||
//pline() << m_movie->speed();
|
||||
}
|
||||
|
||||
void QQtGifWidget::slotFramePlayback()
|
||||
{
|
||||
setPixmap ( m_movie->currentImage() );
|
||||
}
|
||||
|
@ -1,23 +1,32 @@
|
||||
#ifndef QQTGIFWIDGET_H
|
||||
#define QQTGIFWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMovie>
|
||||
#include <qqtwidget.h>
|
||||
#include <qqt-local.h>
|
||||
#include <qqtcore.h>
|
||||
|
||||
class QQTSHARED_EXPORT QQtGifWidget : public QWidget
|
||||
#include <QMovie>
|
||||
#include <QTimer>
|
||||
|
||||
class QQTSHARED_EXPORT QQtGifWidget : public QQtWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtGifWidget ( QWidget* parent = nullptr );
|
||||
virtual ~QQtGifWidget() {}
|
||||
|
||||
void setGifFile ( QString gifFile );
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QMovie* m_movie;
|
||||
QTimer* m_frameTimer;
|
||||
|
||||
private slots:
|
||||
void slotFramePlayback();
|
||||
};
|
||||
|
||||
#endif // QQTGIFWIDGET_H
|
||||
|
@ -116,7 +116,7 @@ contains (DEFINES, __QEXTSERIALPORT__) {
|
||||
##################Bluetooth Module###############################
|
||||
#if you use qtbluetooth, open this annotation
|
||||
DEFINES += __BLUETOOTH__
|
||||
#if you compiler QtBluetooth module manual, note this line is a good idea. default qt4 don't use bluetooth
|
||||
#if you compiler QtBluetooth module manual, note this line is a good idea. default qt4 doesn't use bluetooth
|
||||
lessThan(QT_MAJOR_VERSION, 5): DEFINES -= __BLUETOOTH__
|
||||
#condation
|
||||
contains (DEFINES, __BLUETOOTH__) {
|
||||
@ -148,7 +148,7 @@ contains (DEFINES, __CPP11__) {
|
||||
|
||||
##################MultiMedia Module###############################
|
||||
DEFINES += __MULTIMEDIA__
|
||||
#mac no multimedia
|
||||
#on mac qt has no multimedia
|
||||
contains(QKIT_PRIVATE, macOS) {
|
||||
lessThan(QT_MAJOR_VERSION, 5):DEFINES-=__MULTIMEDIA__
|
||||
}
|
||||
@ -251,6 +251,7 @@ contains (DEFINES, __WEBSOCKETSUPPORT__) {
|
||||
}
|
||||
|
||||
##################Charts Module###############################
|
||||
#Qt Charts has a problem, you can't mod tip label's style.
|
||||
#if you use QQtCharts, open this annotation
|
||||
DEFINES += __QQTCHARTS__
|
||||
lessThan(QT_MAJOR_VERSION, 5):DEFINES-=__QQTCHARTS__
|
||||
|
@ -18,9 +18,23 @@ QQtWidget::~QQtWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void QQtWidget::setPixmap ( QString pic )
|
||||
void QQtWidget::setPixmap ( const QString& pic )
|
||||
{
|
||||
m_pic = pic;
|
||||
bool ret = mImg.load ( pic );
|
||||
/*请确认文件是否拷贝成功。*/
|
||||
//pline() << ret << mImg.isNull();
|
||||
update();
|
||||
}
|
||||
|
||||
void QQtWidget::setPixmap ( const QPixmap& pixmap )
|
||||
{
|
||||
mImg = pixmap.toImage();
|
||||
update();
|
||||
}
|
||||
|
||||
void QQtWidget::setPixmap ( const QImage& image )
|
||||
{
|
||||
mImg = image;
|
||||
update();
|
||||
}
|
||||
|
||||
@ -28,28 +42,41 @@ void QQtWidget::paintEvent ( QPaintEvent* event )
|
||||
{
|
||||
QStylePainter p ( this );
|
||||
|
||||
if ( m_pic.isEmpty() )
|
||||
if ( mImg.isNull() )
|
||||
return;
|
||||
|
||||
QImage image ( m_pic );
|
||||
|
||||
switch ( m_style )
|
||||
{
|
||||
case QQTCENTER:
|
||||
p.drawItemPixmap ( rect(), Qt::AlignCenter, QIcon ( m_pic ).pixmap ( rect().size(), QIcon::Normal, QIcon::On ) );
|
||||
break;
|
||||
{
|
||||
/*
|
||||
* 要达到居中的目标,QImage需要做的size判断很繁复,这里使用QIcon做一些中间转换的后续转换,可以很容易的达到绘制合理大小的pixmap的目的。
|
||||
* source: pixmap file image
|
||||
* QImage 输入、输出两侧是pixmap
|
||||
* 借助(+QIcon) QIcon 输入、输出两侧也是pixmap
|
||||
* dest: 所需要的、合理大小的pixmap
|
||||
*/
|
||||
QIcon icon;
|
||||
icon.addPixmap ( QPixmap::fromImage ( mImg ), QIcon::Normal, QIcon::On );
|
||||
p.drawItemPixmap ( rect(), Qt::AlignCenter, icon.pixmap ( rect().size(), QIcon::Normal, QIcon::On ) );
|
||||
//QSize mSize = mImg.rect() > rect() ? rect().size() : mImg.size();
|
||||
//p.drawItemPixmap ( rect(), Qt::AlignCenter, QPixmap::fromImage ( mImg.scaled ( mSize, Qt::KeepAspectRatio ) ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case QQTTILEDWIDTH:
|
||||
p.drawItemPixmap ( rect(), Qt::AlignLeft | Qt::AlignTop,
|
||||
QPixmap::fromImage ( image.copy ( rect() )
|
||||
/*.copy() 切出图片的左上部分使用*/
|
||||
QPixmap::fromImage ( mImg.copy ( rect() )
|
||||
.scaledToWidth ( rect().width() )
|
||||
) );
|
||||
break;
|
||||
|
||||
case QQTZOOMWIDTH:
|
||||
p.drawItemPixmap ( rect(), Qt::AlignLeft | Qt::AlignTop,
|
||||
QPixmap::fromImage ( image
|
||||
.scaled ( rect().width(), image.height(), Qt::IgnoreAspectRatio )
|
||||
/*不.copy() 切出图片的中间部分使用*/
|
||||
QPixmap::fromImage ( mImg
|
||||
.scaled ( rect().width(), mImg.height(), Qt::IgnoreAspectRatio )
|
||||
) );
|
||||
break;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
#ifndef QQTWIDGET_H
|
||||
#define QQTWIDGET_H
|
||||
|
||||
#include <qqt-local.h>
|
||||
#include <qqtcore.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <qqt-local.h>
|
||||
#include <QImage>
|
||||
|
||||
class QQTSHARED_EXPORT QQtWidget : public QWidget
|
||||
{
|
||||
@ -24,9 +27,12 @@ public:
|
||||
QQTZOOMWIDTH,
|
||||
QQTZOOMHEIGHT,
|
||||
};
|
||||
void setPixmap ( QString pic = QString() );
|
||||
void setType ( ImageStyle style = QQTCENTER ) { m_style = style; }
|
||||
|
||||
void setPixmap ( const QString& pic = QString() );
|
||||
void setPixmap ( const QPixmap& pixmap );
|
||||
void setPixmap ( const QImage& image );
|
||||
|
||||
signals:
|
||||
void click();
|
||||
void doubleClick();
|
||||
@ -46,9 +52,12 @@ protected slots:
|
||||
void slot_timeout();
|
||||
|
||||
private:
|
||||
QString m_pic;
|
||||
quint32 m_style;
|
||||
QTimer* m_lcTimer;
|
||||
/*pixmap是必要的。绘图用pixmap。*/
|
||||
/*内部没有使用QPixmap存储,因为如果缩放widget,pixmap就没办法了,img有*/
|
||||
/*内部对QIcon的使用删除了,icon不是必要的。*/
|
||||
QImage mImg;
|
||||
};
|
||||
|
||||
#endif // QPICWIDGET_H
|
||||
|
BIN
test/giftest/AppRoot/yun.png
Normal file
BIN
test/giftest/AppRoot/yun.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
@ -36,5 +36,12 @@ FORMS += \
|
||||
CONFIG += mobility
|
||||
MOBILITY =
|
||||
|
||||
#促使qqt_deploy_config配置执行,没有这个变量不执行。
|
||||
APP_CONFIG_PWD = $${PWD}/AppRoot
|
||||
win32 {
|
||||
APP_CONFIG_PWD ~=s,/,\\,g
|
||||
}
|
||||
|
||||
#促使编译源代码,qmake pri配置里面的QMAKE_XX_LINK命令就会执行。
|
||||
system("touch main.cpp")
|
||||
include(../../src/app_base_manager.pri)
|
||||
|
@ -7,6 +7,8 @@ GifTestDialog::GifTestDialog ( QWidget* parent ) :
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
ui->labelGif->setGifFile ( "./waiting.gif" );
|
||||
ui->widgetGif->setGifFile ( "./waiting.gif" );
|
||||
ui->widgetQQt->setPixmap ( "./yun.png" );
|
||||
pline() << QMovie::supportedFormats();
|
||||
}
|
||||
|
||||
|
@ -20,19 +20,56 @@
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
<widget class="QQtGifLabel" name="labelGif">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>60</y>
|
||||
<width>151</width>
|
||||
<height>131</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>gif label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>gif widget</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>qqt widget</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QQtGifLabel" name="labelGif">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-color: rgb(17, 54, 13);
|
||||
border-width:2px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QQtGifWidget" name="widgetGif" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-color: rgb(17, 54, 13);
|
||||
border-width:2px;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QQtWidget" name="widgetQQt" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-color: rgb(17, 54, 13);
|
||||
border-width:2px;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
@ -50,6 +87,18 @@
|
||||
<extends>QLabel</extends>
|
||||
<header>qqtgiflabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QQtGifWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qqtgifwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QQtWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qqtwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user