settingswidget.h 5.0 KB

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