void PlayerWidget::mousePressEvent(QMouseEvent *e) {
	QPoint pos(myrtlpoint(e->pos()));

	if (e->button() == Qt::LeftButton) {
		_down = OverNone;
		if (_song && _over == OverPlay) {
			playPausePressed();
			return;
		} else if (_over == OverPrev) {
			prevPressed();
		} else if (_over == OverNext) {
			nextPressed();
		} else if (_over == OverClose) {
			_down = OverClose;
		} else if (_over == OverVolume) {
			_down = OverVolume;
			_downCoord = pos.x() - _volumeRect.x();
			cSetSongVolume(snap((_downCoord - ((_volumeRect.width() - st::playerVolume.pxWidth()) / 2)) / float64(st::playerVolume.pxWidth()), 0., 1.));
			emit audioPlayer()->songVolumeChanged();
			rtlupdate(_volumeRect);
		} else if (_over == OverPlayback) {
			SongMsgId playing;
			AudioPlayerState playingState = AudioPlayerStopped;
			int64 playingPosition = 0, playingDuration = 0;
			int32 playingFrequency = 0;
			audioPlayer()->currentState(&playing, &playingState, &playingPosition, &playingDuration, &playingFrequency);
			if (playing == _song && playingDuration) {
				if (playingState == AudioPlayerPlaying || playingState == AudioPlayerStarting || playingState == AudioPlayerResuming) {
					audioPlayer()->pauseresume(OverviewDocuments);
				}
				_down = OverPlayback;
				_downProgress = snap((pos.x() - _playbackRect.x()) / float64(_playbackRect.width()), 0., 1.);
				_downDuration = playingDuration;
				_downFrequency = (playingFrequency ? playingFrequency : AudioVoiceMsgFrequency);

				rtlupdate(_playbackRect);
				updateDownTime();
			}
		} else if (_over == OverFull && _song) {
			if (HistoryItem *item = App::histItemById(_song.msgId)) {
				App::main()->showMediaOverview(item->history()->peer, OverviewAudioDocuments);
			}
		} else if (_over == OverRepeat) {
			_repeat = !_repeat;
			updateOverRect(OverRepeat);
		}
	}
}
void PlayerWidget::updateDownTime() {
	QString time = formatDurationText(qRound(_downDuration * _downProgress) / _downFrequency);
	if (time != _time) {
		_time = time;
		_timeWidth = st::linkFont->width(_time);
		rtlupdate(_infoRect);
	}
}
void PlayerWidget::updateOverRect(OverState state) {
	switch (state) {
	case OverPrev: rtlupdate(_prevRect); break;
	case OverPlay: rtlupdate(_playRect); break;
	case OverNext: rtlupdate(_nextRect); break;
	case OverClose: rtlupdate(_closeRect); break;
	case OverVolume: rtlupdate(_volumeRect); break;
	case OverFull: rtlupdate(_fullRect); break;
	case OverRepeat: rtlupdate(_repeatRect); break;
	case OverPlayback: rtlupdate(_playbackRect); break;
	}
}
void PlayerWidget::step_progress(float64 ms, bool timer) {
	float64 dt = ms / (2 * AudioVoiceMsgUpdateView);
	if (_duration && dt >= 1) {
		_a_progress.stop();
		a_progress.finish();
		a_loadProgress.finish();
	} else {
		a_progress.update(qMin(dt, 1.), anim::linear);
		a_loadProgress.update(1. - (st::radialDuration / (st::radialDuration + ms)), anim::linear);
	}
	if (timer) rtlupdate(_playbackRect);
}
void PlayerWidget::updateSelected() {
	QPoint pos(myrtlpoint(mapFromGlobal(_lastMousePos)));

	if (_down == OverVolume) {
		int32 delta = (pos.x() - _volumeRect.x()) - _downCoord;
		float64 startFrom = snap((_downCoord - ((_volumeRect.width() - st::playerVolume.pxWidth()) / 2)) / float64(st::playerVolume.pxWidth()), 0., 1.);
		float64 add = delta / float64(4 * st::playerVolume.pxWidth()), result = snap(startFrom + add, 0., 1.);
		if (result != cSongVolume()) {
			cSetSongVolume(result);
			emit audioPlayer()->songVolumeChanged();
			rtlupdate(_volumeRect);
		}
	} else if (_down == OverPlayback) {
		_downProgress = snap((pos.x() - _playbackRect.x()) / float64(_playbackRect.width()), 0., 1.);
		rtlupdate(_playbackRect);
		updateDownTime();
	} else if (_down == OverNone) {
		bool inInfo = ((pos.x() >= _infoRect.x()) && (pos.x() < _fullRect.x() + _fullRect.width()) && (pos.y() >= _playRect.y()) && (pos.y() <= _playRect.y() + _playRect.height()));
		if (_prevAvailable && _prevRect.contains(pos)) {
			updateOverState(OverPrev);
		} else if (_nextAvailable && _nextRect.contains(pos)) {
			updateOverState(OverNext);
		} else if (_playRect.contains(pos)) {
			updateOverState(OverPlay);
		} else if (_closeRect.contains(pos)) {
			updateOverState(OverClose);
		} else if (_volumeRect.contains(pos)) {
			updateOverState(OverVolume);
		} else if (_repeatRect.contains(pos)) {
			updateOverState(OverRepeat);
		} else if (_duration && _playbackRect.contains(pos)) {
			updateOverState(OverPlayback);
		} else if (_fullAvailable && inInfo) {
			updateOverState(OverFull);
		} else if (_over != OverNone) {
			updateOverState(OverNone);
		}
	}
}
Exemple #6
0
bool PlayerWidget::progressStep(float64 ms) {
	float64 dt = ms / (2 * AudioVoiceMsgUpdateView);
	bool res = true;
	if (_duration && dt >= 1) {
		a_progress.finish();
		a_loadProgress.finish();
		res = false;
	} else {
		a_progress.update(qMin(dt, 1.), anim::linear);
		a_loadProgress.update(1. - (st::radialDuration / (st::radialDuration + ms)), anim::linear);
	}
	rtlupdate(_playbackRect);
	return res;
}
void CalendarBox::Inner::mousePressEvent(QMouseEvent *e) {
	setPressed(_selected);
	if (_selected != kEmptySelection) {
		auto index = _selected + _context->daysShift();
		Assert(index >= 0);

		auto row = index / kDaysInWeek;
		auto col = index % kDaysInWeek;
		auto cell = QRect(rowsLeft() + col * st::calendarCellSize.width(), rowsTop() + row * st::calendarCellSize.height(), st::calendarCellSize.width(), st::calendarCellSize.height());
		auto it = _ripples.find(_selected);
		if (it == _ripples.cend()) {
			auto mask = Ui::RippleAnimation::ellipseMask(QSize(st::calendarCellInner, st::calendarCellInner));
			auto update = [this, cell] { rtlupdate(cell); };
			it = _ripples.emplace(_selected, std::make_unique<Ui::RippleAnimation>(st::defaultRippleAnimation, std::move(mask), std::move(update))).first;
		}
		auto ripplePosition = QPoint(cell.x() + (st::calendarCellSize.width() - st::calendarCellInner) / 2, cell.y() + (st::calendarCellSize.height() - st::calendarCellInner) / 2);
		it->second->add(e->pos() - ripplePosition);
	}
}
void BackgroundRow::updateImage() {
	int32 size = st::settingsBackgroundSize * cIntRetinaFactor();
	QImage back(size, size, QImage::Format_ARGB32_Premultiplied);
	back.setDevicePixelRatio(cRetinaFactor());
	{
		QPainter p(&back);
		auto &pix = Window::chatBackground()->image();
		int sx = (pix.width() > pix.height()) ? ((pix.width() - pix.height()) / 2) : 0;
		int sy = (pix.height() > pix.width()) ? ((pix.height() - pix.width()) / 2) : 0;
		int s = (pix.width() > pix.height()) ? pix.height() : pix.width();
		p.setRenderHint(QPainter::SmoothPixmapTransform);
		p.drawPixmap(0, 0, st::settingsBackgroundSize, st::settingsBackgroundSize, pix, sx, sy, s, s);
	}
	imageRound(back, ImageRoundRadius::Small);
	_background = App::pixmapFromImageInPlace(std_::move(back));
	_background.setDevicePixelRatio(cRetinaFactor());

	rtlupdate(radialRect());

	if (radialLoading()) {
		radialStart();
	}
}
void BackgroundRow::step_radial(uint64 ms, bool timer) {
	_radial.update(radialProgress(), !radialLoading(), ms + radialTimeShift());
	if (timer && _radial.animating()) {
		rtlupdate(radialRect());
	}
}
void PeerListWidget::repaintRow(int index) {
	if (index >= 0) {
		auto left = getListLeft();
		rtlupdate(left, getListTop() + index * _st.height, width() - left, _st.height);
	}
}