mirror of https://github.com/procxx/kepka.git
				
				
				
			Display download progress in the media player playback widget.
This commit is contained in:
		
							parent
							
								
									956d048d56
								
							
						
					
					
						commit
						d543073632
					
				| 
						 | 
				
			
			@ -151,6 +151,7 @@ mediaPlayerPlayback: FilledSlider {
 | 
			
		|||
	lineWidth: 2px;
 | 
			
		||||
	activeFg: mediaPlayerActiveFg;
 | 
			
		||||
	inactiveFg: mediaPlayerInactiveFg;
 | 
			
		||||
	disabledFg: #9dd1ef;
 | 
			
		||||
	duration: 150;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -217,6 +218,8 @@ mediaPlayerPanelPlayback: MediaSlider {
 | 
			
		|||
	width: 3px;
 | 
			
		||||
	activeFg: mediaPlayerActiveFg;
 | 
			
		||||
	inactiveFg: mediaPlayerInactiveFg;
 | 
			
		||||
	disabledActiveFg: mediaPlayerInactiveFg;
 | 
			
		||||
	disabledInactiveFg: windowBg;
 | 
			
		||||
	activeOpacity: 1.;
 | 
			
		||||
	inactiveOpacity: 1.;
 | 
			
		||||
	seekSize: size(9px, 9px);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -214,7 +214,11 @@ void CoverWidget::handleSongUpdate(const UpdatedEvent &e) {
 | 
			
		|||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_playback->updateState(*e.playbackState);
 | 
			
		||||
	if (audioId.audio()->loading()) {
 | 
			
		||||
		_playback->updateLoadingState(audioId.audio()->progress());
 | 
			
		||||
	} else {
 | 
			
		||||
		_playback->updateState(*e.playbackState);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto stopped = ((playbackState.state & AudioPlayerStoppedMask) || playbackState.state == AudioPlayerFinishing);
 | 
			
		||||
	auto showPause = !stopped && (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
 | 
			
		||||
| 
						 | 
				
			
			@ -248,9 +252,7 @@ void CoverWidget::updateTimeText(const AudioMsgId &audioId, const AudioPlaybackS
 | 
			
		|||
	_lastDurationMs = (playbackState.duration * 1000LL) / frequency;
 | 
			
		||||
 | 
			
		||||
	if (audioId.audio()->loading()) {
 | 
			
		||||
		auto loaded = audioId.audio()->loadOffset();
 | 
			
		||||
		auto loadProgress = snap(float64(loaded) / qMax(audioId.audio()->size, 1), 0., 1.);
 | 
			
		||||
		_time = QString::number(qRound(loadProgress * 100)) + '%';
 | 
			
		||||
		_time = QString::number(qRound(audioId.audio()->progress() * 100)) + '%';
 | 
			
		||||
		_playback->setDisabled(true);
 | 
			
		||||
	} else {
 | 
			
		||||
		display = display / frequency;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -267,7 +267,11 @@ void Widget::handleSongUpdate(const UpdatedEvent &e) {
 | 
			
		|||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_playback->updateState(*e.playbackState);
 | 
			
		||||
	if (audioId.audio()->loading()) {
 | 
			
		||||
		_playback->updateLoadingState(audioId.audio()->progress());
 | 
			
		||||
	} else {
 | 
			
		||||
		_playback->updateState(*e.playbackState);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto stopped = ((playbackState.state & AudioPlayerStoppedMask) || playbackState.state == AudioPlayerFinishing);
 | 
			
		||||
	auto showPause = !stopped && (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting);
 | 
			
		||||
| 
						 | 
				
			
			@ -301,9 +305,7 @@ void Widget::updateTimeText(const AudioMsgId &audioId, const AudioPlaybackState
 | 
			
		|||
	_lastDurationMs = (playbackState.duration * 1000LL) / frequency;
 | 
			
		||||
 | 
			
		||||
	if (audioId.audio()->loading()) {
 | 
			
		||||
		auto loaded = audioId.audio()->loadOffset();
 | 
			
		||||
		auto loadProgress = snap(float64(loaded) / qMax(audioId.audio()->size, 1), 0., 1.);
 | 
			
		||||
		_time = QString::number(qRound(loadProgress * 100)) + '%';
 | 
			
		||||
		_time = QString::number(qRound(audioId.audio()->progress() * 100)) + '%';
 | 
			
		||||
		_playback->setDisabled(true);
 | 
			
		||||
	} else {
 | 
			
		||||
		display = display / frequency;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,6 +33,7 @@ Playback::Playback(Ui::ContinuousSlider *slider) : _slider(slider) {
 | 
			
		|||
void Playback::updateState(const AudioPlaybackState &playbackState) {
 | 
			
		||||
	qint64 position = 0, duration = playbackState.duration;
 | 
			
		||||
 | 
			
		||||
	setDisabled(false);
 | 
			
		||||
	_playing = !(playbackState.state & AudioPlayerStoppedMask);
 | 
			
		||||
	if (_playing || playbackState.state == AudioPlayerStopped) {
 | 
			
		||||
		position = playbackState.position;
 | 
			
		||||
| 
						 | 
				
			
			@ -57,5 +58,11 @@ void Playback::updateState(const AudioPlaybackState &playbackState) {
 | 
			
		|||
	_slider->update();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Playback::updateLoadingState(float64 progress) {
 | 
			
		||||
	setDisabled(true);
 | 
			
		||||
	auto animated = progress > _slider->value();
 | 
			
		||||
	_slider->setValue(progress, animated);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Clip
 | 
			
		||||
} // namespace Media
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,7 @@ public:
 | 
			
		|||
	Playback(Ui::ContinuousSlider *slider);
 | 
			
		||||
 | 
			
		||||
	void updateState(const AudioPlaybackState &playbackState);
 | 
			
		||||
	void updateLoadingState(float64 progress);
 | 
			
		||||
 | 
			
		||||
	void setFadeOpacity(float64 opacity) {
 | 
			
		||||
		_slider->setFadeOpacity(opacity);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,8 @@ mediaviewPlayback: MediaSlider {
 | 
			
		|||
	width: 3px;
 | 
			
		||||
	activeFg: mediaviewPlaybackActive;
 | 
			
		||||
	inactiveFg: mediaviewPlaybackInactive;
 | 
			
		||||
	disabledActiveFg: mediaviewPlaybackActive;
 | 
			
		||||
	disabledInactiveFg: mediaviewPlaybackInactive;
 | 
			
		||||
	activeOpacity: mediaviewActiveOpacity;
 | 
			
		||||
	inactiveOpacity: mediaviewInactiveOpacity;
 | 
			
		||||
	seekSize: size(11px, 11px);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -105,9 +105,9 @@ void FileLoader::readImage(const QSize &shrinkBox) const {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
float64 FileLoader::currentProgress() const {
 | 
			
		||||
	if (_complete) return 1;
 | 
			
		||||
	if (!fullSize()) return 0;
 | 
			
		||||
	return float64(currentOffset()) / fullSize();
 | 
			
		||||
	if (_complete) return 1.;
 | 
			
		||||
	if (!fullSize()) return 0.;
 | 
			
		||||
	return snap(float64(currentOffset()) / fullSize(), 0., 1.);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32 FileLoader::fullSize() const {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1368,12 +1368,9 @@ bool DocumentData::displayLoading() const {
 | 
			
		|||
 | 
			
		||||
float64 DocumentData::progress() const {
 | 
			
		||||
	if (uploading()) {
 | 
			
		||||
		if (size > 0) {
 | 
			
		||||
			return float64(uploadOffset) / size;
 | 
			
		||||
		}
 | 
			
		||||
		return 0;
 | 
			
		||||
		return snap((size > 0) ? float64(uploadOffset) / size : 0., 0., 1.);
 | 
			
		||||
	}
 | 
			
		||||
	return loading() ? _loader->currentProgress() : (loaded() ? 1 : 0);
 | 
			
		||||
	return loading() ? _loader->currentProgress() : (loaded() ? 1. : 0.);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32 DocumentData::loadOffset() const {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,7 +132,7 @@ void ContinuousSlider::wheelEvent(QWheelEvent *e) {
 | 
			
		|||
#else // OS_MAC_OLD
 | 
			
		||||
	constexpr auto step = static_cast<int>(QWheelEvent::DefaultDeltasPerStep);
 | 
			
		||||
#endif // OS_MAC_OLD
 | 
			
		||||
	constexpr auto coef = 1. / (step * 5.);
 | 
			
		||||
	constexpr auto coef = 1. / (step * 10.);
 | 
			
		||||
 | 
			
		||||
	auto deltaX = e->angleDelta().x(), deltaY = e->angleDelta().y();
 | 
			
		||||
	if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -69,7 +69,7 @@ protected:
 | 
			
		|||
		return _mouseDown ? _downValue : a_value.current();
 | 
			
		||||
	}
 | 
			
		||||
	float64 getCurrentOverFactor(uint64 ms) {
 | 
			
		||||
		return _a_over.current(ms, _over ? 1. : 0.);
 | 
			
		||||
		return _disabled ? 0. : _a_over.current(ms, _over ? 1. : 0.);
 | 
			
		||||
	}
 | 
			
		||||
	bool isDisabled() const {
 | 
			
		||||
		return _disabled;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,13 +51,13 @@ void FilledSlider::paintEvent(QPaintEvent *e) {
 | 
			
		|||
	auto lineWidthPartial = lineWidth - lineWidthRounded;
 | 
			
		||||
	auto seekRect = getSeekRect();
 | 
			
		||||
	auto value = getCurrentValue(ms);
 | 
			
		||||
	auto from = seekRect.x(), mid = disabled ? from : qRound(from + value * seekRect.width()), end = from + seekRect.width();
 | 
			
		||||
	auto from = seekRect.x(), mid = qRound(from + value * seekRect.width()), end = from + seekRect.width();
 | 
			
		||||
	if (mid > from) {
 | 
			
		||||
		p.setOpacity(masterOpacity);
 | 
			
		||||
		p.fillRect(from, height() - lineWidthRounded, (mid - from), lineWidthRounded, _st.activeFg);
 | 
			
		||||
		p.fillRect(from, height() - lineWidthRounded, (mid - from), lineWidthRounded, disabled ? _st.disabledFg : _st.activeFg);
 | 
			
		||||
		if (lineWidthPartial > 0.01) {
 | 
			
		||||
			p.setOpacity(masterOpacity * lineWidthPartial);
 | 
			
		||||
			p.fillRect(from, height() - lineWidthRounded - 1, (mid - from), 1, _st.activeFg);
 | 
			
		||||
			p.fillRect(from, height() - lineWidthRounded - 1, (mid - from), 1, disabled ? _st.disabledFg : _st.activeFg);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (end > mid && over > 0) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,8 +60,10 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
 | 
			
		|||
	auto markerLength = (horizontal ? seekRect.width() : seekRect.height());
 | 
			
		||||
	auto from = _alwaysDisplayMarker ? 0 : markerFrom;
 | 
			
		||||
	auto length = _alwaysDisplayMarker ? (horizontal ? width() : height()) : markerLength;
 | 
			
		||||
	auto mid = disabled ? from : qRound(from + value * length);
 | 
			
		||||
	auto mid = qRound(from + value * length);
 | 
			
		||||
	auto end = from + length;
 | 
			
		||||
	auto &activeFg = disabled ? _st.disabledActiveFg : _st.activeFg;
 | 
			
		||||
	auto &inactiveFg = disabled ? _st.disabledInactiveFg : _st.inactiveFg;
 | 
			
		||||
	if (mid > from) {
 | 
			
		||||
		auto fromClipRect = horizontal ? QRect(0, 0, mid, height()) : QRect(0, 0, width(), mid);
 | 
			
		||||
		auto fromRect = horizontal
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +71,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
 | 
			
		|||
			: QRect((width() - _st.width) / 2, from, _st.width, mid + radius - from);
 | 
			
		||||
		p.setClipRect(fromClipRect);
 | 
			
		||||
		p.setOpacity(masterOpacity * (over * _st.activeOpacity + (1. - over) * _st.inactiveOpacity));
 | 
			
		||||
		p.setBrush(horizontal ? _st.activeFg : _st.inactiveFg);
 | 
			
		||||
		p.setBrush(horizontal ? activeFg : inactiveFg);
 | 
			
		||||
		p.drawRoundedRect(fromRect, radius, radius);
 | 
			
		||||
	}
 | 
			
		||||
	if (end > mid) {
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +81,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
 | 
			
		|||
			: QRect((width() - _st.width) / 2, mid - radius, _st.width, end - (mid - radius));
 | 
			
		||||
		p.setClipRect(endClipRect);
 | 
			
		||||
		p.setOpacity(masterOpacity);
 | 
			
		||||
		p.setBrush(horizontal ? _st.inactiveFg : _st.activeFg);
 | 
			
		||||
		p.setBrush(horizontal ? inactiveFg : activeFg);
 | 
			
		||||
		p.drawRoundedRect(endRect, radius, radius);
 | 
			
		||||
	}
 | 
			
		||||
	auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over);
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +95,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
 | 
			
		|||
		if (remove * 2 < size) {
 | 
			
		||||
			p.setClipRect(rect());
 | 
			
		||||
			p.setOpacity(masterOpacity * _st.activeOpacity);
 | 
			
		||||
			p.setBrush(_st.activeFg);
 | 
			
		||||
			p.setBrush(activeFg);
 | 
			
		||||
			p.drawEllipse(seekButton.marginsRemoved(QMargins(remove, remove, remove, remove)));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,8 @@ MediaSlider {
 | 
			
		|||
	width: pixels;
 | 
			
		||||
	activeFg: color;
 | 
			
		||||
	inactiveFg: color;
 | 
			
		||||
	disabledActiveFg: color;
 | 
			
		||||
	disabledInactiveFg: color;
 | 
			
		||||
	activeOpacity: double;
 | 
			
		||||
	inactiveOpacity: double;
 | 
			
		||||
	seekSize: size;
 | 
			
		||||
| 
						 | 
				
			
			@ -48,6 +50,7 @@ FilledSlider {
 | 
			
		|||
	lineWidth: pixels;
 | 
			
		||||
	activeFg: color;
 | 
			
		||||
	inactiveFg: color;
 | 
			
		||||
	disabledFg: color;
 | 
			
		||||
	duration: int;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue