Skip to content

Commit

Permalink
* Remake hide video panel timer
Browse files Browse the repository at this point in the history
  • Loading branch information
trueromanus committed Apr 10, 2024
1 parent 359ed2a commit 06d0e88
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
13 changes: 13 additions & 0 deletions src/Classes/ViewModels/onlineplayerviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,19 @@ bool OnlinePlayerViewModel::releaseIsRutube(int releaseId) noexcept
return isRutubeHasVideos(release->videos());
}

void OnlinePlayerViewModel::clearPanelTimer() noexcept
{
m_panelTimerCounter = 0;
}

void OnlinePlayerViewModel::increasePanelTimer() noexcept
{
m_panelTimerCounter++;
if (m_panelTimerCounter > 15) {
emit hidePanelIfItVisible();
}
}

void OnlinePlayerViewModel::saveVideoSeens()
{
QJsonArray array;
Expand Down
4 changes: 4 additions & 0 deletions src/Classes/ViewModels/onlineplayerviewmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class OnlinePlayerViewModel : public QObject
bool m_muted { false };
bool m_endSkipOpening { false };
bool m_needProxyFallback { false };
int m_panelTimerCounter { 0 };

public:
explicit OnlinePlayerViewModel(QObject *parent = nullptr);
Expand Down Expand Up @@ -303,6 +304,8 @@ class OnlinePlayerViewModel : public QObject
Q_INVOKABLE void quickSetupForSingleDownloadedTorrent(const QStringList& files, int releaseId) noexcept;
Q_INVOKABLE bool releaseHasVideos(int releaseId) noexcept;
Q_INVOKABLE bool releaseIsRutube(int releaseId) noexcept;
Q_INVOKABLE void clearPanelTimer() noexcept;
Q_INVOKABLE void increasePanelTimer() noexcept;

private:
void saveVideoSeens();
Expand Down Expand Up @@ -380,6 +383,7 @@ private slots:
void mutedChanged();
void endSkipOpeningChanged();
void needProxyFallbackChanged();
void hidePanelIfItVisible();

};

Expand Down
32 changes: 9 additions & 23 deletions src/Views/OnlinePlayer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Page {
signal playInPlayer()
signal stopInPlayer()
signal playerCreated()
signal needHidePlayer()

onPlayInPlayer: {
playerLoader.item.play();
Expand Down Expand Up @@ -80,8 +81,8 @@ Page {
if (event.key === Qt.Key_MediaTogglePlayPause) togglePlayback();
}

onWindowNotActived: {
if (!playerTimer.running) playerTimer.restart();
onNeedHidePlayer: {
_page.setControlVisible(false);
}

onNavigateFrom: {
Expand Down Expand Up @@ -135,14 +136,6 @@ Page {
color: "black"
}

Timer {
id: playerTimer
interval: 2000
running: false
repeat: true
onTriggered: _page.setControlVisible(false)
}

MouseArea {
id: mainPlayerMouseArea
anchors.fill: parent
Expand All @@ -162,15 +155,8 @@ Page {
return;
}

onlinePlayerViewModel.clearPanelTimer();
_page.setControlVisible(true);
const x = mouse.x;
const y = mouse.y;
onlinePlayerViewModel.lastMouseYPosition = y;
if (y > _page.height - controlPanel.height) {
playerTimer.stop();
} else {
playerTimer.restart();
}
}
onExited: {
if (_page.height - onlinePlayerViewModel.lastMouseYPosition < 10) if (!playerTimer.running) playerTimer.restart();
Expand Down Expand Up @@ -215,10 +201,8 @@ Page {
releasePosterArea.visible = showReleaseInfo.checked && playbackState !== "play";
playButton.visible = playbackState === "pause" || playbackState === "stop";
pauseButton.visible = playbackState === "play";
if (playbackState === "play") {
playerTimer.start();
} else {
playerTimer.stop();
if (playbackState !== "play") {
onlinePlayerViewModel.clearPanelTimer();
_page.setControlVisible(true);
}

Expand Down Expand Up @@ -274,6 +258,8 @@ Page {

if (onlinePlayerViewModel.positionIterator < 20 && isPlaying && isBuffered) onlinePlayerViewModel.positionIterator++;

if (isPlaying && isBuffered) onlinePlayerViewModel.increasePanelTimer();

if (onlinePlayerViewModel.positionIterator >= 20) {
onlinePlayerViewModel.positionIterator = 0;
onlinePlayerViewModel.setVideoSeens(onlinePlayerViewModel.selectedRelease, onlinePlayerViewModel.selectedVideo, position);
Expand Down Expand Up @@ -335,7 +321,7 @@ Page {
anchors.fill: parent
hoverEnabled: true
onEntered: {
if (playerTimer.running) playerTimer.stop();
onlinePlayerViewModel.clearPanelTimer();
}
onClicked: {
if (isGroup) return;
Expand Down
6 changes: 4 additions & 2 deletions src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,7 @@ ApplicationWindow {
}
onPlayerPlaybackStateChanged: {
//I'm using hardcode constant because multimedia module loading dynamically
const playingState = 1;
if (playerPlaybackState === playingState) {
if (playerPlaybackState === "play") {
osExtras.startPreventSleepMode();
} else {
osExtras.stopPreventSleepMode();
Expand All @@ -958,6 +957,9 @@ ApplicationWindow {
onRutubeVideoIdChanged: {
if (rutubeVideoId) Qt.openUrlExternally("https://rutube.ru/play/embed/" + rutubeVideoId);
}
onHidePanelIfItVisible: {
videoplayer.needHidePlayer();
}
}

ReleasesViewModel {
Expand Down

0 comments on commit 06d0e88

Please sign in to comment.