Fit media frames inside monitors and close video before widget teardown
This commit is contained in:
1 parent
703f4a4a60
commit
8ab294fb30
2 files changed
+27
-9
No files matched your search
@@ -396,22 +396,28 @@ void MainWindow::restoreMediaWindowGeometry(QWidget* window) {
|
||||
if (!available.isValid()) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "MediaWindow: monitor has no available area name=%s", qPrintable(display->name())); return;
|
||||
}
|
||||
window->setMinimumSize(window->minimumSize().boundedTo(available.size()));
|
||||
window->winId();
|
||||
window->windowHandle()->setScreen(display);
|
||||
const QMargins margins = window->windowHandle()->frameMargins();
|
||||
const QRect bounds = available.marginsRemoved(margins);
|
||||
if (!bounds.isValid()) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "MediaWindow: monitor area cannot fit window frame name=%s frame=%d,%d,%d,%d",
|
||||
qPrintable(display->name()), margins.left(), margins.top(), margins.right(), margins.bottom()); return;
|
||||
}
|
||||
window->setMinimumSize(window->minimumSize().boundedTo(bounds.size()));
|
||||
const QSize size = QSize(saved ? savedWidth : 800, saved ? savedHeight : 600)
|
||||
.expandedTo(window->minimumSize()).boundedTo(available.size());
|
||||
qint64 x = available.x() + (available.width() - size.width()) / 2;
|
||||
qint64 y = available.y() + (available.height() - size.height()) / 2;
|
||||
.expandedTo(window->minimumSize()).boundedTo(bounds.size());
|
||||
qint64 x = bounds.x() + (bounds.width() - size.width()) / 2;
|
||||
qint64 y = bounds.y() + (bounds.height() - size.height()) / 2;
|
||||
if (saved) {
|
||||
x = qint64(m_mediaWindowState.value("x").toInt()) - m_mediaWindowState.value("screen_x").toInt() + available.x();
|
||||
y = qint64(m_mediaWindowState.value("y").toInt()) - m_mediaWindowState.value("screen_y").toInt() + available.y();
|
||||
}
|
||||
const QRect target(int(qBound(qint64(available.left()), x, qint64(available.right() - size.width() + 1))),
|
||||
int(qBound(qint64(available.top()), y, qint64(available.bottom() - size.height() + 1))), size.width(), size.height());
|
||||
const QRect target(int(qBound(qint64(bounds.left()), x, qint64(bounds.right() - size.width() + 1))),
|
||||
int(qBound(qint64(bounds.top()), y, qint64(bounds.bottom() - size.height() + 1))), size.width(), size.height());
|
||||
if (saved && (target.x() != x || target.y() != y || size != QSize(savedWidth, savedHeight)))
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "MediaWindow: fitted saved rect into monitor=%s area=%d,%d %dx%d",
|
||||
qPrintable(display->name()), available.x(), available.y(), available.width(), available.height());
|
||||
window->winId();
|
||||
window->windowHandle()->setScreen(display);
|
||||
window->setGeometry(target);
|
||||
window->setWindowState(!saved || mode == "normal" ? Qt::WindowNoState
|
||||
: mode == "fullscreen" ? Qt::WindowFullScreen : Qt::WindowMaximized);
|
||||
|
||||
@@ -285,9 +285,17 @@ VideoPlayerWindow::VideoPlayerWindow(QWidget* parent)
|
||||
resize(640, 360);
|
||||
}
|
||||
|
||||
VideoPlayerWindow::~VideoPlayerWindow() = default;
|
||||
VideoPlayerWindow::~VideoPlayerWindow() {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "VideoWindow: destroying player state=%d visible=%d", int(m_engine->state()), isVisible());
|
||||
m_hideTimer->stop();
|
||||
disconnect(m_engine, nullptr, this, nullptr);
|
||||
m_engine->close();
|
||||
}
|
||||
|
||||
void VideoPlayerWindow::playFile(const QString& path) {
|
||||
const QRect before = normalGeometry();
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "VideoWindow: open file=%s visible=%d state=%d normal=%d,%d %dx%d",
|
||||
qPrintable(path), isVisible(), int(windowState()), before.x(), before.y(), before.width(), before.height());
|
||||
m_render->clearFrame();
|
||||
m_slider->setRange(0, 0);
|
||||
m_timeLabel->setText(QStringLiteral("0:00 / 0:00"));
|
||||
@@ -368,6 +376,7 @@ void VideoPlayerWindow::onFinished() {
|
||||
}
|
||||
|
||||
void VideoPlayerWindow::toggleFullscreen() {
|
||||
const QRect before = normalGeometry();
|
||||
if (isFullScreen()) {
|
||||
showNormal();
|
||||
setControlsVisible(true);
|
||||
@@ -376,6 +385,9 @@ void VideoPlayerWindow::toggleFullscreen() {
|
||||
showFullScreen();
|
||||
m_hideTimer->start();
|
||||
}
|
||||
const QRect after = normalGeometry();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_VIDEO, "VideoWindow: fullscreen=%d normal_before=%d,%d %dx%d normal_after=%d,%d %dx%d",
|
||||
isFullScreen(), before.x(), before.y(), before.width(), before.height(), after.x(), after.y(), after.width(), after.height());
|
||||
}
|
||||
|
||||
void VideoPlayerWindow::setControlsVisible(bool visible) {
|
||||
|
||||
Reference in new issue
Block a user