|
35 | 35 | QWhatsThisClickedEvent, QKeyEvent, QPalette |
36 | 36 | ) |
37 | 37 | from AnyQt.QtCore import ( |
38 | | - Qt, QObject, QEvent, QSignalMapper, QCoreApplication, QPointF, |
| 38 | + Qt, QObject, QEvent, QSignalMapper, QCoreApplication, QPointF, QRectF, |
39 | 39 | QMimeData, Slot) |
40 | 40 | from AnyQt.QtCore import pyqtProperty as Property, pyqtSignal as Signal |
41 | 41 |
|
|
51 | 51 | ) |
52 | 52 | from ..scheme import ( |
53 | 53 | scheme, signalmanager, Scheme, SchemeNode, SchemeLink, |
54 | | - BaseSchemeAnnotation, SchemeTextAnnotation, WorkflowEvent |
| 54 | + BaseSchemeAnnotation, SchemeTextAnnotation, WorkflowEvent, SchemeArrowAnnotation |
55 | 55 | ) |
56 | 56 | from ..scheme.widgetmanager import WidgetManager |
57 | 57 | from ..canvas.scene import CanvasScene |
@@ -224,6 +224,9 @@ def __init__(self, parent=None, ): |
224 | 224 | self.__editMenu.addAction(self.__copySelectedAction) |
225 | 225 | self.__editMenu.addAction(self.__pasteAction) |
226 | 226 | self.__editMenu.addAction(self.__selectAllAction) |
| 227 | + self.__editMenu.addSeparator() |
| 228 | + self.__editMenu.addAction(self.__newQuickTextAnnotationAction) |
| 229 | + self.__editMenu.addAction(self.__newQuickArrowAnnotationAction) |
227 | 230 |
|
228 | 231 | # Widget context menu |
229 | 232 | self.__widgetMenu = QMenu(self.tr("Widget"), self) |
@@ -293,6 +296,13 @@ def font(size): |
293 | 296 |
|
294 | 297 | self.__newTextAnnotationAction.setMenu(self.__fontMenu) |
295 | 298 |
|
| 299 | + self.__newQuickTextAnnotationAction = QAction( |
| 300 | + self.tr("Text Annotation"), self, |
| 301 | + objectName="new-quick-text-annotation-action", |
| 302 | + toolTip=self.tr("Add a text annotation to the workflow."), |
| 303 | + triggered=self.__triggerNewTextAnnotation |
| 304 | + ) |
| 305 | + |
296 | 306 | self.__newArrowAnnotationAction = QAction( |
297 | 307 | self.tr("Arrow"), self, |
298 | 308 | objectName="new-arrow-action", |
@@ -332,6 +342,13 @@ def color_icon(color): |
332 | 342 |
|
333 | 343 | self.__newArrowAnnotationAction.setMenu(self.__arrowColorMenu) |
334 | 344 |
|
| 345 | + self.__newQuickArrowAnnotationAction = QAction( |
| 346 | + self.tr("Arrow Annotation"), self, |
| 347 | + objectName="new-quick-arrow-annotation-action", |
| 348 | + toolTip=self.tr("Add a arrow annotation to the workflow."), |
| 349 | + triggered=self.__triggerNewArrowAnnotation, |
| 350 | + ) |
| 351 | + |
335 | 352 | self.__undoAction = self.__undoStack.createUndoAction(self) |
336 | 353 | self.__undoAction.setShortcut(QKeySequence.Undo) |
337 | 354 | self.__undoAction.setObjectName("undo-action") |
@@ -1959,6 +1976,38 @@ def __onArrowColorTriggered(self, action): |
1959 | 1976 | if isinstance(handler, interactions.NewArrowAnnotation): |
1960 | 1977 | handler.setColor(action.data()) |
1961 | 1978 |
|
| 1979 | + def __triggerNewTextAnnotation(self): |
| 1980 | + """Place a text annotation at the center of the view""" |
| 1981 | + center = self.view().viewport().rect().center() |
| 1982 | + center = self.view().mapToScene(center) |
| 1983 | + rect = QRectF(0, 0, 300, 150) |
| 1984 | + rect.moveCenter(center) |
| 1985 | + annotation = SchemeTextAnnotation( |
| 1986 | + (rect.x(), rect.y(), rect.width(), rect.height()), |
| 1987 | + content_type="text/markdown", |
| 1988 | + ) |
| 1989 | + self.addAnnotation(annotation) |
| 1990 | + # Give edit focus |
| 1991 | + item = self.scene().item_for_annotation(annotation) |
| 1992 | + item.setFocus(Qt.OtherFocusReason) |
| 1993 | + item.setSelected(True) |
| 1994 | + item.startEdit() |
| 1995 | + |
| 1996 | + def __triggerNewArrowAnnotation(self): |
| 1997 | + """Place an arrow annotation at the center of the view""" |
| 1998 | + center = self.view().viewport().rect().center() |
| 1999 | + center = self.view().mapToScene(center) |
| 2000 | + |
| 2001 | + annotation = SchemeArrowAnnotation( |
| 2002 | + (center.x() - 100, center.y()), (center.x() + 100, center.y()), |
| 2003 | + color=self.__arrowColorActionGroup.checkedAction().data() |
| 2004 | + ) |
| 2005 | + self.addAnnotation(annotation) |
| 2006 | + # Give edit focus |
| 2007 | + item = self.scene().item_for_annotation(annotation) |
| 2008 | + item.setFocus(Qt.OtherFocusReason) |
| 2009 | + item.setSelected(True) |
| 2010 | + |
1962 | 2011 | def __onRenameAction(self): |
1963 | 2012 | # type: () -> None |
1964 | 2013 | """ |
|
0 commit comments