Parent: [790848] (diff)

Child: [988e57] (diff)

Download this file

progresswidget.cpp    116 lines (102 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright (C) 2015 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "progresswidget.h"
#include "HelperStructs/Helper.h"
#include <QDebug>
ProgressWidget::ProgressWidget(QWidget *parent)
: ProgressWidgetIF(parent), m_totalsecs(0), m_step_pc(2), m_step_secs(-1)
{
setupUi(this);
songProgress->setMinimum(0);
songProgress->setMaximum(100);
connect(songProgress, SIGNAL(valueChanged(int)),
this, SLOT(onProgressSliderChanged(int)));
}
void ProgressWidget::setTotalTime(int secs)
{
QString length_str = Helper::cvtMsecs2TitleLengthString(secs * 1000, true);
endTime->setText(length_str);
m_totalsecs = secs;
}
void ProgressWidget::seek(int secs)
{
if (secs < 0) {
secs = 0;
} else if (secs > m_totalsecs) {
secs = m_totalsecs;
}
setUi(secs);
emit seekRequested(secs);
}
void ProgressWidget::step(int steps)
{
int secs = m_step_pc > 0 ? (m_step_pc * steps * m_totalsecs) / 100 :
m_step_secs * steps;
setUi(secs);
emit seekRequested(secs);
}
void ProgressWidget::setStepValuePc(int percent)
{
if (percent > 0 && percent <= 100) {
m_step_secs = -1;
m_step_pc = percent;
}
}
void ProgressWidget::setStepValueSecs(int secs)
{
m_step_secs = secs;
if (secs < 0) {
m_step_pc = 2;
} else {
m_step_pc = -1;
}
}
void ProgressWidget::showTimes(int secs)
{
QString curPosString = Helper::cvtMsecs2TitleLengthString(secs*1000);
curTime->setText(curPosString);
if (secs > 0) {
curPosString =
Helper::cvtMsecs2TitleLengthString((secs - m_totalsecs)*1000);
endTime->setText(curPosString);
} else {
curPosString = Helper::cvtMsecs2TitleLengthString(m_totalsecs*1000);
endTime->setText(curPosString);
}
}
void ProgressWidget::setUi(int secs)
{
int pc = m_totalsecs ? (secs * 100) / m_totalsecs : 0;
songProgress->setValueNoSigs(pc);
showTimes(secs);
}
int ProgressWidget::currentValuePc()
{
return songProgress->value();
}
void ProgressWidget::onProgressSliderChanged(int pc)
{
if (pc > 100) {
pc = 100;
} else if (pc < 0) {
pc = 0;
}
int secs = (pc * m_totalsecs) / 100;
showTimes(secs);
qDebug() << "ProgressWidget: emitting seekRequested(" << secs << ")";
emit seekRequested(secs);
}