Skip to content

Commit

Permalink
feat(DMPRIS): music title support tick effect
Browse files Browse the repository at this point in the history
Change-Id: I69f07b52bf96e44b85846e08b86edc4a31757a59
  • Loading branch information
justforlxz committed Oct 30, 2018
1 parent def01e6 commit 48ac043
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 41 deletions.
71 changes: 45 additions & 26 deletions src/widgets/dmpriscontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,47 @@ void DMPRISControl::setPictureSize(const QSize &size)
}

DMPRISControlPrivate::DMPRISControlPrivate(DMPRISControl *q)
: DObjectPrivate(q),

m_mprisInter(nullptr)
: DObjectPrivate(q), m_mprisInter(nullptr)
{
}

void DMPRISControlPrivate::init()
{
D_Q(DMPRISControl);

m_mprisMonitor = new DMPRISMonitor(q);
m_mprisMonitor = new DMPRISMonitor(q);
m_titleScrollArea = new QScrollArea(q);
m_title = new QLabel;
m_picture = new QLabel;
m_pictureVisible = true;
m_controlWidget = new QWidget;
m_prevBtn = new DImageButton;
m_pauseBtn = new DImageButton;
m_playBtn = new DImageButton;
m_nextBtn = new DImageButton;
m_tickEffect = new DTickEffect(m_title, m_title);

m_title = new QLabel;
m_title->setAlignment(Qt::AlignCenter);
m_picture = new QLabel;
m_picture->setFixedSize(200, 200);
m_pictureVisible = true;
m_controlWidget = new QWidget;
m_prevBtn = new DImageButton;
m_prevBtn->setObjectName("PrevBtn");
m_pauseBtn = new DImageButton;
m_pauseBtn->setObjectName("PauseBtn");
m_playBtn = new DImageButton;
m_playBtn->setObjectName("PlayBtn");
m_nextBtn = new DImageButton;
m_nextBtn->setObjectName("NextBtn");

m_tickEffect->setDirection(DTickEffect::RightToLeft);
m_tickEffect->setDuration(3000);

m_titleScrollArea->setWidget(m_title);
m_titleScrollArea->setObjectName("scrollarea");
m_titleScrollArea->setWidgetResizable(true);
m_titleScrollArea->setFocusPolicy(Qt::NoFocus);
m_titleScrollArea->setFrameStyle(QFrame::NoFrame);
m_titleScrollArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
m_titleScrollArea->setContentsMargins(0, 0, 0, 0);
m_titleScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_titleScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_titleScrollArea->setStyleSheet("background-color:transparent;");

#ifdef QT_DEBUG
m_title->setText("MPRIS Title");
m_nextBtn->setNormalPic("://images/arrow_right_normal.png");
Expand All @@ -130,7 +144,7 @@ void DMPRISControlPrivate::init()


QVBoxLayout *centralLayout = new QVBoxLayout;
centralLayout->addWidget(m_title);
centralLayout->addWidget(m_titleScrollArea);
centralLayout->addWidget(m_picture);
centralLayout->setAlignment(m_picture, Qt::AlignCenter);
// centralLayout->addLayout(controlLayout);
Expand Down Expand Up @@ -183,24 +197,29 @@ void DMPRISControlPrivate::_q_onNextClicked()

void DMPRISControlPrivate::_q_onMetaDataChanged()
{
if (!m_mprisInter)
return;
if (!m_mprisInter) return;

const auto &meta = m_mprisInter->metadata();
const QString &title = meta.value("xesam:title").toString();
const QString &artist = meta.value("xesam:artist").toString();
const QUrl &pictureUrl = meta.value("mpris:artUrl").toString();
const QSize &pictureSize = m_picture->size();
const QPixmap &picture = QPixmap(pictureUrl.toLocalFile()).scaled(pictureSize, Qt::IgnoreAspectRatio);
const auto & meta = m_mprisInter->metadata();
const QString &title = meta.value("xesam:title").toString();
const QString &artist = meta.value("xesam:artist").toString();
const QUrl & pictureUrl = meta.value("mpris:artUrl").toString();
const QSize & pictureSize = m_picture->size();
const QPixmap &picture = QPixmap(pictureUrl.toLocalFile())
.scaled(pictureSize, Qt::IgnoreAspectRatio);

if (title.isEmpty())
if (title.isEmpty()) {
m_title->clear();
else
{
if (artist.isEmpty())
m_tickEffect->stop();
}
else {
if (artist.isEmpty()) {
m_title->setText(title);
else
}
else {
m_title->setText(QString("%1 - %2").arg(title).arg(artist));
}
m_title->adjustSize();
m_tickEffect->play();
}

m_picture->setPixmap(picture);
Expand Down
12 changes: 7 additions & 5 deletions src/widgets/dtickeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ void DTickEffect::draw(QPainter *painter)
else
pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, QGraphicsEffect::NoPad);

QPoint p = d->runAnimation->currentValue().toPoint();
const QPoint p { d->runAnimation->currentValue().toPoint() };
const QSize size { pixmap.size() / d->content->devicePixelRatioF() };


switch (d->direction) {
case LeftToRight:
offset = QPoint(-pixmap.width() + p.x(), p.y());
offset = QPoint(-size.width() + p.x(), p.y());
break;
case RightToLeft:
offset = QPoint(pixmap.width() + p.x(), p.y());
offset = QPoint(size.width() + p.x(), p.y());
break;
case TopToBottom:
offset = QPoint(p.x(), -pixmap.height() + p.y());
offset = QPoint(p.x(), -size.height() + p.y());
break;
case BottomToTop:
offset = QPoint(p.x(), pixmap.height() + p.y());
offset = QPoint(p.x(), size.height() + p.y());
break;
default:
break;
Expand Down
24 changes: 14 additions & 10 deletions src/widgets/private/dmpriscontrol_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@

#include <DObjectPrivate>

#include "dmpriscontrol.h"
#include "dimagebutton.h"
#include "private/mpris/dmprismonitor.h"
#include "dmpriscontrol.h"
#include "dtickeffect.h"
#include "private/mpris/dbusmpris.h"
#include "private/mpris/dmprismonitor.h"

#include <QScrollArea>

DWIDGET_BEGIN_NAMESPACE

class DMPRISControlPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
{
class DMPRISControlPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate {
D_DECLARE_PUBLIC(DMPRISControl)

public:
Expand All @@ -52,23 +54,25 @@ public Q_SLOTS:

public:
DMPRISMonitor *m_mprisMonitor;
DBusMPRIS *m_mprisInter;
DBusMPRIS * m_mprisInter;

QLabel *m_title;
QLabel *m_picture;
QScrollArea *m_titleScrollArea;
QLabel * m_title;
QLabel * m_picture;
DTickEffect *m_tickEffect;

QWidget *m_controlWidget;
QWidget * m_controlWidget;
DImageButton *m_prevBtn;
DImageButton *m_playBtn;
DImageButton *m_pauseBtn;
DImageButton *m_nextBtn;

bool m_pictureVisible;

QString m_lastPath;
QString m_lastPath;
QStringList m_mprisPaths;
};

DWIDGET_END_NAMESPACE

#endif // DMPRISCONTROL_P_H
#endif // DMPRISCONTROL_P_H

0 comments on commit 48ac043

Please sign in to comment.