mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Better handling of image alignment change on right click
This commit is contained in:
parent
9240af7d40
commit
705c174271
@ -16,7 +16,7 @@ from qt.core import (
|
||||
QKeySequence, QLabel, QLineEdit, QMenu, QPalette, QPlainTextEdit, QPushButton,
|
||||
QSize, QSyntaxHighlighter, Qt, QTabWidget, QTextBlockFormat, QTextCharFormat,
|
||||
QTextCursor, QTextEdit, QTextFormat, QTextFrameFormat, QTextListFormat, QTimer,
|
||||
QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal, pyqtSlot,
|
||||
QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal, pyqtSlot, QPointF, QTextDocument
|
||||
)
|
||||
|
||||
from calibre import xml_replace_entities
|
||||
@ -909,13 +909,28 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
||||
c.deleteChar()
|
||||
c.insertImage(fmt.toImageFormat(), alignment)
|
||||
|
||||
def first_image_replacement_char_position_for(self, image_name):
|
||||
d = self.document()
|
||||
c = self.textCursor()
|
||||
c.setPosition(0)
|
||||
while True:
|
||||
c = d.find('\ufffc', c, QTextDocument.FindFlag.FindCaseSensitively)
|
||||
if c.isNull():
|
||||
break
|
||||
fmt = c.charFormat()
|
||||
if fmt.isImageFormat() and fmt.toImageFormat().name() == image_name:
|
||||
return c.position()
|
||||
return -1
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
menu = QMenu(self)
|
||||
# unfortunately there appears to be no way to get the image under the
|
||||
# mouse for floating images.
|
||||
c = self.cursorForPosition(ev.pos())
|
||||
fmt = c.charFormat()
|
||||
if fmt.isImageFormat() and c.currentFrame():
|
||||
img_name = self.document().documentLayout().imageAt(QPointF(ev.pos()))
|
||||
if img_name:
|
||||
pos = self.first_image_replacement_char_position_for(img_name)
|
||||
if pos > -1:
|
||||
c = self.textCursor()
|
||||
c.clearSelection()
|
||||
c.setPosition(pos)
|
||||
cf = c.currentFrame().childFrames()
|
||||
pos = QTextFrameFormat.Position.InFlow
|
||||
if len(cf) == 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user