Skip to content

Commit

Permalink
Option to keep window on top during slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Apr 27, 2024
1 parent 0f777f3 commit 3832e40
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
25 changes: 9 additions & 16 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,25 +1305,18 @@ void MainWindow::nextFrame()
void MainWindow::toggleSlideshow()
{
const auto slideshowActions = qvApp->getActionManager().getAllClonesOfAction("slideshow", this);

if (slideshowTimer->isActive())
{
slideshowTimer->stop();
for (const auto &slideshowAction : slideshowActions)
{
slideshowAction->setText(tr("Start S&lideshow"));
slideshowAction->setIcon(QIcon::fromTheme("media-playback-start"));
}
}
const bool isStarting = !slideshowTimer->isActive();
if (isStarting)
slideshowTimer->start();
else
slideshowTimer->stop();
for (const auto &slideshowAction : slideshowActions)
{
slideshowTimer->start();
for (const auto &slideshowAction : slideshowActions)
{
slideshowAction->setText(tr("Stop S&lideshow"));
slideshowAction->setIcon(QIcon::fromTheme("media-playback-stop"));
}
slideshowAction->setText(isStarting ? tr("Stop S&lideshow") : tr("Start S&lideshow"));
slideshowAction->setIcon(QIcon::fromTheme(isStarting ? "media-playback-stop" : "media-playback-start"));
}
if (qvApp->getSlideshowKeepsWindowOnTop())
windowHandle()->setFlag(Qt::WindowStaysOnTopHint, isStarting);
}

void MainWindow::cancelSlideshow()
Expand Down
1 change: 1 addition & 0 deletions src/qvapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv)
updateChecker.check();

showSubmenuIcons = getSettingsManager().getBoolean("submenuicons");
slideshowKeepsWindowOnTop = getSettingsManager().getBoolean("slideshowkeepswindowontop");

// Block any erroneous icons from showing up on mac and windows
// (this is overridden in some cases)
Expand Down
3 changes: 3 additions & 0 deletions src/qvapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class QVApplication : public QApplication

bool getShowSubmenuIcons() const { return showSubmenuIcons; }

bool getSlideshowKeepsWindowOnTop() const { return slideshowKeepsWindowOnTop; }

void ensureFontLoaded(const QString &path);

static QIcon iconFromFont(const QString &fontFamily, const QChar &codePoint, const int pixelSize, const qreal pixelRatio);
Expand Down Expand Up @@ -143,6 +145,7 @@ protected slots:
QPointer<QVAboutDialog> aboutDialog;

bool showSubmenuIcons {true};
bool slideshowKeepsWindowOnTop {false};

UpdateChecker updateChecker;

Expand Down
14 changes: 10 additions & 4 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
connect(ui->bgColorCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::bgColorCheckboxStateChanged);
connect(ui->nonNativeThemeCheckbox, &QCheckBox::stateChanged, this, [this](int state) { restartNotifyForCheckbox("nonnativetheme", state); });
connect(ui->submenuIconsCheckbox, &QCheckBox::stateChanged, this, [this](int state) { restartNotifyForCheckbox("submenuicons", state); });
connect(ui->slideshowKeepsWindowOnTopCheckbox, &QCheckBox::stateChanged, this, [this](int state) { restartNotifyForCheckbox("slideshowkeepswindowontop", state); });
connect(ui->scalingCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::scalingCheckboxStateChanged);
connect(ui->fitZoomLimitCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::fitZoomLimitCheckboxStateChanged);
connect(ui->constrainImagePositionCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::constrainImagePositionCheckboxStateChanged);
Expand All @@ -46,15 +47,18 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
QSettings settings;
ui->categoryList->setCurrentRow(settings.value("optionstab", 1).toInt());

// On macOS, the dialog should not be dependent on any window
#ifndef Q_OS_MACOS
setWindowModality(Qt::WindowModal);
#ifdef Q_OS_MACOS
if (qvApp->getSlideshowKeepsWindowOnTop())
setWindowModality(Qt::ApplicationModal);
#else
setWindowModality(Qt::WindowModal);
#endif

#ifdef Q_OS_MACOS
// Load window geometry
restoreGeometry(settings.value("optionsgeometry").toByteArray());
#endif


if (QOperatingSystemVersion::current() < QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 13)) {
setWindowTitle(tr("Preferences"));
}
Expand Down Expand Up @@ -190,6 +194,8 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections)
syncCheckbox(ui->detailsInFullscreen, "fullscreendetails", defaults, makeConnections);
// submenuicons
syncCheckbox(ui->submenuIconsCheckbox, "submenuicons", defaults, makeConnections);
// slideshowkeepswindowontop
syncCheckbox(ui->slideshowKeepsWindowOnTopCheckbox, "slideshowkeepswindowontop", defaults, makeConnections);
// persistsession
syncCheckbox(ui->persistSessionCheckbox, "persistsession", defaults, makeConnections);
// filteringenabled
Expand Down
13 changes: 10 additions & 3 deletions src/qvoptionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<x>0</x>
<y>0</y>
<width>482</width>
<height>474</height>
<height>497</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -335,6 +335,13 @@
</widget>
</item>
<item row="15" column="1">
<widget class="QCheckBox" name="slideshowKeepsWindowOnTopCheckbox">
<property name="text">
<string>Keep window on top during slideshow</string>
</property>
</widget>
</item>
<item row="16" column="1">
<widget class="QCheckBox" name="darkTitlebarCheckbox">
<property name="toolTip">
<string>Choose whether or not the titlebar should always be dark regardless of your chosen macOS appearance</string>
Expand All @@ -347,14 +354,14 @@
</property>
</widget>
</item>
<item row="16" column="1">
<item row="17" column="1">
<widget class="QCheckBox" name="quitOnLastWindowCheckbox">
<property name="text">
<string>&amp;Quit on last window closed</string>
</property>
</widget>
</item>
<item row="17" column="1">
<item row="18" column="1">
<widget class="QCheckBox" name="persistSessionCheckbox">
<property name="text">
<string>Persist session across app restarts</string>
Expand Down
1 change: 1 addition & 0 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void SettingsManager::initializeSettingsLibrary()
settingsLibrary.insert("loopfoldersenabled", {true, {}});
settingsLibrary.insert("slideshowdirection", {static_cast<int>(Qv::SlideshowDirection::Forward), {}});
settingsLibrary.insert("slideshowtimer", {5, {}});
settingsLibrary.insert("slideshowkeepswindowontop", {false, {}});
settingsLibrary.insert("afterdelete", {static_cast<int>(Qv::AfterDelete::MoveForward), {}});
settingsLibrary.insert("askdelete", {true, {}});
settingsLibrary.insert("allowmimecontentdetection", {false, {}});
Expand Down

0 comments on commit 3832e40

Please sign in to comment.