2016-10-10 13:29:41 -04:00
|
|
|
#include "icon.h"
|
|
|
|
|
2016-10-16 17:04:21 -04:00
|
|
|
Icon::Icon(IconType t, QWidget *parent) : QToolButton(parent)
|
2016-10-10 13:29:41 -04:00
|
|
|
{
|
|
|
|
QRect rect = QApplication::desktop()->screenGeometry();
|
|
|
|
|
|
|
|
setMinimumHeight(rect.height() / 40);
|
|
|
|
setMinimumWidth(rect.height() / 40);
|
|
|
|
setCursor(Qt::PointingHandCursor);
|
2016-10-16 17:04:21 -04:00
|
|
|
setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
setPopupMode(QToolButton::InstantPopup);
|
2016-10-10 13:29:41 -04:00
|
|
|
|
|
|
|
switch (t)
|
|
|
|
{
|
2016-10-16 17:04:21 -04:00
|
|
|
case PAUSE_PLAY:
|
|
|
|
{
|
|
|
|
stateChanged(QMediaPlayer::StoppedState);
|
|
|
|
setToolTip(tr("Pause/Play"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MENU:
|
|
|
|
{
|
2016-10-23 21:26:58 -04:00
|
|
|
loadImg(":/svg/menu");
|
2016-10-16 17:04:21 -04:00
|
|
|
setToolTip(tr("Menu"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPEN:
|
|
|
|
{
|
2016-10-23 21:26:58 -04:00
|
|
|
loadImg(":/svg/open");
|
2016-10-16 17:04:21 -04:00
|
|
|
setToolTip(tr("Open File"));
|
|
|
|
|
2016-10-23 21:26:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STOP:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/stop");
|
|
|
|
setToolTip(tr("Stop"));
|
2016-10-16 17:04:21 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-23 21:26:58 -04:00
|
|
|
case PREV:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/prev");
|
|
|
|
setToolTip(tr("Previous File"));
|
|
|
|
|
|
|
|
break;
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
2016-10-23 21:26:58 -04:00
|
|
|
case NEXT:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/next");
|
|
|
|
setToolTip(tr("Next File"));
|
2016-10-10 13:29:41 -04:00
|
|
|
|
2016-10-23 21:26:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VOL_UP:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/volume_up");
|
|
|
|
setToolTip(tr("Volume Up"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VOL_DOWN:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/volume_down");
|
|
|
|
setToolTip(tr("Volume Down"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RESTORE:
|
|
|
|
{
|
|
|
|
loadImg(":/svg/restore");
|
|
|
|
setToolTip(tr("Restore"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t != MENU)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
|
|
|
}
|
|
|
|
|
|
|
|
type = t;
|
|
|
|
volSlider = 0;
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
|
2016-10-16 17:04:21 -04:00
|
|
|
void Icon::buttonClicked()
|
2016-10-10 13:29:41 -04:00
|
|
|
{
|
2016-10-16 17:04:21 -04:00
|
|
|
if (type == PAUSE_PLAY)
|
2016-10-10 13:29:41 -04:00
|
|
|
{
|
2016-10-16 17:04:21 -04:00
|
|
|
if (playerState == QMediaPlayer::PlayingState)
|
2016-10-10 13:29:41 -04:00
|
|
|
{
|
2016-10-16 17:04:21 -04:00
|
|
|
emit pause();
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
2016-10-16 17:04:21 -04:00
|
|
|
else
|
2016-10-10 13:29:41 -04:00
|
|
|
{
|
2016-10-16 17:04:21 -04:00
|
|
|
emit play();
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-16 17:04:21 -04:00
|
|
|
else if (type == OPEN)
|
|
|
|
{
|
|
|
|
emit open();
|
|
|
|
}
|
2016-10-23 21:26:58 -04:00
|
|
|
else if (type == NEXT)
|
|
|
|
{
|
|
|
|
emit next();
|
|
|
|
}
|
|
|
|
else if (type == PREV)
|
|
|
|
{
|
|
|
|
emit prev();
|
|
|
|
}
|
|
|
|
else if (type == STOP)
|
|
|
|
{
|
|
|
|
emit stop();
|
|
|
|
}
|
|
|
|
else if ((type == VOL_DOWN) && volSlider)
|
|
|
|
{
|
|
|
|
volSlider->setValue(volSlider->value() - 1);
|
|
|
|
}
|
|
|
|
else if ((type == VOL_UP) && volSlider)
|
|
|
|
{
|
|
|
|
volSlider->setValue(volSlider->value() + 1);
|
|
|
|
}
|
|
|
|
else if (type == RESTORE)
|
|
|
|
{
|
|
|
|
emit restore();
|
|
|
|
}
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-10-23 21:26:58 -04:00
|
|
|
loadImg(":/svg/pause");
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-23 21:26:58 -04:00
|
|
|
loadImg(":/svg/play");
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::loadImg(const QString &path)
|
|
|
|
{
|
|
|
|
svgFile = path;
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
2016-10-23 21:26:58 -04:00
|
|
|
|
|
|
|
void Icon::setSlider(QSlider *slider)
|
|
|
|
{
|
|
|
|
volSlider = slider;
|
|
|
|
}
|