Android QQ音乐歌词动效demo qq音乐歌词动效怎么弄 |
您所在的位置:网站首页 › qq音乐伴奏歌词怎么弄的 › Android QQ音乐歌词动效demo qq音乐歌词动效怎么弄 |
拖的太久,主要再上一篇文章中,新学习了相关知识,做了右键菜单,点击按钮动画切换窗口和播放时歌词颜色显示当前播放位置。 主要为了实现功能的展示,所以很多文件读取都直接采用了本地文件这种比较low的方式。对软件来说使用会很差,不过毕竟以实现为主,所以不再此考虑太多花里胡哨了。 点击动画效果先上图对比下与qq音乐的样式 猛的一看好像就是点击按钮出现了一个新的窗口。其实这个动画效果唯一的特点就是,这个窗口是慢慢从底部滑动到顶部,滑动的时间是可以自己设置的。 动画效果设计思路1、在主窗口内底部添加一个子窗口,窗口最小值为0,最大值为∞。样式可在上篇文章github连接查看 2、自定义动画效果类,但主要还是调用QPropertyAnimation类。 3、点击按钮之后,窗口位置根据设置的QRect发生改变。 相关代码 QMyanimation.h头文件 #ifndef QMYANIMATION_H #define QMYANIMATION_H #include #include class QMyanimation : public QObject { Q_OBJECT public: explicit QMyanimation(QObject *parent = nullptr); void setAnimationWgt(QWidget* pParentWgt, QWidget* pSubWgt); void StartAnimation(bool bShow = true); void getAniamtionGeometry(QRect& RcBegin,QRect& RcEnd,bool IsShow); signals: public slots: private: QWidget* m_ParentWgt; QWidget* m_SubWgt; }; #endif // QMYANIMATION_HQMyanimation.cpp源文件 #include "qmyanimation.h" #include #include QMyanimation::QMyanimation(QObject *parent) : QObject(parent) { } void QMyanimation::setAnimationWgt(QWidget *pParentWgt, QWidget* pSubWgt) { if(nullptr == pParentWgt || nullptr == pSubWgt) { return; } m_ParentWgt = pParentWgt; m_SubWgt = pSubWgt; } void QMyanimation::StartAnimation(bool bShow) { if(nullptr == m_ParentWgt || nullptr == m_SubWgt) { return; } QPropertyAnimation* animation = new QPropertyAnimation(m_SubWgt, "geometry"); QRect rcBegin; QRect rcEnd; getAniamtionGeometry(rcBegin, rcEnd, bShow); qDebug()height()); } else { RcBegin = QRect(0, 0, m_ParentWgt->width(),m_ParentWgt->height()); RcEnd = QRect(0,m_ParentWgt->height(),m_ParentWgt->width(),m_ParentWgt->height()); } }在主窗口初始化时传入主窗口与子窗口(滑动窗口)位置即可。 void QMusicWidget::InitAnimation() { m_nMusicAnimation = new QMyanimation(this); m_nMusicAnimation->setAnimationWgt(ui->widget, ui->MusicViewAnimation); }歌词播放颜色变换展示话不多说,先上图看效果。QQ音乐,网易云等等歌词效果就没必要上图了,都见怪不怪了。 歌词切换设计思路歌词文件为普通的lrc文件,歌词格式为[00:00]xxxxxxxxx 读取文件内容对每一句歌词进行存储。并有个相关的Label展示。 还是为了功能实现,主要是思路的设计,文件都是写死的。 展示歌词的窗口 QMusicAnimation.h #ifndef QMUSICANIMATION_H #define QMUSICANIMATION_H #include #include #include namespace Ui { class QMusicAnimation; } class QMusicAnimation : public QWidget { Q_OBJECT public: explicit QMusicAnimation(QWidget *parent = nullptr); ~QMusicAnimation(); void InitMusicAnimationStyle(); void InitMusicLyric(std::string musicstr); void ParserLyirs(QString ParStr, std::string musicname); void InitLyircLabel(QString musicstr); void ChangeLyitcLabel(int posVal); void SetCurrentLyric(qint64 position); signals: void sgnCloseMusicLryView(bool); public slots: void OnSlotCloseMusicLryView(); private: Ui::QMusicAnimation *ui; std::map m_mLyricName; std::map m_mLyircLabel; QString m_sCurrentMusicName; }; #endif // QMUSICANIMATION_H我是采用了map来存储歌词与Label,如果你有更好的想法也可以尝试。 歌词跳转展示逻辑 QMusicAnimation.cpp void QMusicAnimation::InitMusicLyric(std::string musicstr) { QFile qssFile("/Users/liuyucheng/WorkSpace/Qt/Music_QQ/Resources/Lyric/" + QString::fromStdString(musicstr) + ".Lrc");//注意qss文件的保存路径 qDebug() |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |