timeline_view.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * timeline_view.h - simple timeline
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __STUDIO__WIDGETS__TIMELINE_VIEW_H__D9D5E306
  19. #define __STUDIO__WIDGETS__TIMELINE_VIEW_H__D9D5E306
  20. #include <QWidget>
  21. #include <QPen>
  22. #include <generic/context_listener.h>
  23. namespace studio {
  24. class TimelineView : public QWidget, public ContextListener {
  25. Q_OBJECT
  26. public:
  27. explicit TimelineView(QWidget* parent = nullptr);
  28. public:
  29. virtual QSize sizeHint() const override;
  30. public Q_SLOTS:
  31. void set_zoom_level(int level);
  32. protected:
  33. virtual void time_changed(core::Time) override;
  34. protected:
  35. virtual void paintEvent(QPaintEvent* paintEvent) override;
  36. virtual void mousePressEvent(QMouseEvent* event) override;
  37. virtual void mouseReleaseEvent(QMouseEvent* event) override;
  38. virtual void mouseMoveEvent(QMouseEvent* event) override;
  39. private:
  40. void start_moving(double x);
  41. void stop_moving(double x);
  42. void move(double x);
  43. bool is_moving = false;
  44. private:
  45. double frames_to_x(double frames);
  46. double x_to_frames(double x);
  47. inline double zoom_factor() {
  48. return std::pow(2, zoom_level);
  49. }
  50. private:
  51. QPen time_cursor_pen;
  52. private:
  53. int zoom_level;
  54. struct Null {};
  55. std::shared_ptr<Null> destroy_detector;
  56. };
  57. }
  58. #endif