#include "BmpAnimationWidget.h" #include "UserInterfaceUtility.h" #include #include #include #include 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() { }