JustAudio/gui/icon.cpp
Maurice O'Neal 679fc61feb I've updated the icons to a new hallow outline transparent look. added
stop, next file, previous file buttons along with the added feasures the
buttons represent. i've also added png versions of all of the icons just
in case the svg versions are not practical to use. i also fully built
out a tray icon functionality so the application can now minimize to
system tray. also updated the app logo to a new flat icon type sinewave
look. then finally, i've added the restore button to the tray icon so it
will restore the window back in front from the tray.
2016-10-23 21:26:58 -04:00

165 lines
2.8 KiB
C++

#include "icon.h"
Icon::Icon(IconType t, QWidget *parent) : QToolButton(parent)
{
QRect rect = QApplication::desktop()->screenGeometry();
setMinimumHeight(rect.height() / 40);
setMinimumWidth(rect.height() / 40);
setCursor(Qt::PointingHandCursor);
setToolButtonStyle(Qt::ToolButtonIconOnly);
setPopupMode(QToolButton::InstantPopup);
switch (t)
{
case PAUSE_PLAY:
{
stateChanged(QMediaPlayer::StoppedState);
setToolTip(tr("Pause/Play"));
break;
}
case MENU:
{
loadImg(":/svg/menu");
setToolTip(tr("Menu"));
break;
}
case OPEN:
{
loadImg(":/svg/open");
setToolTip(tr("Open File"));
break;
}
case STOP:
{
loadImg(":/svg/stop");
setToolTip(tr("Stop"));
break;
}
case PREV:
{
loadImg(":/svg/prev");
setToolTip(tr("Previous File"));
break;
}
case NEXT:
{
loadImg(":/svg/next");
setToolTip(tr("Next File"));
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;
}
void Icon::buttonClicked()
{
if (type == PAUSE_PLAY)
{
if (playerState == QMediaPlayer::PlayingState)
{
emit pause();
}
else
{
emit play();
}
}
else if (type == OPEN)
{
emit open();
}
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();
}
}
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(":/svg/pause");
}
else
{
loadImg(":/svg/play");
}
}
void Icon::loadImg(const QString &path)
{
svgFile = path;
update();
}
void Icon::setSlider(QSlider *slider)
{
volSlider = slider;
}