Skip to content
Snippets Groups Projects
arrow.py 1.51 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jacob Wahlman's avatar
    Jacob Wahlman committed
    from PySide2.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,\
    
    QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\
    QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget, QListWidgetItem,\
    QGraphicsLineItem, QGraphicsWidget
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
    from PySide2.QtCore import Qt, QSize, QLineF, QPoint, QRectF
    from PySide2.QtGui import QIcon, QFont, QPainter, QPen
    
    from b_asic import Signal
    
    
    class Arrow(QGraphicsLineItem):
    
        def __init__(self, source, destination, window, parent=None):
            super(Arrow, self).__init__(parent)
            self.source = source
    
            self.signal = Signal(source.port, destination.port)
    
            self.destination = destination
            self._window = window
            self.moveLine()
            self.source.moved.connect(self.moveLine)
            self.destination.moved.connect(self.moveLine)
    
        def contextMenuEvent(self, event):
            menu = QMenu()
            menu.addAction("Delete", self.remove)
            menu.exec_(self.cursor().pos())
    
        def remove(self):
    
            self.signal.remove_destination()
            self.signal.remove_source()
    
            self._window.scene.removeItem(self)
            self._window.signalList.remove(self)
    
        def moveLine(self):
            self.setPen(QPen(Qt.black, 3))
    
            self.setLine(QLineF(self.source.operation.x()+self.source.x()+14,\
                 self.source.operation.y()+self.source.y()+7.5,\
                 self.destination.operation.x()+self.destination.x(),\
                 self.destination.operation.y()+self.destination.y()+7.5))