diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ce843625..e219217a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1326,10 +1326,18 @@ void MainWindow::cancelSlideshow() void MainWindow::slideshowAction() { - if (qvApp->getSettingsManager().getBoolean("slideshowreversed")) - previousFile(); - else + switch (qvApp->getSettingsManager().getEnum("slideshowdirection")) + { + case Qv::SlideshowDirection::Forward: nextFile(); + break; + case Qv::SlideshowDirection::Backward: + previousFile(); + break; + case Qv::SlideshowDirection::Random: + randomFile(); + break; + } } void MainWindow::decreaseSpeed() diff --git a/src/qvnamespace.h b/src/qvnamespace.h index b82ba52d..841bc427 100644 --- a/src/qvnamespace.h +++ b/src/qvnamespace.h @@ -46,6 +46,13 @@ namespace Qv Extended = 2 }; + enum class SlideshowDirection + { + Forward = 0, + Backward = 1, + Random = 2 + }; + enum class SortMode { Name = 0, diff --git a/src/qvoptionsdialog.cpp b/src/qvoptionsdialog.cpp index 3d875cb9..4b20b3fe 100644 --- a/src/qvoptionsdialog.cpp +++ b/src/qvoptionsdialog.cpp @@ -18,8 +18,6 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) : setAttribute(Qt::WA_DeleteOnClose); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint)); - populateComboBoxes(); - connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &QVOptionsDialog::buttonBoxClicked); connect(ui->shortcutsTable, &QTableWidget::cellDoubleClicked, this, &QVOptionsDialog::shortcutCellDoubleClicked); connect(ui->bgColorCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::bgColorCheckboxStateChanged); @@ -29,7 +27,11 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) : connect(ui->constrainImagePositionCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::constrainImagePositionCheckboxStateChanged); connect(ui->middleButtonModeClickRadioButton, &QRadioButton::clicked, this, &QVOptionsDialog::middleButtonModeChanged); connect(ui->middleButtonModeDragRadioButton, &QRadioButton::clicked, this, &QVOptionsDialog::middleButtonModeChanged); + connect(ui->titlebarComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::titlebarComboBoxCurrentIndexChanged); + connect(ui->windowResizeComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged); + connect(ui->langComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged); + populateComboBoxes(); populateLanguages(); QSettings settings; @@ -83,11 +85,10 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) : ui->altHorizontalScrollLabel->setText(tr("%1 + Horizontal Scroll:").arg(ctrlKeyName)); syncSettings(false, true); - connect(ui->titlebarComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::titlebarComboBoxCurrentIndexChanged); - connect(ui->windowResizeComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged); - connect(ui->langComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged); syncShortcuts(); updateButtonBox(); + + isInitialLoad = false; } QVOptionsDialog::~QVOptionsDialog() @@ -156,12 +157,10 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections) syncCheckbox(ui->checkerboardBackgroundCheckbox, "checkerboardbackground", defaults, makeConnections); // titlebarmode syncComboBox(ui->titlebarComboBox, "titlebarmode", defaults, makeConnections); - titlebarComboBoxCurrentIndexChanged(ui->titlebarComboBox->currentIndex()); // customtitlebartext syncLineEdit(ui->customTitlebarLineEdit, "customtitlebartext", defaults, makeConnections); // windowresizemode syncComboBox(ui->windowResizeComboBox, "windowresizemode", defaults, makeConnections); - windowResizeComboBoxCurrentIndexChanged(ui->windowResizeComboBox->currentIndex()); // aftermatchingsize syncComboBox(ui->afterMatchingSizeComboBox, "aftermatchingsizemode", defaults, makeConnections); // minwindowresizedpercentage @@ -215,7 +214,7 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections) // colorspaceconversion syncComboBox(ui->colorSpaceConversionComboBox, "colorspaceconversion", defaults, makeConnections); // language - syncComboBoxData(ui->langComboBox, "language", defaults, makeConnections); + syncComboBox(ui->langComboBox, "language", defaults, makeConnections); // sortmode syncComboBox(ui->sortComboBox, "sortmode", defaults, makeConnections); // sortdescending @@ -224,8 +223,8 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections) syncComboBox(ui->preloadingComboBox, "preloadingmode", defaults, makeConnections); // loopfolders syncCheckbox(ui->loopFoldersCheckbox, "loopfoldersenabled", defaults, makeConnections); - // slideshowreversed - syncComboBox(ui->slideshowDirectionComboBox, "slideshowreversed", defaults, makeConnections); + // slideshowdirection + syncComboBox(ui->slideshowDirectionComboBox, "slideshowdirection", defaults, makeConnections); // slideshowtimer syncDoubleSpinBox(ui->slideshowTimerSpinBox, "slideshowtimer", defaults, makeConnections); // afterdelete @@ -290,20 +289,6 @@ void QVOptionsDialog::syncRadioButtons(QList buttons, const QStr } void QVOptionsDialog::syncComboBox(QComboBox *comboBox, const QString &key, bool defaults, bool makeConnection) -{ - auto val = qvApp->getSettingsManager().getInteger(key, defaults); - comboBox->setCurrentIndex(val); - transientSettings.insert(key, val); - - if (makeConnection) - { - connect(comboBox, QOverload::of(&QComboBox::currentIndexChanged), this, [this, key](int index) { - modifySetting(key, index); - }); - } -} - -void QVOptionsDialog::syncComboBoxData(QComboBox *comboBox, const QString &key, bool defaults, bool makeConnection) { auto val = qvApp->getSettingsManager().getString(key, defaults); comboBox->setCurrentIndex(comboBox->findData(val)); @@ -513,12 +498,14 @@ void QVOptionsDialog::scalingCheckboxStateChanged(int state) void QVOptionsDialog::titlebarComboBoxCurrentIndexChanged(int index) { - ui->customTitlebarLineEdit->setEnabled(index == 4); + const auto value = static_cast(ui->titlebarComboBox->itemData(index).toInt()); + ui->customTitlebarLineEdit->setEnabled(value == Qv::TitleBarText::Custom); } void QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged(int index) { - bool enableRelatedControls = index != 0; + const auto value = static_cast(ui->windowResizeComboBox->itemData(index).toInt()); + bool enableRelatedControls = value != Qv::WindowResizeMode::Never; ui->afterMatchingSizeLabel->setEnabled(enableRelatedControls); ui->afterMatchingSizeComboBox->setEnabled(enableRelatedControls); ui->minWindowResizeLabel->setEnabled(enableRelatedControls); @@ -557,7 +544,7 @@ void QVOptionsDialog::populateLanguages() void QVOptionsDialog::languageComboBoxCurrentIndexChanged(int index) { Q_UNUSED(index) - if (!languageRestartMessageShown) + if (!isInitialLoad && !languageRestartMessageShown) { QMessageBox::information(this, tr("Restart Required"), tr("You must restart qView to change the language.")); languageRestartMessageShown = true; @@ -578,7 +565,7 @@ void QVOptionsDialog::middleButtonModeChanged() ui->altMiddleDragComboBox->setVisible(isDrag); } -const QMap QVOptionsDialog::mapAfterDelete() { +const Ui::ComboBoxItems QVOptionsDialog::mapAfterDelete() { return { { Qv::AfterDelete::MoveBack, tr("Move Back") }, { Qv::AfterDelete::DoNothing, tr("Do Nothing") }, @@ -586,7 +573,7 @@ const QMap QVOptionsDialog::mapAfterDelete() { }; } -const QMap QVOptionsDialog::mapAfterMatchingSize() { +const Ui::ComboBoxItems QVOptionsDialog::mapAfterMatchingSize() { return { { Qv::AfterMatchingSize::AvoidRepositioning, tr("Avoid repositioning") }, { Qv::AfterMatchingSize::CenterOnPrevious, tr("Center relative to previous image") }, @@ -594,14 +581,14 @@ const QMap QVOptionsDialog::mapAfterMatchingSize }; } -const QMap QVOptionsDialog::mapCalculatedZoomMode() { +const Ui::ComboBoxItems QVOptionsDialog::mapCalculatedZoomMode() { return { { Qv::CalculatedZoomMode::ZoomToFit, tr("Zoom to Fit") }, { Qv::CalculatedZoomMode::FillWindow, tr("Fill Window") } }; } -const QMap QVOptionsDialog::mapColorSpaceConversion() { +const Ui::ComboBoxItems QVOptionsDialog::mapColorSpaceConversion() { return { { Qv::ColorSpaceConversion::Disabled, tr("Disabled") }, { Qv::ColorSpaceConversion::AutoDetect, tr("Auto-detect") }, @@ -610,7 +597,7 @@ const QMap QVOptionsDialog::mapColorSpaceConv }; } -const QMap QVOptionsDialog::mapPreloadMode() { +const Ui::ComboBoxItems QVOptionsDialog::mapPreloadMode() { return { { Qv::PreloadMode::Disabled, tr("Disabled") }, { Qv::PreloadMode::Adjacent, tr("Adjacent") }, @@ -618,7 +605,15 @@ const QMap QVOptionsDialog::mapPreloadMode() { }; } -const QMap QVOptionsDialog::mapSortMode() { +const Ui::ComboBoxItems QVOptionsDialog::mapSlideshowDirection() { + return { + { Qv::SlideshowDirection::Forward, tr("Forward") }, + { Qv::SlideshowDirection::Backward, tr("Backward") }, + { Qv::SlideshowDirection::Random, tr("Random") } + }; +} + +const Ui::ComboBoxItems QVOptionsDialog::mapSortMode() { return { { Qv::SortMode::Name, tr("Name") }, { Qv::SortMode::DateModified, tr("Date Modified") }, @@ -629,7 +624,7 @@ const QMap QVOptionsDialog::mapSortMode() { }; } -const QMap QVOptionsDialog::mapTitleBarText() { +const Ui::ComboBoxItems QVOptionsDialog::mapTitleBarText() { return { { Qv::TitleBarText::Basic, tr("Basic") }, { Qv::TitleBarText::Minimal, tr("Minimal") }, @@ -639,7 +634,7 @@ const QMap QVOptionsDialog::mapTitleBarText() { }; } -const QMap QVOptionsDialog::mapWindowResizeMode() { +const Ui::ComboBoxItems QVOptionsDialog::mapWindowResizeMode() { return { { Qv::WindowResizeMode::Never, tr("Never") }, { Qv::WindowResizeMode::WhenLaunching, tr("When launching") }, @@ -647,7 +642,7 @@ const QMap QVOptionsDialog::mapWindowResizeMode() }; } -const QMap QVOptionsDialog::mapViewportClickAction() { +const Ui::ComboBoxItems QVOptionsDialog::mapViewportClickAction() { return { { Qv::ViewportClickAction::None, tr("None") }, { Qv::ViewportClickAction::ZoomToFit, tr("Zoom to Fit") }, @@ -658,7 +653,7 @@ const QMap QVOptionsDialog::mapViewportClickAc }; } -const QMap QVOptionsDialog::mapViewportDragAction() { +const Ui::ComboBoxItems QVOptionsDialog::mapViewportDragAction() { return { { Qv::ViewportDragAction::None, tr("None") }, { Qv::ViewportDragAction::Pan, tr("Pan") }, @@ -666,7 +661,7 @@ const QMap QVOptionsDialog::mapViewportDragActi }; } -const QMap QVOptionsDialog::mapViewportScrollAction() { +const Ui::ComboBoxItems QVOptionsDialog::mapViewportScrollAction() { return { { Qv::ViewportScrollAction::None, tr("None") }, { Qv::ViewportScrollAction::Zoom, tr("Zoom") }, @@ -676,12 +671,12 @@ const QMap QVOptionsDialog::mapViewportScroll } template -static void populateComboBox(QComboBox *comboBox, const QMap &items) +static void populateComboBox(QComboBox *comboBox, const Ui::ComboBoxItems &items) { comboBox->clear(); - for (auto it = items.constBegin(); it != items.constEnd(); ++it) + for (const auto &item : items) { - comboBox->addItem(it.value(), static_cast(it.key())); + comboBox->addItem(item.second, static_cast(item.first)); } } @@ -701,6 +696,8 @@ void QVOptionsDialog::populateComboBoxes() populateComboBox(ui->preloadingComboBox, mapPreloadMode()); + populateComboBox(ui->slideshowDirectionComboBox, mapSlideshowDirection()); + populateComboBox(ui->afterDeletionComboBox, mapAfterDelete()); populateComboBox(ui->doubleClickComboBox, mapViewportClickAction()); diff --git a/src/qvoptionsdialog.h b/src/qvoptionsdialog.h index abe0575f..c337858a 100644 --- a/src/qvoptionsdialog.h +++ b/src/qvoptionsdialog.h @@ -12,6 +12,9 @@ namespace Ui { class QVOptionsDialog; + +template +using ComboBoxItems = QVector>; } class QVOptionsDialog : public QDialog @@ -32,7 +35,6 @@ class QVOptionsDialog : public QDialog void syncCheckbox(QCheckBox *checkbox, const QString &key, bool defaults = false, bool makeConnection = false); void syncRadioButtons(QList buttons, const QString &key, bool defaults = false, bool makeConnection = false); void syncComboBox(QComboBox *comboBox, const QString &key, bool defaults = false, bool makeConnection = false); - void syncComboBoxData(QComboBox *comboBox, const QString &key, bool defaults = false, bool makeConnection = false); void syncSpinBox(QSpinBox *spinBox, const QString &key, bool defaults = false, bool makeConnection = false); void syncDoubleSpinBox(QDoubleSpinBox *doubleSpinBox, const QString &key, bool defaults = false, bool makeConnection = false); void syncLineEdit(QLineEdit *lineEdit, const QString &key, bool defaults = false, bool makeConnection = false); @@ -45,17 +47,18 @@ class QVOptionsDialog : public QDialog void populateLanguages(); void populateComboBoxes(); - const QMap mapAfterDelete(); - const QMap mapAfterMatchingSize(); - const QMap mapCalculatedZoomMode(); - const QMap mapColorSpaceConversion(); - const QMap mapPreloadMode(); - const QMap mapSortMode(); - const QMap mapTitleBarText(); - const QMap mapWindowResizeMode(); - const QMap mapViewportClickAction(); - const QMap mapViewportDragAction(); - const QMap mapViewportScrollAction(); + const Ui::ComboBoxItems mapAfterDelete(); + const Ui::ComboBoxItems mapAfterMatchingSize(); + const Ui::ComboBoxItems mapCalculatedZoomMode(); + const Ui::ComboBoxItems mapColorSpaceConversion(); + const Ui::ComboBoxItems mapPreloadMode(); + const Ui::ComboBoxItems mapSlideshowDirection(); + const Ui::ComboBoxItems mapSortMode(); + const Ui::ComboBoxItems mapTitleBarText(); + const Ui::ComboBoxItems mapWindowResizeMode(); + const Ui::ComboBoxItems mapViewportClickAction(); + const Ui::ComboBoxItems mapViewportDragAction(); + const Ui::ComboBoxItems mapViewportScrollAction(); private slots: void shortcutCellDoubleClicked(int row, int column); @@ -83,6 +86,8 @@ private slots: QList transientShortcuts; + bool isInitialLoad {true}; + bool languageRestartMessageShown {false}; }; diff --git a/src/qvoptionsdialog.ui b/src/qvoptionsdialog.ui index 55895b0b..dda9b430 100644 --- a/src/qvoptionsdialog.ui +++ b/src/qvoptionsdialog.ui @@ -627,18 +627,7 @@ - - - - Forward - - - - - Backward - - - + diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index f2a2072e..ccf6dd47 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -209,7 +209,7 @@ void SettingsManager::initializeSettingsLibrary() settingsLibrary.insert("sortdescending", {false, {}}); settingsLibrary.insert("preloadingmode", {static_cast(Qv::PreloadMode::Adjacent), {}}); settingsLibrary.insert("loopfoldersenabled", {true, {}}); - settingsLibrary.insert("slideshowreversed", {false, {}}); + settingsLibrary.insert("slideshowdirection", {static_cast(Qv::SlideshowDirection::Forward), {}}); settingsLibrary.insert("slideshowtimer", {5, {}}); settingsLibrary.insert("afterdelete", {static_cast(Qv::AfterDelete::MoveForward), {}}); settingsLibrary.insert("askdelete", {true, {}});