| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "BmpAnimationWidget.h"
- #include "UserInterfaceUtility.h"
- #include <QPainter>
- #include <QFile>
- #include <QScopedPointer>
- #include <QEvent>
- class BmpAnimationWidgetPrivate
- {
- Q_DISABLE_COPY(BmpAnimationWidgetPrivate)
- public:
- explicit BmpAnimationWidgetPrivate(BmpAnimationWidget* parent);
- ~BmpAnimationWidgetPrivate();
- QImage m_BackGroundImage;
- QString m_BackgroundPath;
- bool m_Reload;
- bool m_bFull;
- bool m_bIgnore;
- private:
- BmpAnimationWidget* m_Parent;
- };
- BmpAnimationWidget::BmpAnimationWidget(QWidget *parent)
- : QWidget(parent)
- , m_Private(new BmpAnimationWidgetPrivate(this))
- {
- }
- BmpAnimationWidget::~BmpAnimationWidget()
- {
- }
- void BmpAnimationWidget::setBackgroundBmpPath(const QString &path)
- {
- QImageReader ir(path);
- m_Private->m_BackGroundImage = ir.read();
- if(!m_Private->m_BackGroundImage.isNull()){
- m_Private->m_BackGroundImage.scaled(width(),height(),Qt::KeepAspectRatioByExpanding);
- m_Private->m_BackgroundPath = path;
- m_Private->m_Reload = false;
- if (isVisible()) {
- update();
- }
- }
- }
- void BmpAnimationWidget::setFullMode()
- {
- m_Private->m_bFull = true;
- }
- void BmpAnimationWidget::setEventIgnore()
- {
- m_Private->m_bIgnore = true;
- }
- void BmpAnimationWidget::styleChange()
- {
- m_Private->m_Reload = true;
- }
- void BmpAnimationWidget::paintEvent(QPaintEvent *)
- {
- QPainter painter(this);
- painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
- if (m_Private->m_Reload) {
- setBackgroundBmpPath(m_Private->m_BackgroundPath);
- }
- if (!m_Private->m_BackGroundImage.isNull()) {
- int x = (width() - m_Private->m_BackGroundImage.width()) >> 1;
- int y = (height() - m_Private->m_BackGroundImage.height()) >> 1;
- QRect rect(0, 0, width(), height());
- if(m_Private->m_bFull) {
- painter.drawImage(rect, m_Private->m_BackGroundImage);
- } else {
- painter.drawImage(x, y, m_Private->m_BackGroundImage);
- }
- }
- }
- bool BmpAnimationWidget::event(QEvent *event)
- {
- switch (event->type()) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseMove: {
- if(m_Private->m_bIgnore) {
- event->ignore();
- }
- break;
- }
- default: {
- break;
- }
- }
- return QWidget::event(event);
- }
- BmpAnimationWidgetPrivate::BmpAnimationWidgetPrivate(BmpAnimationWidget *parent) : m_Parent(parent)
- , m_bFull(false)
- , m_bIgnore(false)
- {
- m_BackgroundPath.clear();
- m_BackGroundImage.fill(0);
- m_Reload = false;
- }
- BmpAnimationWidgetPrivate::~BmpAnimationWidgetPrivate()
- {
- }
|