def __init__(self, details, drop2Details, session): scene = MyScene(details, drop2Details, session) QtGui.QGraphicsView.__init__(self, scene) for hint in [QtGui.QPainter.Antialiasing, QtGui.QPainter.TextAntialiasing]: self.setRenderHint(hint) self.setAcceptDrops(True) #self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) #a = QtGui.QAction('Nieuw Blok', self) #self.addAction(a) #a.triggered.connect(self.onAddBlock) # TODO: Implement copy to use case self.menu_noitem = mkMenu([('New Block', self.onAddBlock), ('New Use Case', lambda triggered : self.onAddBlock(triggered, details, True)), ('New Annotation', self.onAddAnnotation), ('Copieer naar Nieuw View', self.onCopyToUseCase), ('Export as PNG', self.exportPng), ('Export as SVG', self.exportSvg)], self) up = lambda _:self.onChangeItemOrder(self.MOVE_UP) down = lambda _:self.onChangeItemOrder(self.MOVE_DOWN) top = lambda _:self.onChangeItemOrder(self.MOVE_TOP) bottom = lambda _:self.onChangeItemOrder(self.MOVE_BOTTOM) self.standard_menu_def = [('Move Up', up), ('Move Down', down), ('Move Top', top), ('Move Bottom', bottom), ('---', None), ('Delete', self.onDeleteItem)] self.scene = scene self.details = details self.last_rmouse_click = None self.session = session self.scene.selectionChanged.connect(self.onSelectionChanged) self.selection_order = []
def menuFactory(self, view): ''' Factory function for creating a right-click menu. :param view: The view where the right-click menu is requested. :return: An instance of QtGui.QMenu ''' details = self.details return mkMenu(view.standard_menu_def, view)
def contextMenuEvent(self, ev): index = self.indexAt(ev.pos()) if index.isValid(): actions = self.item_actions + [('---', None)] + self.std_actions else: actions = self.std_actions menu = mkMenu(actions, self.session_parent) menu.exec_(self.mapToGlobal(ev.pos()))
def menuFactory(self, view): ''' Factory function for creating a right-click menu. :param view: The view where the right-click menu is requested. :return: An instance of QtGui.QMenu ''' details = self.block_details def bind(n): ''' Utility: bind a menu action trigger to the right function ''' return lambda: view.addExistingAction(n, details.Id) definition = list(view.standard_menu_def) # Add the dynamic menu items nr_items = len(view.scene.selectedItems()) if nr_items in [0, 1]: definition += [('Create New Child Block', view.onAddChildBlock), ('New Action', view.onNewAction), ('---', None)] for fp in details.FunctionPoints: definition.append((fp.Name, bind(fp.Id))) if nr_items == 2: definition = [('Connect blocks', view.onConnect)] return mkMenu(definition, view)
def mkMenu(*args): return mkMenu(*args)