attachable.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* attachable.h - attachable to canvas interface
  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_ATTACHABLE_H_3B57A84F_8276_545C_8A78_11812A0ECA88
  18. #define STUDIO_CANVAS_ATTACHABLE_H_3B57A84F_8276_545C_8A78_11812A0ECA88
  19. class QGraphicsScene;
  20. class QEvent;
  21. namespace rainynite::studio {
  22. class AbstractCanvas;
  23. class CanvasAttachable {
  24. public:
  25. virtual ~CanvasAttachable() = default;
  26. void set_canvas(AbstractCanvas* canvas_);
  27. /// Called by canvas on mouse event
  28. virtual bool canvas_event(QEvent* /*event*/) {
  29. return false;
  30. }
  31. protected:
  32. virtual void detach_canvas() {}
  33. virtual void setup_canvas() {}
  34. AbstractCanvas* get_canvas() const {
  35. return canvas;
  36. }
  37. QGraphicsScene* get_scene() const;
  38. private:
  39. AbstractCanvas* canvas = nullptr;
  40. };
  41. } // namespace rainynite::studio
  42. #endif