JustAudio/gui/icon.cpp
Maurice O'Neal 73a8c03fa1 Added a logo to the project and changed the "settings" button to "menu"
and added some options to the menu that changes the behaviour of the
app. such as turning on/off the auto playing of files and the directory
and volume control. this is all kept persistent using an IDM formated
file in the app's config directory. still having issues with it not
calculating the durations properly but i now know why. it's because
QMediaPlayer can't calculate the durations of VBR files (variable bit-
rate) properly. other than that, everything seems to be working
perfectly. i'll add more feasures such as a next/previous file button
and a stop button.
2016-10-16 17:04:21 -04:00

92 lines
1.6 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"));
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;
}
}
type = t;
}
void Icon::buttonClicked()
{
if (type == PAUSE_PLAY)
{
if (playerState == QMediaPlayer::PlayingState)
{
emit pause();
}
else
{
emit play();
}
}
else if (type == OPEN)
{
emit open();
}
}
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();
}