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();
|
||
|
}
|