浏览代码

Finished implementing Settings functionality

Ivan Arkhipov 5 年之前
父节点
当前提交
54ac499bce

+ 6 - 0
src/Legacy/models/patchlist.cpp

@@ -136,6 +136,12 @@ void PatchList::startAutoUpdate()
     patch_update_timer.start();
 }
 
+void PatchList::stopAutoUpdate()
+{
+    patch_update_timer.stop();
+    auto_updates_enabled_ = false;
+}
+
 void PatchList::initialize() {
     ++active_operations_num_;
     emit patchOperationsStarted();

+ 2 - 0
src/Legacy/models/patchlist.h

@@ -30,6 +30,8 @@ signals:
 public slots:
     void startAutoUpdate();
 
+    void stopAutoUpdate();
+
     void update();
 
     void initialize();

+ 12 - 0
src/Legacy/widgets/mainwindow.cpp

@@ -58,6 +58,12 @@ MainWindow::MainWindow(PatchList *legacy_patches, QWidget *parent)
     ui->content_layout->addWidget(help_widget_);
     ui->content_layout->addWidget(about_widget_);
 
+    // Adding patch update triggers on settings state changes
+    connect(settings_widget_, &SettingsWidget::SettingsChanged, legacy_patches_, &PatchList::stopAutoUpdate);
+    connect(settings_widget_, &SettingsWidget::SettingsReset, legacy_patches_, &PatchList::startAutoUpdate);
+    connect(settings_widget_, &SettingsWidget::SettingsApplied, legacy_patches_, &PatchList::initialize);
+
+
     hideAllContentWidgets();
     status_widget_->show();
 
@@ -91,6 +97,12 @@ MainWindow::MainWindow(PatchList *legacy_patches, QWidget *parent)
     qDebug() << __FUNCTION__ << "Installing event filters to clickable objects";
     setEventFilterRecursive(this);
 
+    qDebug() << __FUNCTION__ << "Resizing window due to Settings value";
+    int window_scale_factor = Settings::getValue("General/UI_scale").toInt();;
+    window_width = default_window_width * window_scale_factor / 100;
+    window_height = default_window_height * window_scale_factor / 100;
+    resize(window_width, window_height);
+
     qDebug() << __FUNCTION__ << "Finished main frame initialisation";
     show();
 }

+ 57 - 49
src/Legacy/widgets/settingswidget.cpp

@@ -43,7 +43,8 @@ SettingsWidget::SettingsWidget(PatchList *legacy_patches, QWidget *parent)
 
     ui->apply_changes_button->hide();
     ui->apply_changes_label->hide();
-
+    ui->patch_installing_label->hide();
+    settings_backup_ = Settings::createSettingsBackup();
     setActualParametersValues();
 }
 
@@ -87,10 +88,10 @@ void SettingsWidget::setActualParametersValues()
 
     ui->patch_texts_checkbox->setChecked(Settings::getValue("Components/texts_main").toBool());
     ui->patch_items_checkbox->setChecked(Settings::getValue("Components/texts_items").toBool());
-    ui->patch_emotes_checkbox->setChecked(Settings::getValue("Components/texts/emotes").toBool());
+    ui->patch_emotes_checkbox->setChecked(Settings::getValue("Components/texts_emotes").toBool());
     ui->patch_maps_checkbox->setChecked(Settings::getValue("Components/maps").toBool());
     ui->patch_loadscreens_checkbox->setChecked(Settings::getValue("Components/loadscreens").toBool());
-    ui->patch_textures_checkbox->setChecked(Settings::getValue("Componens/textures").toBool());
+    ui->patch_textures_checkbox->setChecked(Settings::getValue("Components/textures").toBool());
     ui->patch_sounds_checkbox->setChecked(Settings::getValue("Components/sounds").toBool());
     ui->patch_video_checkbox->setChecked(Settings::getValue("Components/videos").toBool());
     ui->micropatch_checkbox->setChecked(Settings::getValue("Components/micropatch").toBool());
@@ -197,7 +198,6 @@ void SettingsWidget::resizeEvent(QResizeEvent *)
 void SettingsWidget::processParameterChange() {
     if (!settings_changed_) {
         settings_changed_ = true;
-        settings_backup_ = Settings::createSettingsBackup();
         emit SettingsChanged();
         ui->apply_changes_label->show();
         ui->apply_changes_button->show();
@@ -225,12 +225,12 @@ void SettingsWidget::on_change_folder_button_clicked()
 
     QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/") + "/";
 
-    if (Settings::getValue("Lotro/game_path").toString() == game_folder) {
+    if (settings_backup_["Lotro/game_path"].toString() == game_folder) {
         return;
     }
 
     processParameterChange();
-    Settings::setValue("Lotro/game_path", game_folder);
+    settings_backup_["Lotro/game_path"] = game_folder;
     ui->game_folder_path->setText(game_folder);
     checkIfParametersWereReset();
 }
@@ -246,36 +246,36 @@ void SettingsWidget::on_lotro_base_language_combobox_currentIndexChanged(int ind
     if (index == 2)
         value = "FR";
 
-    if (Settings::getValue("Lotro/original_locale").toString() == value) {
+    if (settings_backup_["Lotro/original_locale"].toString() == value) {
         return;
     }
 
     processParameterChange();
-    Settings::setValue("Lotro/original_locale", value);
+    settings_backup_["Lotro/original_locale"] = value;
     checkIfParametersWereReset();
 }
 
 void SettingsWidget::on_skiprawdownload_checkbox_stateChanged(int arg1) {
-    processParameterChange();
     if (arg1 == Qt::Checked) {
         Settings::setValue("Lotro/skip_raw_download", true);
+        settings_backup_["Lotro/skip_raw_download"] = true;
     }
     if (arg1 == Qt::Unchecked) {
         Settings::setValue("Lotro/skip_raw_download", false);
+        settings_backup_["Lotro/skip_raw_download"] = false;
     }
-    checkIfParametersWereReset();
 }
 
 void SettingsWidget::on_nosplashscreen_checkbox_stateChanged(int arg1)
 {
-    processParameterChange();
     if (arg1 == Qt::Checked) {
         Settings::setValue("Lotro/no_splash_screen", true);
+        settings_backup_["Lotro/no_splash_screen"] = true;
     }
     if (arg1 == Qt::Unchecked) {
         Settings::setValue("Lotro/no_splash_screen", false);
+        settings_backup_["Lotro/no_splash_screen"] = false;
     }
-    checkIfParametersWereReset();
 }
 
 void SettingsWidget::on_backup_create_button_clicked()
@@ -325,91 +325,91 @@ void SettingsWidget::on_backup_remove_button_clicked()
     QMetaObject::invokeMethod(legacy_patches_, "removeBackup", Qt::QueuedConnection);
 }
 
-void SettingsWidget::on_patch_texts_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_texts_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/texts_main", true);
+    if (ui->patch_texts_checkbox->isChecked()) {
+        settings_backup_["Components/texts_main"] = true;
     } else {
-        Settings::setValue("Components/texts_main", false);
+        settings_backup_["Components/texts_main"] = false;
     }
     checkIfParametersWereReset();
 }
 
-
-void SettingsWidget::on_patch_items_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_items_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/texts_items", true);
+    if (ui->patch_items_checkbox->isChecked()) {
+        settings_backup_["Components/texts_items"] = true;
     } else {
-        Settings::setValue("Components/texts_items", false);
+        settings_backup_["Components/texts_items"] = false;
     }
     checkIfParametersWereReset();
 }
 
-void SettingsWidget::on_patch_emotes_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_emotes_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/texts_emotes", true);
+    if (ui->patch_emotes_checkbox->isChecked()) {
+        settings_backup_["Components/texts_emotes"] = true;
     } else {
-        Settings::setValue("Components/texts_emotes", false);
+        settings_backup_["Components/texts_emotes"] = false;
     }
     checkIfParametersWereReset();
 }
 
-void SettingsWidget::on_patch_maps_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_maps_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/maps", true);
+    if (ui->patch_maps_checkbox->isChecked()) {
+        settings_backup_["Components/maps"] = true;
     } else {
-        Settings::setValue("Components/maps", false);
+        settings_backup_["Components/maps"] = false;
     }
     checkIfParametersWereReset();
 }
 
-void SettingsWidget::on_patch_textures_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_textures_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/textures", true);
+    if (ui->patch_textures_checkbox->isChecked()) {
+        settings_backup_["Components/textures"] = true;
     } else {
-        Settings::setValue("Components/textures", false);
+        settings_backup_["Components/textures"] = false;
     }
     checkIfParametersWereReset();
 }
 
-void SettingsWidget::on_patch_loadscreens_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_loadscreens_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/loadscreens", true);
+    if (ui->patch_loadscreens_checkbox->isChecked()) {
+        settings_backup_["Components/loadscreens"] = true;
     } else {
-        Settings::setValue("Components/loadscreens", false);
+        settings_backup_["Components/loadscreens"] = false;
     }
     checkIfParametersWereReset();
+
 }
 
-void SettingsWidget::on_patch_sounds_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_sounds_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/sounds", true);
+    if (ui->patch_sounds_checkbox->isChecked()) {
+        settings_backup_["Components/sounds"] = true;
     } else {
-        Settings::setValue("Components/sounds", false);
+        settings_backup_["Components/sounds"] = false;
     }
     checkIfParametersWereReset();
 }
 
-void SettingsWidget::on_patch_video_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_patch_video_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/videos", true);
+    if (ui->patch_video_checkbox->isChecked()) {
+        settings_backup_["Components/videos"] = true;
     } else {
-        Settings::setValue("Components/videos", false);
+        settings_backup_["Components/videos"] = false;
     }
     checkIfParametersWereReset();
 }
@@ -419,13 +419,13 @@ void SettingsWidget::on_patch_force_apply_button_clicked()
  // TODO(endevir): Implement
 }
 
-void SettingsWidget::on_micropatch_checkbox_stateChanged(int arg1)
+void SettingsWidget::on_micropatch_checkbox_clicked()
 {
     processParameterChange();
-    if (arg1 == Qt::Checked) {
-        Settings::setValue("Components/micropatch", true);
+    if (ui->micropatch_checkbox->isChecked()) {
+        settings_backup_["Components/micropatch"] = true;
     } else {
-        Settings::setValue("Components/micropatch", false);
+        settings_backup_["Components/micropatch"] = false;
     }
     checkIfParametersWereReset();
 }
@@ -444,6 +444,7 @@ void SettingsWidget::on_interface_scale_combobox_currentIndexChanged(const QStri
     window->resize(default_window_width * value / 100, default_window_height * value / 100);
 
     Settings::setValue("General/UI_scale", value);
+    settings_backup_["General/UI_scale"] = value;
 }
 
 void SettingsWidget::onPatchTotalOperationsStarted()
@@ -474,6 +475,7 @@ void SettingsWidget::onPatchTotalOperationsFinished()
 {
     patch_operations_running_ = false;
     ui->patch_installing_label->hide();
+    settings_backup_ = Settings::createSettingsBackup();
 
     ui->change_folder_button->setEnabled(true);
     ui->lotro_base_language_combobox->setEnabled(true);
@@ -496,5 +498,11 @@ void SettingsWidget::onPatchTotalOperationsFinished()
 
 void SettingsWidget::on_apply_changes_button_clicked()
 {
+    Settings::restoreFromSettingsBackup(settings_backup_);
     Settings::updatePatchComponentsDependencies();
+    settings_changed_ = false;
+    ui->apply_changes_label->hide();
+    ui->apply_changes_button->hide();
+    emit SettingsApplied();
 }
+

+ 15 - 14
src/Legacy/widgets/settingswidget.h

@@ -146,37 +146,38 @@ private slots:
 
     void on_backup_remove_button_clicked();
 
-    void on_patch_texts_checkbox_stateChanged(int arg1);
+    void on_patch_texts_checkbox_clicked();
 
-    void on_patch_items_checkbox_stateChanged(int arg1);
+    void on_patch_items_checkbox_clicked();
 
-    void on_patch_emotes_checkbox_stateChanged(int arg1);
+    void on_patch_emotes_checkbox_clicked();
 
-    void on_patch_maps_checkbox_stateChanged(int arg1);
+    void on_patch_maps_checkbox_clicked();
 
-    void on_patch_textures_checkbox_stateChanged(int arg1);
+    void on_patch_textures_checkbox_clicked();
 
-    void on_patch_loadscreens_checkbox_stateChanged(int arg1);
+    void on_patch_loadscreens_checkbox_clicked();
 
-    void on_patch_sounds_checkbox_stateChanged(int arg1);
+    void on_patch_sounds_checkbox_clicked();
 
-    void on_patch_video_checkbox_stateChanged(int arg1);
+    void on_patch_video_checkbox_clicked();
 
     void on_patch_force_apply_button_clicked();
 
-    void on_micropatch_checkbox_stateChanged(int arg1);
+    void on_micropatch_checkbox_clicked();
 
     void on_apply_changes_button_clicked();
 
+
 private:
-    bool patch_operations_running_;
+    bool patch_operations_running_ = false;
 
-    Ui::SettingsWidget *ui;
+    Ui::SettingsWidget *ui = nullptr;
 
-    PatchList *legacy_patches_;
+    PatchList *legacy_patches_ = nullptr;
 
-    SettingsWidgetPrivate::ComboboxScrollingDisabler* combobox_scrolling_disabler;
-    SettingsWidgetPrivate::SettingsTabsScroller* scroller;
+    SettingsWidgetPrivate::ComboboxScrollingDisabler* combobox_scrolling_disabler = nullptr;
+    SettingsWidgetPrivate::SettingsTabsScroller* scroller = nullptr;
 
     Settings::SettingsBackup settings_backup_;
     bool settings_changed_ = false;

+ 3 - 3
src/Legacy/widgets/settingswidget.ui

@@ -70,7 +70,7 @@
      <number>15</number>
     </property>
     <item row="7" column="0">
-     <widget class="QWidget" name="widget_3" native="true">
+     <widget class="QWidget" name="apply_changes_button_widget" native="true">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
         <horstretch>0</horstretch>
@@ -394,9 +394,9 @@ QScrollBar:vertical {
     <property name="geometry">
      <rect>
       <x>0</x>
-      <y>0</y>
+      <y>-455</y>
       <width>651</width>
-      <height>967</height>
+      <height>976</height>
      </rect>
     </property>
     <property name="sizePolicy">