time_item.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* time_item.h - time editing item
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_CANVAS_EDITORS_TIME_ITEM_H_E6E1B74E_13BE_5F5F_B46E_771E4C2E09A3
  18. #define STUDIO_CANVAS_EDITORS_TIME_ITEM_H_E6E1B74E_13BE_5F5F_B46E_771E4C2E09A3
  19. #include <QGraphicsRectItem>
  20. #include <core/time/time.h>
  21. namespace rainynite::studio {
  22. /**
  23. * Time-editing canvas item that can be used to make editors on timeline.
  24. *
  25. * TODO: more flexible fps support (currently editors stick to const fps).
  26. */
  27. class TimeItem : public QGraphicsRectItem {
  28. public:
  29. TimeItem();
  30. virtual ~TimeItem() {
  31. }
  32. QVariant itemChange(GraphicsItemChange change, QVariant const& value) override;
  33. QRectF boundingRect() const override;
  34. void move_to(core::Time time);
  35. void set_fps(core::Time::fps_type fps_);
  36. void set_readonly(bool ro);
  37. void set_pos_height(int y, int height);
  38. protected:
  39. virtual void position_changed(core::Time time) = 0;
  40. virtual void selected_changed(bool /*is_selected*/) {}
  41. private:
  42. double change_pos(double x);
  43. private:
  44. core::Time::fps_type fps = 1;
  45. };
  46. } // namespace rainynite::studio
  47. #endif