#include "ProgressBar.h" #include "ui_ProgressBar.h" #include #define DURATION 10000 ProgressBar::ProgressBar(QWidget* parent) : QWidget(parent) , ui(new Ui::ProgressBar) { ui->setupUi(this); // move to bottom of screen this->setFixedWidth(parent->width()); int height = parent->height(); this->move(0, height - this->height()); timer = new QTimer(); timer->setInterval(DURATION); timer->stop(); connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout())); QString styles = "QSlider::groove:horizontal { \ border: none; \ height: 6px; \ border-radius: 3px; \ background: #FF5C38; \ } \ QSlider::sub-page:horizontal { \ background: #FF5C38; \ height: 4px; \ border-radius: 3px; \ } \ QSlider::add-page:horizontal { \ background: #949494; \ height: 4px; \ border-radius: 3px; \ }"; QString max = "QSlider::handle:horizontal {\ border: none;\ margin: -5px 0px;\ width: 16px;\ height: 16px;\ border-radius: 8px;\ background: #FF5C38;\ }"; QString min = "QSlider::handle:horizontal {\ border: none;\ margin: -5px -8px;\ width: 16px;\ height: 16px;\ border-radius: 8px;\ background: rgba(0, 0, 0, 0);\ }"; sliderMaxStyles = styles + max; sliderMinStyles = styles + min; this->setStyleSheet(sliderMaxStyles); } ProgressBar::~ProgressBar() { delete ui; delete timer; } void ProgressBar::setDuration(int dur) { this->duration = dur; ui->horizontalSlider->setMaximum(dur); QString time = this->secToString(dur); this->durationStr = time; ui->label->setText(QString("00:00:00/%1").arg(time)); } void ProgressBar::setCurrent(int cur) { ui->horizontalSlider->setValue(cur); QString time = this->secToString(cur); ui->label->setText(QString("%1/%2").arg(time).arg(durationStr)); } void ProgressBar::showMax() { if (timer->isActive()) { timer->stop(); timer->start(); } else { timer->start(); } if (!isMax) { this->setFixedHeight(100); ui->horizontalSlider->setStyleSheet(sliderMaxStyles); this->move(0, parentWidget()->height() - this->height()); ui->widget->setStyleSheet("QWidget#widget{background-color: rgba(0, 0, 0, 0.7);}"); isMax = true; ui->actionContainer->show(); } } void ProgressBar::onTimeout() { ui->actionContainer->hide(); ui->horizontalSlider->setStyleSheet(sliderMinStyles); this->setFixedHeight(ui->horizontalSlider->height() + ui->widget->layout()->contentsMargins().top()); this->move(0, parentWidget()->height() - this->height()); ui->widget->setStyleSheet("QWidget#widget{background-color: rgba(0, 0, 0, 0);}"); timer->stop(); isMax = false; } void ProgressBar::setState(PlayState state) { if (state == Play) { ui->lblStatus->setPixmap(QPixmap(":/images/pause.png")); } else { ui->lblStatus->setPixmap(QPixmap(":/images/start.png")); } }