settingswidget.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #ifndef SettingsWidget_H
  2. #define SettingsWidget_H
  3. #include <QWidget>
  4. #include <QTimer>
  5. #include <QSettings>
  6. #include <QPropertyAnimation>
  7. #include <QPushButton>
  8. #include <QEvent>
  9. #include <QDebug>
  10. #include <QScrollArea>
  11. #include <QScrollBar>
  12. #include <QWheelEvent>
  13. #include "models/settings.h"
  14. #include "models/lotrodatmanager.h"
  15. namespace Ui {
  16. class SettingsWidget;
  17. }
  18. class PatchList;
  19. namespace SettingsWidgetPrivate {
  20. class ComboboxScrollingDisabler : public QObject {
  21. Q_OBJECT
  22. protected:
  23. bool eventFilter(QObject *, QEvent *event) override {
  24. if (event->type() == QEvent::Wheel) {
  25. event->ignore();
  26. return true;
  27. } else {
  28. return false;
  29. }
  30. }
  31. };
  32. class SettingsTabsScroller : public QObject {
  33. public:
  34. SettingsTabsScroller(QList<QWidget*> entries, QScrollArea* target_widget) : target_widget_(target_widget), current_entry_id_(0), entries_(std::move(entries)) {
  35. scroll_entries_animation_ = new QPropertyAnimation(target_widget_->verticalScrollBar(), "value");
  36. scroll_entries_animation_->setDuration(450);
  37. scroll_entries_animation_->setEasingCurve(QEasingCurve::InOutQuart);
  38. }
  39. ~SettingsTabsScroller() {
  40. scroll_entries_animation_->deleteLater();
  41. }
  42. protected:
  43. bool eventFilter(QObject *, QEvent *event) override {
  44. // if (obj != target_widget_) {
  45. // return false;
  46. // }
  47. if (event->type() == QEvent::Wheel) {
  48. event->ignore();
  49. QWheelEvent *wheel_event = (QWheelEvent*)(event);
  50. int wheel_angle = wheel_event->angleDelta().y();
  51. qDebug() << "SCROLL EVENT! " << wheel_event->pixelDelta() << "/" << wheel_event->angleDelta();
  52. if (scroll_entries_animation_->state() == QPropertyAnimation::Running) {
  53. return true;
  54. }
  55. if (wheel_angle < 0 && current_entry_id_ + 1 < entries_.size()) {
  56. ++current_entry_id_;
  57. scroll_entries_animation_->setStartValue(target_widget_->verticalScrollBar()->value());
  58. scroll_entries_animation_->setEndValue(entries_[current_entry_id_]->y());
  59. scroll_entries_animation_->start();
  60. return true;
  61. }
  62. if (wheel_angle > 0 && current_entry_id_ - 1 >= 0) {
  63. --current_entry_id_;
  64. scroll_entries_animation_->setStartValue(target_widget_->verticalScrollBar()->value());
  65. scroll_entries_animation_->setEndValue(entries_[current_entry_id_]->y());
  66. scroll_entries_animation_->start();
  67. return true;
  68. }
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. private:
  75. QScrollArea* target_widget_;
  76. int current_entry_id_;
  77. QList<QWidget*> entries_;
  78. QPropertyAnimation* scroll_entries_animation_;
  79. };
  80. }
  81. class SettingsWidget : public QWidget
  82. {
  83. Q_OBJECT
  84. public:
  85. explicit SettingsWidget(PatchList *legacy_patches, QWidget *parent = 0);
  86. ~SettingsWidget();
  87. signals:
  88. void SettingsChanged(); // Settings were changed so we should not do any actions until SettingsApplied() signal
  89. void SettingsApplied(); // Need to re-initialise all environment and start updates check
  90. void SettingsReset(); // Need to drop updates blockage, but do not re-initialize all environment
  91. public slots:
  92. void setActualParametersValues();
  93. void updateFontsSizes();
  94. protected:
  95. void resizeEvent(QResizeEvent *event) override;
  96. private slots:
  97. void onLotroManagerProcessChanged(LotroDatManager::Status status);
  98. void onBackupSettingsInfoChanged();
  99. void processParameterChange();
  100. void checkIfParametersWereReset();
  101. void on_interface_scale_combobox_currentIndexChanged(const QString &arg1);
  102. void on_change_folder_button_clicked();
  103. void on_lotro_base_language_combobox_currentIndexChanged(int index);
  104. void onPatchTotalOperationsStarted();
  105. void onPatchTotalOperationsFinished();
  106. void on_skiprawdownload_checkbox_stateChanged(int arg1);
  107. void on_nosplashscreen_checkbox_stateChanged(int arg1);
  108. void on_backup_create_button_clicked();
  109. void on_backup_restore_button_clicked();
  110. void on_backup_remove_button_clicked();
  111. void on_patch_texts_checkbox_clicked();
  112. void on_patch_items_checkbox_clicked();
  113. void on_patch_emotes_checkbox_clicked();
  114. void on_patch_maps_checkbox_clicked();
  115. void on_patch_textures_checkbox_clicked();
  116. void on_patch_loadscreens_checkbox_clicked();
  117. void on_patch_sounds_checkbox_clicked();
  118. void on_patch_video_checkbox_clicked();
  119. void on_patch_force_apply_button_clicked();
  120. void on_micropatch_checkbox_clicked();
  121. void on_apply_changes_button_clicked();
  122. private:
  123. bool patch_operations_running_ = false;
  124. Ui::SettingsWidget *ui = nullptr;
  125. PatchList *legacy_patches_ = nullptr;
  126. SettingsWidgetPrivate::ComboboxScrollingDisabler* combobox_scrolling_disabler = nullptr;
  127. SettingsWidgetPrivate::SettingsTabsScroller* scroller = nullptr;
  128. Settings::SettingsBackup settings_backup_;
  129. bool settings_changed_ = false;
  130. };
  131. #endif // SettingsWidget_H