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.

95 lines
2.6KB

  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 "canvaslinemov.h"
  18. #include <QtGui/QPainter>
  19. #include "canvasport.h"
  20. START_NAMESPACE_PATCHCANVAS
  21. CanvasLineMov::CanvasLineMov(PortMode port_mode, PortType port_type, QGraphicsItem* parent) :
  22. QGraphicsLineItem(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_lineX = scenePos().x();
  28. p_lineY = 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::CanvasLineMov(%s, %s, %p) - invalid port type", port_mode2str(port_mode), port_type2str(port_type), parent);
  42. pen = QPen(Qt::black);
  43. }
  44. setPen(pen);
  45. }
  46. void CanvasLineMov::deleteFromScene()
  47. {
  48. canvas.scene->removeItem(this);
  49. delete this;
  50. }
  51. void CanvasLineMov::updateLinePos(QPointF scenePos)
  52. {
  53. int item_pos[2] = { 0, 0 };
  54. if (m_port_mode == PORT_MODE_INPUT)
  55. {
  56. item_pos[0] = 0;
  57. item_pos[1] = 7.5;
  58. }
  59. else if (m_port_mode == PORT_MODE_OUTPUT)
  60. {
  61. item_pos[0] = p_width+12;
  62. item_pos[1] = 7.5;
  63. }
  64. else
  65. return;
  66. QLineF line(item_pos[0], item_pos[1], scenePos.x()-p_lineX, scenePos.y()-p_lineY);
  67. setLine(line);
  68. }
  69. int CanvasLineMov::type() const
  70. {
  71. return CanvasLineMovType;
  72. }
  73. void CanvasLineMov::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  74. {
  75. painter->setRenderHint(QPainter::Antialiasing, bool(options.antialiasing));
  76. QGraphicsLineItem::paint(painter, option, widget);
  77. }
  78. END_NAMESPACE_PATCHCANVAS