canvas.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * canvas.cpp - main canvas widget
  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. #include <fmt/format.h>
  19. #include <QGraphicsScene>
  20. #include <QGraphicsPixmapItem>
  21. #include <QDebug>
  22. #include <geom_helpers/knots.h>
  23. #include <core/node.h>
  24. #include <generic/canvas_editor.h>
  25. #include "canvas.h"
  26. using namespace fmt::literals;
  27. namespace studio {
  28. Canvas::Canvas(QWidget* parent) :
  29. QGraphicsView(parent),
  30. the_scene(std::make_unique<QGraphicsScene>()),
  31. image(std::make_unique<QGraphicsPixmapItem>())
  32. {
  33. setScene(the_scene.get());
  34. the_scene->addItem(image.get());
  35. }
  36. Canvas::~Canvas() {
  37. }
  38. void Canvas::set_main_image(QPixmap const& pixmap) {
  39. image->setPixmap(pixmap);
  40. }
  41. void Canvas::active_node_changed(std::shared_ptr<core::AbstractValue> node) {
  42. if (active_node != node) {
  43. active_node = node;
  44. remove_node_editor();
  45. add_canvas_editor(*this, node);
  46. }
  47. }
  48. void Canvas::add_node_editor(std::unique_ptr<CanvasEditor> editor_) {
  49. editor = std::move(editor_);
  50. editor->set_canvas(this);
  51. }
  52. void Canvas::remove_node_editor() {
  53. editor.reset();
  54. }
  55. } // namespace studio