TreeView.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "TreeView.h"
  2. #include "Common/SmoothScroll.h"
  3. #include <QWheelEvent>
  4. TreeWidget::TreeWidget(QWidget *parent) : QTreeWidget(parent)
  5. {
  6. verticalSmoothScroll = new SmoothScroll(this, Qt::Vertical);
  7. horizonSmoothScroll = new SmoothScroll(this, Qt::Horizontal);
  8. setItemDelegate(new TreeItemDelegate(this));
  9. setIconSize(QSize(16, 16));
  10. FluentStyleSheet::apply("TREE_VIEW", this);
  11. }
  12. void TreeWidget::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
  13. {
  14. QRect rc = rect;
  15. rc.moveLeft(15);
  16. return QTreeWidget::drawBranches(painter, rc, index);
  17. }
  18. void TreeWidget::wheelEvent(QWheelEvent *event)
  19. {
  20. if (event->modifiers() == Qt::NoModifier) {
  21. if ((verticalSmoothScroll->smoothMode() == SmoothMode::NO_SMOOTH)
  22. || (abs(event->angleDelta().y()) % 120 != 0)) {
  23. QTreeWidget::wheelEvent(event);
  24. } else {
  25. verticalSmoothScroll->wheelEvent(event);
  26. }
  27. } else {
  28. if ((horizonSmoothScroll->smoothMode() == SmoothMode::NO_SMOOTH) || (abs(event->angleDelta().y()) % 120 != 0)) {
  29. QTreeWidget::wheelEvent(event);
  30. } else {
  31. horizonSmoothScroll->wheelEvent(event);
  32. }
  33. }
  34. }
  35. TreeView::TreeView(QWidget *parent) : QTreeView(parent)
  36. {
  37. verticalSmoothScroll = new SmoothScroll(this, Qt::Vertical);
  38. horizonSmoothScroll = new SmoothScroll(this, Qt::Horizontal);
  39. setItemDelegate(new TreeItemDelegate(this));
  40. setIconSize(QSize(16, 16));
  41. FluentStyleSheet::apply("TREE_VIEW", this);
  42. FluentStyleSheet::apply("TREE_VIEW", (QWidget *)this->verticalScrollBar());
  43. }
  44. void TreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
  45. {
  46. QRect rc = rect;
  47. rc.moveLeft(15);
  48. return QTreeView::drawBranches(painter, rc, index);
  49. }
  50. void TreeView::wheelEvent(QWheelEvent *event)
  51. {
  52. if (event->modifiers() == Qt::NoModifier) {
  53. if ((verticalSmoothScroll->smoothMode() == SmoothMode::NO_SMOOTH)
  54. || (abs(event->angleDelta().y()) % 120 != 0)) {
  55. QTreeView::wheelEvent(event);
  56. } else {
  57. verticalSmoothScroll->wheelEvent(event);
  58. }
  59. } else {
  60. if ((horizonSmoothScroll->smoothMode() == SmoothMode::NO_SMOOTH) || (abs(event->angleDelta().y()) % 120 != 0)) {
  61. QTreeView::wheelEvent(event);
  62. } else {
  63. horizonSmoothScroll->wheelEvent(event);
  64. }
  65. }
  66. }