Skip to content

Commit

Permalink
ui/video-presets: Persist the preset lock setting
Browse files Browse the repository at this point in the history
  • Loading branch information
leikareipa committed Nov 1, 2023
1 parent dd63387 commit 86dd54c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/capture/video_presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void kvideopreset_lock(const bool isLocked)

void kvideopreset_activate_preset(const video_preset_s *const preset)
{
if (LOCKED || !kc_has_signal())
if (LOCKED || !kc_has_signal() || !preset)
{
return;
}
Expand Down
30 changes: 21 additions & 9 deletions src/display/qt/windows/ControlPanel/VideoPresets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ control_panel::VideoPresets::VideoPresets(QWidget *parent) :
this->ui->lineEdit_presetFilename->setText(QFileInfo(newFilename).fileName());
this->ui->lineEdit_presetFilename->setToolTip(newFilename);

this->ui->checkBox_lockSelectedPreset->setDisabled(newFilename.isEmpty());
this->ui->pushButton_savePresetFileAs->setDisabled(newFilename.isEmpty());
this->ui->pushButton_closePresetFile->setDisabled(newFilename.isEmpty());
});
Expand All @@ -164,6 +165,11 @@ control_panel::VideoPresets::VideoPresets(QWidget *parent) :
}
});

connect(ui->comboBox_presetList, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](const int index)
{
kpers_set_value(INI_GROUP_VIDEO_PRESETS, "SelectedPresetIndex", std::max(index, 0));
});

connect(ui->comboBox_presetList, &VideoPresetList::preset_selected, this, [this]
{
CONTROLS_LIVE_UPDATE = false;
Expand Down Expand Up @@ -231,6 +237,8 @@ control_panel::VideoPresets::VideoPresets(QWidget *parent) :

connect(ui->checkBox_lockSelectedPreset, &QCheckBox::toggled, this, [this](const bool isChecked)
{
kpers_set_value(INI_GROUP_VIDEO_PRESETS, "LockSelectedPreset", isChecked);

if (isChecked)
{
kvideopreset_activate_preset(ui->comboBox_presetList->current_preset());
Expand Down Expand Up @@ -414,21 +422,23 @@ control_panel::VideoPresets::VideoPresets(QWidget *parent) :
});
}

// Register app event listeners.
{
ev_video_preset_activated.listen([this]
{
this->update_active_preset_indicator();
});
}

// Restore persistent settings.
{
if (kcom_video_presets_file_name().empty())
{
const QString presetsSourceFile = kpers_value_of(INI_GROUP_VIDEO_PRESETS, "SourceFile", QString()).toString();
kcom_override_video_presets_file_name(presetsSourceFile.toStdString());
}
}

// Register app event listeners.
{
ev_video_preset_activated.listen([this]
{
this->update_active_preset_indicator();
});
this->ui->checkBox_lockSelectedPreset->setChecked(kpers_value_of(INI_GROUP_VIDEO_PRESETS, "LockSelectedPreset", false).toBool());
}

// Force initialization of any GUI elements that respond to dynamic changes
Expand Down Expand Up @@ -522,6 +532,8 @@ void control_panel::VideoPresets::update_active_preset_indicator(void)

void control_panel::VideoPresets::assign_presets(const std::vector<video_preset_s*> &presets)
{
const unsigned idx = kpers_value_of(INI_GROUP_VIDEO_PRESETS, "SelectedPresetIndex", 0).toUInt();

ui->comboBox_presetList->clear();

for (auto *const preset: presets)
Expand All @@ -532,8 +544,8 @@ void control_panel::VideoPresets::assign_presets(const std::vector<video_preset_
/// TODO: It would be better to sort the items by (numeric) resolution.
ui->comboBox_presetList->sort_alphabetically();

ui->comboBox_presetList->setCurrentIndex(0);
emit ui->comboBox_presetList->preset_selected(0); // Manually force the signal, in case there's only one preset in the list.
ui->comboBox_presetList->setCurrentIndex(-1);
ui->comboBox_presetList->setCurrentIndex(std::min(int(idx), (ui->comboBox_presetList->count() - 1)));

return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/display/qt/windows/ControlPanel/VideoPresets.ui
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
</item>
<item>
<widget class="QCheckBox" name="checkBox_lockSelectedPreset">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down

0 comments on commit 86dd54c

Please sign in to comment.