Skip to content

Commit

Permalink
canvas/annotations: Change context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Jun 22, 2017
1 parent b188589 commit ef62ee4
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions Orange/canvas/canvas/items/annotationitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from AnyQt.QtWidgets import (
QGraphicsItem, QGraphicsPathItem, QGraphicsWidget, QGraphicsTextItem,
QGraphicsDropShadowEffect, QMenu
QGraphicsDropShadowEffect, QMenu, QAction, QActionGroup
)
from AnyQt.QtGui import (
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen
Expand Down Expand Up @@ -496,20 +496,41 @@ def contextMenuEvent(self, event):
if event.modifiers() & Qt.AltModifier:
menu = QMenu(event.widget())
menu.setAttribute(Qt.WA_DeleteOnClose)
formatmenu = menu.addMenu("Render as")
group = QActionGroup(self, exclusive=True)

def makeaction(text, parent, data=None, **kwargs):
action = QAction(text, parent, **kwargs)
if data is not None:
action.setData(data)
return action

formatactions = [
makeaction("Plain Text", group, checkable=True,
toolTip=self.tr("Render contents as plain text"),
data="text/plain"),
makeaction("HTML", group, checkable=True,
toolTip=self.tr("Render contents as HTML"),
data="text/html"),
makeaction("RST", group, checkable=True,
toolTip=self.tr("Render contents as RST "
"(reStructuredText)"),
data="text/rst"),
makeaction("Markdown", group, checkable=True,
toolTip=self.tr("Render contents as Markdown"),
data="text/markdown")
]
for action in formatactions:
action.setChecked(action.data() == self.__contentType.lower())
formatmenu.addAction(action)

menu.addAction("text/plain")
menu.addAction("text/markdown")
menu.addAction("text/rst")
menu.addAction("text/html")

for action in menu.actions():
action.setCheckable(True)
action.setChecked(action.text() == self.__contentType.lower())

@menu.triggered.connect
def ontriggered(action):
self.setContent(self.content(), action.text())
mimetype = action.data()
content = self.content()
self.setContent(content, mimetype)
self.editingFinished.emit()

menu.triggered.connect(ontriggered)
menu.popup(event.screenPos())
event.accept()
else:
Expand Down

0 comments on commit ef62ee4

Please sign in to comment.