mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
allow copy context item in info view
This commit is contained in:
parent
5044089d42
commit
9f6b073def
2 changed files with 8 additions and 9 deletions
|
@ -861,7 +861,7 @@ by clicking on one on the left."""))
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
l = QVBoxLayout()
|
l = QVBoxLayout()
|
||||||
l.setMargin(0)
|
l.setMargin(0)
|
||||||
w = AnkiWebView()
|
w = AnkiWebView(canCopy=True)
|
||||||
l.addWidget(w)
|
l.addWidget(w)
|
||||||
w.stdHtml(info + "<p>" + reps)
|
w.stdHtml(info + "<p>" + reps)
|
||||||
bb = QDialogButtonBox(QDialogButtonBox.Close)
|
bb = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
|
|
|
@ -40,7 +40,8 @@ class AnkiWebPage(QWebPage):
|
||||||
|
|
||||||
class AnkiWebView(QWebView):
|
class AnkiWebView(QWebView):
|
||||||
|
|
||||||
def __init__(self, canFocus=False):
|
# canFocus implies canCopy
|
||||||
|
def __init__(self, canFocus=False, canCopy=False):
|
||||||
QWebView.__init__(self)
|
QWebView.__init__(self)
|
||||||
self.setRenderHints(
|
self.setRenderHints(
|
||||||
QPainter.TextAntialiasing |
|
QPainter.TextAntialiasing |
|
||||||
|
@ -60,6 +61,7 @@ class AnkiWebView(QWebView):
|
||||||
# reset each time new html is set; used to detect if still in same state
|
# reset each time new html is set; used to detect if still in same state
|
||||||
self.key = None
|
self.key = None
|
||||||
self.setCanFocus(canFocus)
|
self.setCanFocus(canFocus)
|
||||||
|
self._canCopy = canCopy or canFocus
|
||||||
|
|
||||||
def keyPressEvent(self, evt):
|
def keyPressEvent(self, evt):
|
||||||
if evt.matches(QKeySequence.Copy):
|
if evt.matches(QKeySequence.Copy):
|
||||||
|
@ -79,7 +81,7 @@ class AnkiWebView(QWebView):
|
||||||
QWebView.keyReleaseEvent(self, evt)
|
QWebView.keyReleaseEvent(self, evt)
|
||||||
|
|
||||||
def contextMenuEvent(self, evt):
|
def contextMenuEvent(self, evt):
|
||||||
if not self.isCardViewer:
|
if not self._canCopy:
|
||||||
return
|
return
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
a = m.addAction(_("Copy"))
|
a = m.addAction(_("Copy"))
|
||||||
|
@ -130,12 +132,9 @@ button {
|
||||||
def setBridge(self, bridge):
|
def setBridge(self, bridge):
|
||||||
self._bridge.setBridge(bridge)
|
self._bridge.setBridge(bridge)
|
||||||
|
|
||||||
def setCanFocus(self, isCardViewer=False):
|
def setCanFocus(self, canFocus=False):
|
||||||
"""Set flag to denote if this WebView should follow rules specific to
|
self._canFocus = canFocus
|
||||||
card display (e.g., allow context menu, copy/paste)"""
|
if self._canFocus:
|
||||||
|
|
||||||
self.isCardViewer = isCardViewer
|
|
||||||
if self.isCardViewer:
|
|
||||||
self.setFocusPolicy(Qt.WheelFocus)
|
self.setFocusPolicy(Qt.WheelFocus)
|
||||||
else:
|
else:
|
||||||
self.setFocusPolicy(Qt.NoFocus)
|
self.setFocusPolicy(Qt.NoFocus)
|
||||||
|
|
Loading…
Reference in a new issue