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