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.

149 lines
4.2KB

  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 "canvasline.h"
  18. #include <QtGui/QPainter>
  19. #include "canvasport.h"
  20. #include "canvasportglow.h"
  21. START_NAMESPACE_PATCHCANVAS
  22. CanvasLine::CanvasLine(CanvasPort* item1_, CanvasPort* item2_, QGraphicsItem* parent) :
  23. QGraphicsLineItem(parent, canvas.scene)
  24. {
  25. item1 = item1_;
  26. item2 = item2_;
  27. m_locked = false;
  28. m_lineSelected = false;
  29. setGraphicsEffect(0);
  30. updateLinePos();
  31. }
  32. CanvasLine::~CanvasLine()
  33. {
  34. setGraphicsEffect(0);
  35. }
  36. void CanvasLine::deleteFromScene()
  37. {
  38. canvas.scene->removeItem(this);
  39. delete this;
  40. }
  41. bool CanvasLine::isLocked() const
  42. {
  43. return m_locked;
  44. }
  45. void CanvasLine::setLocked(bool yesno)
  46. {
  47. m_locked = yesno;
  48. }
  49. bool CanvasLine::isLineSelected() const
  50. {
  51. return m_lineSelected;
  52. }
  53. void CanvasLine::setLineSelected(bool yesno)
  54. {
  55. if (m_locked)
  56. return;
  57. if (options.eyecandy == EYECANDY_FULL)
  58. {
  59. if (yesno)
  60. setGraphicsEffect(new CanvasPortGlow(item1->getPortType(), toGraphicsObject()));
  61. else
  62. setGraphicsEffect(0);
  63. }
  64. m_lineSelected = yesno;
  65. updateLineGradient();
  66. }
  67. void CanvasLine::updateLinePos()
  68. {
  69. if (item1->getPortMode() == PORT_MODE_OUTPUT)
  70. {
  71. QLineF line(item1->scenePos().x() + item1->getPortWidth()+12, item1->scenePos().y()+7.5, item2->scenePos().x(), item2->scenePos().y()+7.5);
  72. setLine(line);
  73. m_lineSelected = false;
  74. updateLineGradient();
  75. }
  76. }
  77. int CanvasLine::type() const
  78. {
  79. return CanvasLineType;
  80. }
  81. void CanvasLine::updateLineGradient()
  82. {
  83. short pos1, pos2;
  84. int pos_top = boundingRect().top();
  85. int pos_bot = boundingRect().bottom();
  86. if (item2->scenePos().y() >= item1->scenePos().y())
  87. {
  88. pos1 = 0;
  89. pos2 = 1;
  90. }
  91. else
  92. {
  93. pos1 = 1;
  94. pos2 = 0;
  95. }
  96. PortType port_type1 = item1->getPortType();
  97. PortType port_type2 = item2->getPortType();
  98. QLinearGradient port_gradient(0, pos_top, 0, pos_bot);
  99. if (port_type1 == PORT_TYPE_AUDIO_JACK)
  100. port_gradient.setColorAt(pos1, m_lineSelected ? canvas.theme->line_audio_jack_sel : canvas.theme->line_audio_jack);
  101. else if (port_type1 == PORT_TYPE_MIDI_JACK)
  102. port_gradient.setColorAt(pos1, m_lineSelected ? canvas.theme->line_midi_jack_sel : canvas.theme->line_midi_jack);
  103. else if (port_type1 == PORT_TYPE_MIDI_A2J)
  104. port_gradient.setColorAt(pos1, m_lineSelected ? canvas.theme->line_midi_a2j_sel : canvas.theme->line_midi_a2j);
  105. else if (port_type1 == PORT_TYPE_MIDI_ALSA)
  106. port_gradient.setColorAt(pos1, m_lineSelected ? canvas.theme->line_midi_alsa_sel : canvas.theme->line_midi_alsa);
  107. if (port_type2 == PORT_TYPE_AUDIO_JACK)
  108. port_gradient.setColorAt(pos2, m_lineSelected ? canvas.theme->line_audio_jack_sel : canvas.theme->line_audio_jack);
  109. else if (port_type2 == PORT_TYPE_MIDI_JACK)
  110. port_gradient.setColorAt(pos2, m_lineSelected ? canvas.theme->line_midi_jack_sel : canvas.theme->line_midi_jack);
  111. else if (port_type2 == PORT_TYPE_MIDI_A2J)
  112. port_gradient.setColorAt(pos2, m_lineSelected ? canvas.theme->line_midi_a2j_sel : canvas.theme->line_midi_a2j);
  113. else if (port_type2 == PORT_TYPE_MIDI_ALSA)
  114. port_gradient.setColorAt(pos2, m_lineSelected ? canvas.theme->line_midi_alsa_sel : canvas.theme->line_midi_alsa);
  115. setPen(QPen(port_gradient, 2));
  116. }
  117. void CanvasLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  118. {
  119. painter->setRenderHint(QPainter::Antialiasing, bool(options.antialiasing));
  120. QGraphicsLineItem::paint(painter, option, widget);
  121. }
  122. END_NAMESPACE_PATCHCANVAS