• 大小: 5KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签: 动画Qt  

资源简介

对应博文地址:http://blog.csdn.net/CSND_Ayo/article/details/70175385

资源截图

代码片段和文件信息

#include 
#include 

#ifndef QT_NO_DEBUG
#include 
#endif

#include “customdynamicwidget.h“

CustomDynamicWidget::CustomDynamicWidget(QWidget *parent) : QWidget(parent)
    isLoop_(true) currentIndex_(0) {
}

void CustomDynamicWidget::setAnimation(const QPixmap &_pix const short _count const int _msec) {
    count_ = _count;
    currentIndex_ = 0;

    if (!pixList_.empty()) {
        pixList_.clear();
    }
    else {
        /*  顺时针动画关联  */
        clockTimer_ = new QTimer(this);
        clockTimer_->setInterval(_msec);
        connect(clockTimer_ SIGNAL(timeout()) this SLOT(updateClockwise()));

        /*  逆时针动画关联  */
        counterclockTimer_ = new QTimer(this);
        counterclockTimer_->setInterval(_msec);
        connect(counterclockTimer_ SIGNAL(timeout()) this SLOT(updateCounterclockwise()));
    }

    /*  链式动画图标分离  */
    for(short i=0; i != _count; ++i) {
        pixList_.append(_pix.copy(i * (_pix.width() / _count) 0
                        _pix.width() / _count _pix.height()));
    }

    currentPix_ = pixList_.at(0);
    this->setGeometry(00currentPix_.width()currentPix_.height());

    update();

}

void CustomDynamicWidget::startClockwise() {
    /*  防止动画错乱  */
    if(counterclockTimer_->isActive()) {
        counterclockTimer_->stop();
    }
    else {
        currentIndex_ = 0;
    }

    clockTimer_->start();
}

void CustomDynamicWidget::startCounterclockwise() {
    /*  防止动画错乱  */
    if(clockTimer_->isActive())
    {
        clockTimer_->stop();
    }
    else {
        currentIndex_ = count_ - 1;
    }

    if(currentIndex_ > 0) {
        counterclockTimer_->start();
    }

}

void CustomDynamicWidget::stop() {
    /*  停止动画  */
    if(clockTimer_->isActive()) {
        clockTimer_->stop();
    }
    if(counterclockTimer_->isActive()) {
        counterclockTimer_->stop();
    }

    /*  重置  */
    currentIndex_ = 0;
    currentPix_ = pixList_.at(0);
    update();
}

void CustomDynamicWidget::updateClockwise(void) {
    do {
        if (currentIndex_ < count_ && currentIndex_ >= 0) {
            /*  更新帧  */
            currentPix_ = pixList_.at(currentIndex_);
            update();

            /*  判断帧数  */
            if (currentIndex_ >= (count_ - 1)) {
                if(isLoop_) {
                    currentIndex_ = 0;
                    return;
                }
                break;
            }

            /*  跳帧  */
            ++currentIndex_;
            return;
        }
        else {
    #ifndef QT_NO_DEBUG
            qDebug() << __FUNCTION__ << “waring: 错误的下标“ << currentIndex_;
    #endif
        }
    } while(false);

    clockTimer_->stop();
    currentIndex_ = 0;
    emit clockwiseFinished();
}

void CustomDynamicWidget::updateCounterclockwise() {
    do {
        if(currentIndex_ >= 0 && currentIndex_ < count_) {
            /*  更新帧  */

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....      3992  2017-03-13 16:14  Animation\customdynamicwidget.cpp

    I.A....      2465  2017-03-13 16:14  Animation\customdynamicwidget.h

    I.A....      2806  2017-03-13 16:14  Animation\customprogressindicator.cpp

    I.A....      2543  2017-03-13 16:14  Animation\customprogressindicator.h

    I.A....        79  2017-05-23 09:48  Readme.md

     目录          0  2017-03-13 16:14  Animation

----------- ---------  ---------- -----  ----

                11885                    6


评论

共有 条评论

相关资源