Qt模仿酷狗音乐的播放图标

手机酷狗音乐在播放的时候,中间有一个旋转图标,显示播放进度,如下所示。在这里插入图片描述
Qt模仿酷狗音乐的播放图标效果图:
在这里插入图片描述
头文件

#ifndef QWHKUGOUMUSICLABEL_H
#define QWHKUGOUMUSICLABEL_H

/*
 * 模仿酷狗音乐的音乐播放图标
 * 支持缩放
 */

#include <QWidget>
#include <QPainter>
#include <QPropertyAnimation>
#include <QTimer>
#include <QPixmap>

class QWHKuGouMusicLabel : public QWidget
{
    Q_OBJECT
    Q_ENUMS(State)
    Q_PROPERTY(int m_rotate READ getRotate WRITE setRotate)
public:
    enum State
    {
        Stopped,    //停止
        Paused,     //暂停
        Running,    //运行
    };

    explicit QWHKuGouMusicLabel(QWidget *parent = nullptr);
    ~QWHKuGouMusicLabel();

public:
    //设置音乐时长
    void setMusicDuration(int secs);
    //设置背景图片旋转周期
    void setBgPixmapDuration(int secs);
    //设置每多少毫秒进度条更新一次进度
    void setBarInterval(int msecs);
    //设置当前音乐毫秒数
    void setCurMusicSecs(int msecs);
    //设置背景边缘宽度百分比(0-100)
    void setBorderWidth(int borderWidth);
    //设置背景图片当前旋转角度
    void setRotate(int rotate);
    //设置背景图片
    void setBgPixmap(const QPixmap &pixmap);
    //设置背景边缘颜色
    void setBorderColor(QColor borderColor);
    //设置背景图片底色
    void setBgColor(QColor bgColor);
    //设置进度条颜色
    void setBarColor(QColor barColor);
    //设置进度条圆圈颜色
    void setCircleColor(QColor circleColor);

    //获取音乐时长
    int getMusicDuration()      const;
    //获取背景图片旋转周期
    int getBgPixmapDuration()   const;
    //获取进度条更新频率(每多少毫秒更新一次进度)
    int getBarInterval()        const;
    //获取当前音乐毫秒数
    int getCurMusicSecs()       const;
    //获取背景边缘宽度百分比(0-100)
    int getBorderWidth()        const;
    //获取背景图片角度
    int getRotate()             const;
    //获取背景图片
    QPixmap getBgPixmap()       const;
    //获取背景边缘颜色
    QColor getBorderColor()     const;
    //获取背景图片底色
    QColor gtBgColor()          const;
    //获取进度条颜色
    QColor getBarColor()        const;
    //获取进度条圆圈颜色
    QColor getCircleColor()     const;

    //开始音乐动画
    void start();
    //暂停音乐动画
    void pause();
    //继续音乐动画
    void resume();
    //停止音乐动画
    void stop();

protected:
    void paintEvent(QPaintEvent *event);
    //绘制背景
    void drawBackground(QPainter *painter);
    //绘制进度条
    void drawProgressBar(QPainter *painter);
    //绘制进度条圆圈
    void drawProgressBarCircle(QPainter *painter);

private:
    //角度转弧度
    double degreeToRadius(double degree);

signals:
    //状态改变时发送信号
    void stateChanged(State state);

private slots:
    void onTimeOut();

private:
    int m_musicDuration;                //音乐时长
    int m_pixmapDuration;               //背景图片旋转周期
    int m_barInterval;                  //每几秒进度条更新一次进度

    int m_curMusicSecs;                 //当前音乐毫秒数
    int m_borderWidth;                  //背景边缘宽度,百分比
    int m_rotate;                       //背景图片当前旋转角度
    QPixmap m_pixmap;                   //背景图片

    QColor m_borderColor;               //背景边缘颜色
    QColor m_bgColor;                   //背景图片底色
    QColor m_barColor;                  //进度条颜色
    QColor m_circleColor;               //进度条圆圈颜色

    QPropertyAnimation *m_animation;    //属性动画,旋转背景图片
    QTimer *m_timer;                    //定时器,更新进度条
};

#endif // QWHKUGOUMUSICLABEL_H
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮生卍流年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值