Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.0KB

  1. /*
  2. * Patchbay Canvas engine using QGraphicsView/Scene
  3. * Copyright (C) 2010-2012 Filipe Coelho <falktx@falktx.com>
  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 2 of the License, or
  8. * 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. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #include "canvasbezierlinemov.h"
  18. #include <QtGui/QPainter>
  19. #include "canvasport.h"
  20. START_NAMESPACE_PATCHCANVAS
  21. CanvasBezierLineMov::CanvasBezierLineMov(PortMode port_mode, PortType port_type, QGraphicsItem* parent) :
  22. QGraphicsPathItem(parent, canvas.scene)
  23. {
  24. m_port_mode = port_mode;
  25. m_port_type = port_type;
  26. // Port position doesn't change while moving around line
  27. p_itemX = scenePos().x();
  28. p_itemY = scenePos().y();
  29. p_width = ((CanvasPort*)parentItem())->getPortWidth();
  30. QPen pen;
  31. if (port_type == PORT_TYPE_AUDIO_JACK)
  32. pen = QPen(canvas.theme->line_audio_jack, 2);
  33. else if (port_type == PORT_TYPE_MIDI_JACK)
  34. pen = QPen(canvas.theme->line_midi_jack, 2);
  35. else if (port_type == PORT_TYPE_MIDI_A2J)
  36. pen = QPen(canvas.theme->line_midi_a2j, 2);
  37. else if (port_type == PORT_TYPE_MIDI_ALSA)
  38. pen = QPen(canvas.theme->line_midi_alsa, 2);
  39. else
  40. {
  41. qWarning("PatchCanvas::CanvasBezierLineMov(%s, %s, %p) - invalid port type", port_mode2str(port_mode), port_type2str(port_type), parent);
  42. pen = QPen(Qt::black);
  43. }
  44. QColor color(0,0,0,0);
  45. setBrush(color);
  46. setPen(pen);
  47. }
  48. void CanvasBezierLineMov::deleteFromScene()
  49. {
  50. canvas.scene->removeItem(this);
  51. delete this;
  52. }
  53. void CanvasBezierLineMov::updateLinePos(QPointF scenePos)
  54. {
  55. int old_x, old_y, mid_x, new_x, final_x, final_y;
  56. if (m_port_mode == PORT_MODE_INPUT)
  57. {
  58. old_x = 0;
  59. old_y = 7.5;
  60. mid_x = abs(scenePos.x()-p_itemX)/2;
  61. new_x = old_x-mid_x;
  62. }
  63. else if (m_port_mode == PORT_MODE_OUTPUT)
  64. {
  65. old_x = p_width+12;
  66. old_y = 7.5;
  67. mid_x = abs(scenePos.x()-(p_itemX+old_x))/2;
  68. new_x = old_x+mid_x;
  69. }
  70. else
  71. return;
  72. final_x = scenePos.x()-p_itemX;
  73. final_y = scenePos.y()-p_itemY;
  74. QPainterPath path(QPointF(old_x, old_y));
  75. path.cubicTo(new_x, old_y, new_x, final_y, final_x, final_y);
  76. setPath(path);
  77. }
  78. int CanvasBezierLineMov::type() const
  79. {
  80. return CanvasBezierLineMovType;
  81. }
  82. void CanvasBezierLineMov::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  83. {
  84. painter->setRenderHint(QPainter::Antialiasing, bool(options.antialiasing));
  85. QGraphicsPathItem::paint(painter, option, widget);
  86. }
  87. END_NAMESPACE_PATCHCANVAS