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
18 #include "canvaslinemov.h"
19
20 #include <QtGui/QPainter>
21
22 #include "canvasport.h"
23
24 START_NAMESPACE_PATCHCANVAS
25
CanvasLineMov(PortMode port_mode,PortType port_type,QGraphicsItem * parent)26 CanvasLineMov::CanvasLineMov(PortMode port_mode, PortType port_type, QGraphicsItem* parent) :
27 QGraphicsLineItem(parent, canvas.scene)
28 {
29 m_port_mode = port_mode;
30 m_port_type = port_type;
31
32 // Port position doesn't change while moving around line
33 p_lineX = scenePos().x();
34 p_lineY = scenePos().y();
35 p_width = ((CanvasPort*)parentItem())->getPortWidth();
36
37 QPen pen;
38
39 if (port_type == PORT_TYPE_AUDIO_JACK)
40 pen = QPen(canvas.theme->line_audio_jack, 2);
41 else if (port_type == PORT_TYPE_MIDI_JACK)
42 pen = QPen(canvas.theme->line_midi_jack, 2);
43 else if (port_type == PORT_TYPE_MIDI_A2J)
44 pen = QPen(canvas.theme->line_midi_a2j, 2);
45 else if (port_type == PORT_TYPE_MIDI_ALSA)
46 pen = QPen(canvas.theme->line_midi_alsa, 2);
47 else
48 {
49 qWarning("PatchCanvas::CanvasLineMov(%s, %s, %p) - invalid port type", port_mode2str(port_mode), port_type2str(port_type), parent);
50 pen = QPen(Qt::black);
51 }
52
53 setPen(pen);
54 }
55
deleteFromScene()56 void CanvasLineMov::deleteFromScene()
57 {
58 canvas.scene->removeItem(this);
59 delete this;
60 }
61
updateLinePos(QPointF scenePos)62 void CanvasLineMov::updateLinePos(QPointF scenePos)
63 {
64 int item_pos[2] = { 0, 0 };
65
66 if (m_port_mode == PORT_MODE_INPUT)
67 {
68 item_pos[0] = 0;
69 item_pos[1] = 7.5;
70 }
71 else if (m_port_mode == PORT_MODE_OUTPUT)
72 {
73 item_pos[0] = p_width+12;
74 item_pos[1] = 7.5;
75 }
76 else
77 return;
78
79 QLineF line(item_pos[0], item_pos[1], scenePos.x()-p_lineX, scenePos.y()-p_lineY);
80 setLine(line);
81 }
82
type() const83 int CanvasLineMov::type() const
84 {
85 return CanvasLineMovType;
86 }
87
paint(QPainter * painter,const QStyleOptionGraphicsItem * option,QWidget * widget)88 void CanvasLineMov::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
89 {
90 painter->setRenderHint(QPainter::Antialiasing, bool(options.antialiasing));
91 QGraphicsLineItem::paint(painter, option, widget);
92 }
93
94 END_NAMESPACE_PATCHCANVAS
95