canvas.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/abstract_value.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. clear_node_editors();
  45. add_canvas_editor(*this, node);
  46. }
  47. }
  48. void Canvas::add_node_editor(std::unique_ptr<CanvasEditor> editor) {
  49. editor->set_canvas(this);
  50. editors.push_back(std::move(editor));
  51. }
  52. void Canvas::remove_node_editor() {
  53. // TODO
  54. clear_node_editors();
  55. }
  56. void Canvas::clear_node_editors() {
  57. editors.clear();
  58. }
  59. } // namespace studio