shape.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* shape.h - base for shape creating tools
  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_TOOLS_SHAPE_H_5A163439_B575_5309_B679_7539C7DF5AB7
  18. #define STUDIO_CANVAS_TOOLS_SHAPE_H_5A163439_B575_5309_B679_7539C7DF5AB7
  19. #include <2geom/point.h>
  20. #include <core/node_tree/path.h>
  21. #include "base.h"
  22. namespace rainynite::studio::tools {
  23. /**
  24. * Base class for shape-creating tools.
  25. */
  26. class Shape : public Base {
  27. public:
  28. bool canvas_event(QEvent* event) override;
  29. protected:
  30. using MakeShape = std::function<shared_ptr<core::AbstractValue>(Geom::Point)>;
  31. void new_shape_at(QPointF const& pos, MakeShape f);
  32. virtual bool draw_shape_event(QEvent* event);
  33. virtual bool mouse_press(QPoint const& pos) = 0;
  34. virtual bool mouse_move(QPoint const& /*pos*/) {
  35. return false;
  36. }
  37. virtual bool mouse_release(QPoint const& /*pos*/) {
  38. return false;
  39. }
  40. /**
  41. * Called on double click which should indicate editing is finished.
  42. *
  43. * Default implementation is empty because some shapes are finished
  44. * implicitly by end of dragging (circle, rectangle, etc)
  45. */
  46. virtual bool editing_done() {
  47. return false;
  48. }
  49. /// Returns whether this node can accept the shape
  50. virtual bool accept(shared_ptr<core::AbstractValue> node);
  51. /// Write shape to active node
  52. virtual void write_shape(shared_ptr<core::AbstractValue> node);
  53. /// Get target node index
  54. core::NodeTreeIndex get_index() const;
  55. private:
  56. core::NodeTreePath target_node_index;
  57. };
  58. } // namespace rainynite::studio::tools
  59. #endif