settingswidget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. namespace Ui {
  14. class SettingsWidget;
  15. }
  16. class PatchList;
  17. namespace SettingsWidgetPrivate {
  18. class ComboboxScrollingDisabler : public QObject {
  19. Q_OBJECT
  20. protected:
  21. bool eventFilter(QObject *, QEvent *event) override {
  22. if (event->type() == QEvent::Wheel) {
  23. event->ignore();
  24. return true;
  25. } else {
  26. return false;
  27. }
  28. }
  29. };
  30. class SettingsTabsScroller : public QObject {
  31. public:
  32. SettingsTabsScroller(QList<QWidget*> entries, QScrollArea* target_widget) : target_widget_(target_widget), current_entry_id_(0), entries_(std::move(entries)) {
  33. scroll_entries_animation_ = new QPropertyAnimation(target_widget_->verticalScrollBar(), "value");
  34. scroll_entries_animation_->setDuration(450);
  35. scroll_entries_animation_->setEasingCurve(QEasingCurve::InOutQuart);
  36. }
  37. ~SettingsTabsScroller() {
  38. scroll_entries_animation_->deleteLater();
  39. }
  40. protected:
  41. bool eventFilter(QObject *obj, QEvent *event) override {
  42. // if (obj != target_widget_) {
  43. // return false;
  44. // }
  45. if (event->type() == QEvent::Wheel) {
  46. event->ignore();
  47. QWheelEvent *wheel_event = (QWheelEvent*)(event);
  48. int wheel_angle = wheel_event->angleDelta().y();
  49. qDebug() << "SCROLL EVENT! " << wheel_event->pixelDelta() << "/" << wheel_event->angleDelta();
  50. if (scroll_entries_animation_->state() == QPropertyAnimation::Running) {
  51. return true;
  52. }
  53. if (wheel_angle < 0 && current_entry_id_ + 1 < entries_.size()) {
  54. ++current_entry_id_;
  55. scroll_entries_animation_->setStartValue(target_widget_->verticalScrollBar()->value());
  56. scroll_entries_animation_->setEndValue(entries_[current_entry_id_]->y());
  57. scroll_entries_animation_->start();
  58. return true;
  59. }
  60. if (wheel_angle > 0 && current_entry_id_ - 1 >= 0) {
  61. --current_entry_id_;
  62. scroll_entries_animation_->setStartValue(target_widget_->verticalScrollBar()->value());
  63. scroll_entries_animation_->setEndValue(entries_[current_entry_id_]->y());
  64. scroll_entries_animation_->start();
  65. return true;
  66. }
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. private:
  73. int current_entry_id_;
  74. QScrollArea* target_widget_;
  75. QList<QWidget*> entries_;
  76. QPropertyAnimation* scroll_entries_animation_;
  77. };
  78. }
  79. class SettingsWidget : public QWidget
  80. {
  81. Q_OBJECT
  82. public:
  83. explicit SettingsWidget(PatchList *legacy_patches, QWidget *parent = 0);
  84. ~SettingsWidget();
  85. enum E_STATUS {
  86. E_NONE = 0,
  87. E_ERROR = -2,
  88. E_WARNING = -1,
  89. E_OK = 1
  90. };
  91. public slots:
  92. void updateFontsSizes();
  93. void setStatusToBlock(int block_id, E_STATUS status);
  94. protected:
  95. void resizeEvent(QResizeEvent *event) override;
  96. private slots:
  97. void on_interface_scale_combobox_currentIndexChanged(const QString &arg1);
  98. void on_change_folder_button_clicked();
  99. void on_lotro_base_language_combobox_currentIndexChanged(int index);
  100. private:
  101. Ui::SettingsWidget *ui;
  102. PatchList *legacy_patches_;
  103. SettingsWidgetPrivate::ComboboxScrollingDisabler* combobox_scrolling_disabler;
  104. SettingsWidgetPrivate::SettingsTabsScroller* scroller;
  105. };
  106. #endif // SettingsWidget_H