void ContentSlider::stepDn() { int content_pos = position_ * (content_size_ - view_size_) + view_size_; int dst = content_pos + getStep(); if (dst > content_size_) { if (1 != position_) { position_ = 1; emit postionChanged(position_); update(); } } else { position_ = (double)(dst - view_size_) / (double)(content_size_ - view_size_); if (position_ < 0) position_ = 0; else if (position_ > 1) position_ = 1; emit postionChanged(position_); update(); } }
void ContentSlider::stepUp() { int content_pos = position_ * (content_size_ - view_size_); int dst = content_pos - getStep(); if (dst < 0) { if (0 != dst) { position_ = 0; emit postionChanged(position_); update(); } } else { position_ = (double)dst / (double)(content_size_ - view_size_); if (position_ < 0) position_ = 0; else if (position_ > 1) position_ = 1; emit postionChanged(position_); update(); } }
void ContentSlider::mouseMoveEvent(QMouseEvent *e) { e->accept(); if (ignore_mouse_press_) return; if (!valid()) return; int pos_int = e->pos().y() + press_off_; if (pos_int - slider_size_ / 2 < 0) { if (0 != position_) { position_ = 0; emit postionChanged(position_); update(); } } else if (pos_int + slider_size_ / 2 > height()) { if (1 != position_) { position_ = 1; emit postionChanged(position_); update(); } } else { position_ = (double)(pos_int - slider_size_ / 2) / (double)(height() - slider_size_); emit postionChanged(position_); update(); } }
void MainBottomWidget::setNetWorkMode(bool isTrue) { if (isTrue) { disconnect(m_playButton, SIGNAL(clicked()), this, SLOT(on_playButton_clicked())); disconnect(m_postionWidget, SIGNAL(changeTo(qreal)), this, SLOT(postionChanged(qreal))); connect(m_playButton, SIGNAL(clicked()), this, SIGNAL(play())); connect(m_postionWidget, SIGNAL(changeTo(qreal)), this, SIGNAL(setPosTo(qreal))); } }
void MainBottomWidget::initConnect() { connect(m_playButton, SIGNAL(clicked()), this, SLOT(on_playButton_clicked())); connect(m_playFrontButton, SIGNAL(clicked()), this, SIGNAL(playFront())); connect(m_playNextButton, SIGNAL(clicked()), this, SIGNAL(playNext())); // 进度条 connect(m_voiceWidget, SIGNAL(changeTo(qreal)), this, SLOT(voiceChanged(qreal))); connect(m_postionWidget, SIGNAL(changeTo(qreal)), this, SLOT(postionChanged(qreal))); }
void ContentSlider::mousePressEvent(QMouseEvent *e) { e->accept(); if (!valid() || e->buttons() != Qt::LeftButton) { ignore_mouse_press_ = true; return; } ignore_mouse_press_ = false; int pos_int = position_ * (height() - slider_size_) + slider_size_ / 2; int mouse_pos = e->pos().y(); if (mouse_pos >= pos_int - slider_size_ / 2 && mouse_pos <= pos_int + slider_size_ / 2) /*on slider*/ press_off_ = pos_int - mouse_pos; else if (mouse_pos - slider_size_ / 2 >= 0 && mouse_pos + slider_size_ / 2 <= height()) { press_off_ = 0; position_ = (double)(mouse_pos - slider_size_ / 2) / (double)(height() - slider_size_); emit postionChanged(position_); update(); } else if (mouse_pos - slider_size_ / 2 < 0) { press_off_ = slider_size_ / 2 - mouse_pos; press_off_ = 0; update(); } else { press_off_ = (height() - slider_size_ / 2) - mouse_pos; press_off_ = 1; update(); } //qDebug() << press_off_; }
MusicWindow::MusicWindow(QWidget *parent) : MainWindow(parent) { this->setWindowIcon(QIcon(":/images/icons/app_icon")); systemTrayIcon = new MySystemTrayIcon(this); connect(systemTrayIcon, SIGNAL(showWindow()), this, SLOT(show())); connect(systemTrayIcon, SIGNAL(quit()), this, SLOT(close())); player = new MyPlayer(); connect(player, SIGNAL(playerStateChanged(int)), this, SLOT(playerStateChanged(int))); connect(player, SIGNAL(musicChanged(QString,int)), this, SLOT(musicChanged(QString,int))); topBar = new TopBar(this); connect(topBar, SIGNAL(setMinSize()), this, SLOT(showMinimized())); connect(topBar, SIGNAL(setMaxSize()), this, SLOT(setMaxSize())); connect(topBar, SIGNAL(closeWindow()), this, SLOT(hide())); connect(topBar, SIGNAL(quit()), this, SLOT(close())); connect(topBar, SIGNAL(setBackgroud(QString)), this, SLOT(setBackgroud(QString))); connect(topBar, SIGNAL(aboutQtMusic()), this, SLOT(aboutQtMusic())); fuctionPage = new QStackedWidget; fuctionPage->setMinimumWidth(200); lyricLabel = new LyricLabel(false, this); connect(player, SIGNAL(positionChanged(qint64)), lyricLabel, SLOT(postionChanged(qint64))); connect(lyricLabel, SIGNAL(changeTo(qint64)), player, SLOT(setPosition(qint64))); networkPage = new NetworkPage(); QLabel *label2 = new QLabel("Network"); label2->setAlignment(Qt::AlignCenter); QLabel *label3 = new QLabel("Download"); label3->setAlignment(Qt::AlignCenter); fuctionPage->addWidget(lyricLabel); fuctionPage->addWidget(networkPage); fuctionPage->addWidget(label3); fuctionPage->setCurrentIndex(0); connect(topBar, SIGNAL(selectFuction(int)), fuctionPage, SLOT(setCurrentIndex(int))); musicPage = new MusicPage; musicPage->setMaximumWidth(500); musicPage->setMinimumWidth(300); connect(musicPage, SIGNAL(tryToCreateList(QString)), this, SLOT(tryToCreateList(QString))); connect(musicPage, SIGNAL(deleteList(QString)), this, SLOT(deleteList(QString))); connect(musicPage, SIGNAL(addMusics()), this, SLOT(addMusics())); connect(musicPage, SIGNAL(play(QString,int)), player, SLOT(playTheMusic(QString,int))); connect(musicPage, SIGNAL(removeTheMusic(QString,int)), this, SLOT(removeTheMusic(QString,int))); connect(musicPage, SIGNAL(removeAllMusics(QString)), this, SLOT(removeAllMusics(QString))); connect(musicPage, SIGNAL(moveMusic(QString,int,int)), this, SLOT(moveMusic(QString,int,int))); bottomBar = new BottomBar(this); connect(bottomBar, SIGNAL(setVoice(int)), player, SLOT(setVoice(int))); connect(bottomBar, SIGNAL(setMode(int)), player, SLOT(setPlayMode(int))); connect(bottomBar, SIGNAL(setPostion(qint64)), player, SLOT(setPosition(qint64))); connect(bottomBar, SIGNAL(setPostion(qint64)), lyricLabel, SLOT(setPostion(qint64))); connect(player, SIGNAL(durationChanged(qint64)), bottomBar, SLOT(setMaxDuration(qint64))); connect(player, SIGNAL(positionChanged(qint64)), bottomBar, SLOT(changePostionTo(qint64))); connect(musicPage, SIGNAL(play(QString,int)), bottomBar, SLOT(setPostionAvailable())); connect(bottomBar, SIGNAL(tryplay()), this, SLOT(clickPlay())); connect(bottomBar, SIGNAL(playPre()), this, SLOT(playPre())); connect(bottomBar, SIGNAL(playNext()), this, SLOT(playNext())); connect(systemTrayIcon, SIGNAL(setMode(int)), bottomBar, SLOT(setPlayMode(int))); connect(bottomBar, SIGNAL(setMode(int)), systemTrayIcon, SLOT(setPlayMode(int))); connect(bottomBar, SIGNAL(showLyric(QString)), topBar, SLOT(changeFuction(QString))); //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SLOT(changePostionTo(qint64))); //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SIGNAL(setPostion(qint64))); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(topBar); QSplitter *splitter = new QSplitter(Qt::Horizontal, this); //设定分割窗口的分割条在拖动时是否为实时更新 true为实时更新 false则在拖动时只显示一条灰色的线条 //在拖动到位并弹起鼠标后再显示分隔条 splitter->setOpaqueResize(false); splitter->setChildrenCollapsible(false); splitter->addWidget(fuctionPage); splitter->addWidget(musicPage); splitter->setStretchFactor(0, 10); splitter->setStretchFactor(1, 1); splitter->setStyleSheet("QSplitter::handle { background-color: rgba(0,0,0,0%) }"); splitter->setHandleWidth(4); mainLayout->addWidget(splitter); mainLayout->addWidget(bottomBar); mainLayout->setMargin(1); mainLayout->setSpacing(3); this->setLayout(mainLayout); dealMouse(); readData(); }