MyPlayer::MyPlayer() { playerState = NOMUSIC; connect(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(playNext(QMediaPlayer::MediaStatus))); connect(&player, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64))); connect(&player, SIGNAL(durationChanged(qint64)), this, SLOT(musicChanged())); connect(&player, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64))); connect(this, SIGNAL(playerStateChanged(int)), this, SLOT(stateChanged(int))); }
MusicControl::MusicControl(QWidget *parent) : QWidget(parent) { setStyleSheet("QPushButton{ background-color: transparent; border: none; color:white; }" "QPushButton:pressed{ background-color: qradialgradient(spread:pad, cx:0.468355, cy:0.472, radius:0.449, fx:0.472658, fy:0.477045, stop:0.261603 rgba(255, 255, 255, 130), stop:1 rgba(255, 255, 255, 0));}" "QPushButton:checked{ background-color: qradialgradient(spread:pad, cx:0.468355, cy:0.472, radius:0.449, fx:0.472658, fy:0.477045, stop:0.261603 rgba(255, 255, 255, 130), stop:1 rgba(255, 255, 255, 0));}" "QLabel{ color:white; }"); m_c = Core::instance(); connect(m_c, SIGNAL(lengthChanged()), this, SLOT(updateTime())); connect(m_c, SIGNAL(posChanged(int)), this, SLOT(updateTime())); connect(m_c, SIGNAL(tagsChanged()), this, SLOT(showTags())); connect(m_c, SIGNAL(currentMusicChanged()), this, SLOT(musicChanged())); connect(m_c, SIGNAL(videoAppearanceChanged(bool)), this, SLOT(moveWidgets())); connect(m_c, SIGNAL(isPlayingChanged()), this, SLOT(isPlayingChanged())); m_cover = new Cover(this); m_musicTagsLabel = new QLabel(this); m_musicTagsLabel->setAlignment(Qt::AlignCenter); m_musicTagsLabel->setText(QString(tr("<b>Welcome!</b>"))); QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(); shadowEffect->setOffset(1, 1); m_musicTagsLabel->setGraphicsEffect(shadowEffect); //Player button, slider and label m_previousButton = new QPushButton(this); m_previousButton->setIcon(QIcon(QString(":/Player_Previous.png"))); m_previousButton->setIconSize(QSize(32, 32)); m_previousButton->setShortcut(QKeySequence(Qt::Key_Left)); m_previousButton->setToolTip(tr("Previous media in the playlist")); connect(m_previousButton, SIGNAL(clicked()), this, SLOT(previous())); m_playButton = new QPushButton(this); m_playButton->setIcon(QIcon(QString(":/Player_Play.png"))); m_playButton->setIconSize(QSize(50, 50)); m_playButton->setShortcut(QKeySequence(Qt::Key_Space)); m_playButton->setToolTip(tr("Play/Pause")); connect(m_playButton, SIGNAL(clicked()), this, SLOT(play())); m_nextButton = new QPushButton(this); m_nextButton->setIcon(QIcon(QString(":/Player_Next.png"))); m_nextButton->setIconSize(QSize(32, 32)); m_nextButton->setShortcut(QKeySequence(Qt::Key_Right)); m_nextButton->setToolTip(tr("Next media in the playlist")); connect(m_nextButton, SIGNAL(clicked()), this, SLOT(next())); m_volumeIcon = new QPushButton(this); m_volumeIcon->setIcon(QIcon(":/Volume.png")); m_volumeIcon->setIconSize(m_volumeIcon->size()); m_volumeIcon->setToolTip(tr("Mute or not")); connect(m_volumeIcon, SIGNAL(clicked()), this, SLOT(mute())); m_volumeIcon->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); m_volumeSlider = new QSlider(this); m_volumeSlider->setOrientation(Qt::Vertical); m_volumeSlider->setToolTip(tr("Change the volume")); m_volumeSlider->setValue(m_c->volume()); m_volumeSlider->setMaximum(200); connect(m_volumeSlider, SIGNAL(valueChanged(int)), m_c, SLOT(setVolume(int))); m_seekSlider = new QSlider(this); m_seekSlider->setOrientation(Qt::Horizontal); m_seekSlider->setToolTip(tr("Change the position in the media")); connect(m_seekSlider, SIGNAL(sliderMoved(int)), m_c, SLOT(setPosition(int))); m_timeLabel = new QLabel(this); m_timeLabel->setMinimumSize(150, 0); m_timeLabel->setAlignment(Qt::AlignRight); m_timeLabel->setText("0:00 / 0:00"); m_randButton = new QPushButton(this); m_randButton->setIconSize(QSize(22, 22)); m_randButton->setIcon(QIcon(QString(":/Random.png"))); m_randButton->setCheckable(true); m_randButton->setToolTip(tr("Random medias in the playlist or not")); m_randButton->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); m_repeatButton = new QPushButton(this); m_repeatButton->setIconSize(QSize(22, 22)); m_repeatButton->setIcon(QIcon(QString(":/Repeat.png"))); m_repeatButton->setCheckable(true); m_repeatButton->setToolTip(tr("Repeat the media or not")); m_repeatButton->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); moveWidgets(); }
void MyPlayer::musicChanged() { emit musicChanged(currentList, currentindex); }