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,
|
QKeySequence, QLabel, QLineEdit, QMenu, QPalette, QPlainTextEdit, QPushButton,
|
||||||
QSize, QSyntaxHighlighter, Qt, QTabWidget, QTextBlockFormat, QTextCharFormat,
|
QSize, QSyntaxHighlighter, Qt, QTabWidget, QTextBlockFormat, QTextCharFormat,
|
||||||
QTextCursor, QTextEdit, QTextFormat, QTextFrameFormat, QTextListFormat, QTimer,
|
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
|
from calibre import xml_replace_entities
|
||||||
@ -909,13 +909,28 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
c.deleteChar()
|
c.deleteChar()
|
||||||
c.insertImage(fmt.toImageFormat(), alignment)
|
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):
|
def contextMenuEvent(self, ev):
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
# unfortunately there appears to be no way to get the image under the
|
img_name = self.document().documentLayout().imageAt(QPointF(ev.pos()))
|
||||||
# mouse for floating images.
|
if img_name:
|
||||||
c = self.cursorForPosition(ev.pos())
|
pos = self.first_image_replacement_char_position_for(img_name)
|
||||||
fmt = c.charFormat()
|
if pos > -1:
|
||||||
if fmt.isImageFormat() and c.currentFrame():
|
c = self.textCursor()
|
||||||
|
c.clearSelection()
|
||||||
|
c.setPosition(pos)
|
||||||
cf = c.currentFrame().childFrames()
|
cf = c.currentFrame().childFrames()
|
||||||
pos = QTextFrameFormat.Position.InFlow
|
pos = QTextFrameFormat.Position.InFlow
|
||||||
if len(cf) == 1:
|
if len(cf) == 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user