10e5af0588
working, also added svg icons to the user interface. the settings button currently does nothing (still work in progress). during testing, i discovered QMediaPlayer would have trouble playing some music files that have an ID3 tag so AudFile was created as a way to read the size of the ID3 tag and step over it when QMediaPlayer reads from the file. although it fixed the playback issue, QMediaPlayer is now having trouble calculating the duration properly without the tag. i already have a solution to the porblem in mind, more to come in the next commit.
84 lines
1.5 KiB
C++
84 lines
1.5 KiB
C++
#include "icon.h"
|
|
|
|
Icon::Icon(IconType t, QWidget *parent) : QLabel(parent)
|
|
{
|
|
QRect rect = QApplication::desktop()->screenGeometry();
|
|
|
|
setMinimumHeight(rect.height() / 40);
|
|
setMinimumWidth(rect.height() / 40);
|
|
setCursor(Qt::PointingHandCursor);
|
|
|
|
switch (t)
|
|
{
|
|
case PAUSE_PLAY: stateChanged(QMediaPlayer::StoppedState); break;
|
|
case SETTINGS: loadImg(":/settings"); break;
|
|
case OPEN: loadImg(":/open"); break;
|
|
}
|
|
|
|
type = t;
|
|
}
|
|
|
|
void Icon::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton)
|
|
{
|
|
switch (type)
|
|
{
|
|
case PAUSE_PLAY:
|
|
{
|
|
if (playerState == QMediaPlayer::PlayingState)
|
|
{
|
|
emit pause();
|
|
}
|
|
else
|
|
{
|
|
emit play();
|
|
}
|
|
|
|
break;
|
|
}
|
|
case SETTINGS:
|
|
{
|
|
emit settings();
|
|
|
|
break;
|
|
}
|
|
case OPEN:
|
|
{
|
|
emit open();
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Icon::paintEvent(QPaintEvent *)
|
|
{
|
|
QPainter painter(this);
|
|
QSvgRenderer svg(svgFile, this);
|
|
|
|
svg.render(&painter);
|
|
}
|
|
|
|
void Icon::stateChanged(QMediaPlayer::State state)
|
|
{
|
|
playerState = state;
|
|
|
|
if (state == QMediaPlayer::PlayingState)
|
|
{
|
|
loadImg(":/pause");
|
|
}
|
|
else
|
|
{
|
|
loadImg(":/play");
|
|
}
|
|
}
|
|
|
|
void Icon::loadImg(const QString &path)
|
|
{
|
|
svgFile = path;
|
|
|
|
update();
|
|
}
|