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"));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MENU:
|
|
|
|
{
|
|
|
|
loadImg(":/menu");
|
|
|
|
setToolTip(tr("Menu"));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPEN:
|
|
|
|
{
|
|
|
|
loadImg(":/open");
|
|
|
|
setToolTip(tr("Open File"));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(clicked()), this, SLOT(buttonClicked()));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-10 13:29:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type = t;
|
|
|
|
}
|
|
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
loadImg(":/pause");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loadImg(":/play");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::loadImg(const QString &path)
|
|
|
|
{
|
|
|
|
svgFile = path;
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|