Skip to content

Commit

Permalink
Finish decoupling combobox values from indexes.
Browse files Browse the repository at this point in the history
Also add "Random" slideshow direction because I had to change that code anyway.
  • Loading branch information
jdpurcell committed Oct 8, 2023
1 parent f2e5ba2 commit 0898faf
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 69 deletions.
14 changes: 11 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,18 @@ void MainWindow::cancelSlideshow()

void MainWindow::slideshowAction()
{
if (qvApp->getSettingsManager().getBoolean("slideshowreversed"))
previousFile();
else
switch (qvApp->getSettingsManager().getEnum<Qv::SlideshowDirection>("slideshowdirection"))
{
case Qv::SlideshowDirection::Forward:
nextFile();
break;
case Qv::SlideshowDirection::Backward:
previousFile();
break;
case Qv::SlideshowDirection::Random:
randomFile();
break;
}
}

void MainWindow::decreaseSpeed()
Expand Down
7 changes: 7 additions & 0 deletions src/qvnamespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ namespace Qv
Extended = 2
};

enum class SlideshowDirection
{
Forward = 0,
Backward = 1,
Random = 2
};

enum class SortMode
{
Name = 0,
Expand Down
79 changes: 38 additions & 41 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::titlebarComboBoxCurrentIndexChanged);
connect(ui->windowResizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged);
connect(ui->langComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged);

populateComboBoxes();
populateLanguages();

QSettings settings;
Expand Down Expand Up @@ -83,11 +85,10 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
ui->altHorizontalScrollLabel->setText(tr("%1 + Horizontal Scroll:").arg(ctrlKeyName));

syncSettings(false, true);
connect(ui->titlebarComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::titlebarComboBoxCurrentIndexChanged);
connect(ui->windowResizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged);
connect(ui->langComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged);
syncShortcuts();
updateButtonBox();

isInitialLoad = false;
}

QVOptionsDialog::~QVOptionsDialog()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -290,20 +289,6 @@ void QVOptionsDialog::syncRadioButtons(QList<QRadioButton *> 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<int>::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));
Expand Down Expand Up @@ -513,12 +498,14 @@ void QVOptionsDialog::scalingCheckboxStateChanged(int state)

void QVOptionsDialog::titlebarComboBoxCurrentIndexChanged(int index)
{
ui->customTitlebarLineEdit->setEnabled(index == 4);
const auto value = static_cast<Qv::TitleBarText>(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<Qv::WindowResizeMode>(ui->windowResizeComboBox->itemData(index).toInt());
bool enableRelatedControls = value != Qv::WindowResizeMode::Never;
ui->afterMatchingSizeLabel->setEnabled(enableRelatedControls);
ui->afterMatchingSizeComboBox->setEnabled(enableRelatedControls);
ui->minWindowResizeLabel->setEnabled(enableRelatedControls);
Expand Down Expand Up @@ -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;
Expand All @@ -578,30 +565,30 @@ void QVOptionsDialog::middleButtonModeChanged()
ui->altMiddleDragComboBox->setVisible(isDrag);
}

const QMap<Qv::AfterDelete, QString> QVOptionsDialog::mapAfterDelete() {
const Ui::ComboBoxItems<Qv::AfterDelete> QVOptionsDialog::mapAfterDelete() {
return {
{ Qv::AfterDelete::MoveBack, tr("Move Back") },
{ Qv::AfterDelete::DoNothing, tr("Do Nothing") },
{ Qv::AfterDelete::MoveForward, tr("Move Forward") }
};
}

const QMap<Qv::AfterMatchingSize, QString> QVOptionsDialog::mapAfterMatchingSize() {
const Ui::ComboBoxItems<Qv::AfterMatchingSize> QVOptionsDialog::mapAfterMatchingSize() {
return {
{ Qv::AfterMatchingSize::AvoidRepositioning, tr("Avoid repositioning") },
{ Qv::AfterMatchingSize::CenterOnPrevious, tr("Center relative to previous image") },
{ Qv::AfterMatchingSize::CenterOnScreen, tr("Center relative to screen") }
};
}

const QMap<Qv::CalculatedZoomMode, QString> QVOptionsDialog::mapCalculatedZoomMode() {
const Ui::ComboBoxItems<Qv::CalculatedZoomMode> QVOptionsDialog::mapCalculatedZoomMode() {
return {
{ Qv::CalculatedZoomMode::ZoomToFit, tr("Zoom to Fit") },
{ Qv::CalculatedZoomMode::FillWindow, tr("Fill Window") }
};
}

const QMap<Qv::ColorSpaceConversion, QString> QVOptionsDialog::mapColorSpaceConversion() {
const Ui::ComboBoxItems<Qv::ColorSpaceConversion> QVOptionsDialog::mapColorSpaceConversion() {
return {
{ Qv::ColorSpaceConversion::Disabled, tr("Disabled") },
{ Qv::ColorSpaceConversion::AutoDetect, tr("Auto-detect") },
Expand All @@ -610,15 +597,23 @@ const QMap<Qv::ColorSpaceConversion, QString> QVOptionsDialog::mapColorSpaceConv
};
}

const QMap<Qv::PreloadMode, QString> QVOptionsDialog::mapPreloadMode() {
const Ui::ComboBoxItems<Qv::PreloadMode> QVOptionsDialog::mapPreloadMode() {
return {
{ Qv::PreloadMode::Disabled, tr("Disabled") },
{ Qv::PreloadMode::Adjacent, tr("Adjacent") },
{ Qv::PreloadMode::Extended, tr("Extended") }
};
}

const QMap<Qv::SortMode, QString> QVOptionsDialog::mapSortMode() {
const Ui::ComboBoxItems<Qv::SlideshowDirection> QVOptionsDialog::mapSlideshowDirection() {
return {
{ Qv::SlideshowDirection::Forward, tr("Forward") },
{ Qv::SlideshowDirection::Backward, tr("Backward") },
{ Qv::SlideshowDirection::Random, tr("Random") }
};
}

const Ui::ComboBoxItems<Qv::SortMode> QVOptionsDialog::mapSortMode() {
return {
{ Qv::SortMode::Name, tr("Name") },
{ Qv::SortMode::DateModified, tr("Date Modified") },
Expand All @@ -629,7 +624,7 @@ const QMap<Qv::SortMode, QString> QVOptionsDialog::mapSortMode() {
};
}

const QMap<Qv::TitleBarText, QString> QVOptionsDialog::mapTitleBarText() {
const Ui::ComboBoxItems<Qv::TitleBarText> QVOptionsDialog::mapTitleBarText() {
return {
{ Qv::TitleBarText::Basic, tr("Basic") },
{ Qv::TitleBarText::Minimal, tr("Minimal") },
Expand All @@ -639,15 +634,15 @@ const QMap<Qv::TitleBarText, QString> QVOptionsDialog::mapTitleBarText() {
};
}

const QMap<Qv::WindowResizeMode, QString> QVOptionsDialog::mapWindowResizeMode() {
const Ui::ComboBoxItems<Qv::WindowResizeMode> QVOptionsDialog::mapWindowResizeMode() {
return {
{ Qv::WindowResizeMode::Never, tr("Never") },
{ Qv::WindowResizeMode::WhenLaunching, tr("When launching") },
{ Qv::WindowResizeMode::WhenOpeningImages, tr("When opening images") }
};
}

const QMap<Qv::ViewportClickAction, QString> QVOptionsDialog::mapViewportClickAction() {
const Ui::ComboBoxItems<Qv::ViewportClickAction> QVOptionsDialog::mapViewportClickAction() {
return {
{ Qv::ViewportClickAction::None, tr("None") },
{ Qv::ViewportClickAction::ZoomToFit, tr("Zoom to Fit") },
Expand All @@ -658,15 +653,15 @@ const QMap<Qv::ViewportClickAction, QString> QVOptionsDialog::mapViewportClickAc
};
}

const QMap<Qv::ViewportDragAction, QString> QVOptionsDialog::mapViewportDragAction() {
const Ui::ComboBoxItems<Qv::ViewportDragAction> QVOptionsDialog::mapViewportDragAction() {
return {
{ Qv::ViewportDragAction::None, tr("None") },
{ Qv::ViewportDragAction::Pan, tr("Pan") },
{ Qv::ViewportDragAction::MoveWindow, tr("Move Window") }
};
}

const QMap<Qv::ViewportScrollAction, QString> QVOptionsDialog::mapViewportScrollAction() {
const Ui::ComboBoxItems<Qv::ViewportScrollAction> QVOptionsDialog::mapViewportScrollAction() {
return {
{ Qv::ViewportScrollAction::None, tr("None") },
{ Qv::ViewportScrollAction::Zoom, tr("Zoom") },
Expand All @@ -676,12 +671,12 @@ const QMap<Qv::ViewportScrollAction, QString> QVOptionsDialog::mapViewportScroll
}

template <typename TEnum>
static void populateComboBox(QComboBox *comboBox, const QMap<TEnum, QString> &items)
static void populateComboBox(QComboBox *comboBox, const Ui::ComboBoxItems<TEnum> &items)
{
comboBox->clear();
for (auto it = items.constBegin(); it != items.constEnd(); ++it)
for (const auto &item : items)
{
comboBox->addItem(it.value(), static_cast<int>(it.key()));
comboBox->addItem(item.second, static_cast<int>(item.first));
}
}

Expand All @@ -701,6 +696,8 @@ void QVOptionsDialog::populateComboBoxes()

populateComboBox(ui->preloadingComboBox, mapPreloadMode());

populateComboBox(ui->slideshowDirectionComboBox, mapSlideshowDirection());

populateComboBox(ui->afterDeletionComboBox, mapAfterDelete());

populateComboBox(ui->doubleClickComboBox, mapViewportClickAction());
Expand Down
29 changes: 17 additions & 12 deletions src/qvoptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Ui {
class QVOptionsDialog;

template <typename TEnum>
using ComboBoxItems = QVector<std::pair<TEnum, QString>>;
}

class QVOptionsDialog : public QDialog
Expand All @@ -32,7 +35,6 @@ class QVOptionsDialog : public QDialog
void syncCheckbox(QCheckBox *checkbox, const QString &key, bool defaults = false, bool makeConnection = false);
void syncRadioButtons(QList<QRadioButton*> 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);
Expand All @@ -45,17 +47,18 @@ class QVOptionsDialog : public QDialog
void populateLanguages();
void populateComboBoxes();

const QMap<Qv::AfterDelete, QString> mapAfterDelete();
const QMap<Qv::AfterMatchingSize, QString> mapAfterMatchingSize();
const QMap<Qv::CalculatedZoomMode, QString> mapCalculatedZoomMode();
const QMap<Qv::ColorSpaceConversion, QString> mapColorSpaceConversion();
const QMap<Qv::PreloadMode, QString> mapPreloadMode();
const QMap<Qv::SortMode, QString> mapSortMode();
const QMap<Qv::TitleBarText, QString> mapTitleBarText();
const QMap<Qv::WindowResizeMode, QString> mapWindowResizeMode();
const QMap<Qv::ViewportClickAction, QString> mapViewportClickAction();
const QMap<Qv::ViewportDragAction, QString> mapViewportDragAction();
const QMap<Qv::ViewportScrollAction, QString> mapViewportScrollAction();
const Ui::ComboBoxItems<Qv::AfterDelete> mapAfterDelete();
const Ui::ComboBoxItems<Qv::AfterMatchingSize> mapAfterMatchingSize();
const Ui::ComboBoxItems<Qv::CalculatedZoomMode> mapCalculatedZoomMode();
const Ui::ComboBoxItems<Qv::ColorSpaceConversion> mapColorSpaceConversion();
const Ui::ComboBoxItems<Qv::PreloadMode> mapPreloadMode();
const Ui::ComboBoxItems<Qv::SlideshowDirection> mapSlideshowDirection();
const Ui::ComboBoxItems<Qv::SortMode> mapSortMode();
const Ui::ComboBoxItems<Qv::TitleBarText> mapTitleBarText();
const Ui::ComboBoxItems<Qv::WindowResizeMode> mapWindowResizeMode();
const Ui::ComboBoxItems<Qv::ViewportClickAction> mapViewportClickAction();
const Ui::ComboBoxItems<Qv::ViewportDragAction> mapViewportDragAction();
const Ui::ComboBoxItems<Qv::ViewportScrollAction> mapViewportScrollAction();

private slots:
void shortcutCellDoubleClicked(int row, int column);
Expand Down Expand Up @@ -83,6 +86,8 @@ private slots:

QList<QStringList> transientShortcuts;

bool isInitialLoad {true};

bool languageRestartMessageShown {false};
};

Expand Down
13 changes: 1 addition & 12 deletions src/qvoptionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,7 @@
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="slideshowDirectionComboBox">
<item>
<property name="text">
<string>Forward</string>
</property>
</item>
<item>
<property name="text">
<string>Backward</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="slideshowDirectionComboBox"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_5">
Expand Down
2 changes: 1 addition & 1 deletion src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void SettingsManager::initializeSettingsLibrary()
settingsLibrary.insert("sortdescending", {false, {}});
settingsLibrary.insert("preloadingmode", {static_cast<int>(Qv::PreloadMode::Adjacent), {}});
settingsLibrary.insert("loopfoldersenabled", {true, {}});
settingsLibrary.insert("slideshowreversed", {false, {}});
settingsLibrary.insert("slideshowdirection", {static_cast<int>(Qv::SlideshowDirection::Forward), {}});
settingsLibrary.insert("slideshowtimer", {5, {}});
settingsLibrary.insert("afterdelete", {static_cast<int>(Qv::AfterDelete::MoveForward), {}});
settingsLibrary.insert("askdelete", {true, {}});
Expand Down

0 comments on commit 0898faf

Please sign in to comment.