mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
allow changing image alignment for floating images as well
This commit is contained in:
parent
0be966db4a
commit
9240af7d40
@ -895,6 +895,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
|
|
||||||
def align_image_at(self, cursor_pos, alignment):
|
def align_image_at(self, cursor_pos, alignment):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
|
c.clearSelection()
|
||||||
c.setPosition(cursor_pos)
|
c.setPosition(cursor_pos)
|
||||||
fmt = c.charFormat()
|
fmt = c.charFormat()
|
||||||
if fmt.isImageFormat() and c.currentFrame():
|
if fmt.isImageFormat() and c.currentFrame():
|
||||||
@ -904,13 +905,19 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
ff.setPosition(alignment)
|
ff.setPosition(alignment)
|
||||||
cf[0].setFrameFormat(ff)
|
cf[0].setFrameFormat(ff)
|
||||||
self.document().markContentsDirty(cursor_pos-2, 5)
|
self.document().markContentsDirty(cursor_pos-2, 5)
|
||||||
|
else:
|
||||||
|
c.deleteChar()
|
||||||
|
c.insertImage(fmt.toImageFormat(), alignment)
|
||||||
|
|
||||||
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
|
||||||
|
# mouse for floating images.
|
||||||
c = self.cursorForPosition(ev.pos())
|
c = self.cursorForPosition(ev.pos())
|
||||||
fmt = c.charFormat()
|
fmt = c.charFormat()
|
||||||
if fmt.isImageFormat() and c.currentFrame():
|
if fmt.isImageFormat() and c.currentFrame():
|
||||||
cf = c.currentFrame().childFrames()
|
cf = c.currentFrame().childFrames()
|
||||||
|
pos = QTextFrameFormat.Position.InFlow
|
||||||
if len(cf) == 1:
|
if len(cf) == 1:
|
||||||
pos = cf[0].frameFormat().position()
|
pos = cf[0].frameFormat().position()
|
||||||
align_menu = menu.addMenu(QIcon.ic('view-image.png'), _('Change image alignment...'))
|
align_menu = menu.addMenu(QIcon.ic('view-image.png'), _('Change image alignment...'))
|
||||||
@ -1353,5 +1360,6 @@ if __name__ == '__main__':
|
|||||||
set <u>out</u> to have an <em>affair</em>, <span style="font-style:italic; background-color:red">
|
set <u>out</u> to have an <em>affair</em>, <span style="font-style:italic; background-color:red">
|
||||||
much</span> less a <s>long-term</s>, <b>devoted</b> one.</span><p>hello'''
|
much</span> less a <s>long-term</s>, <b>devoted</b> one.</span><p>hello'''
|
||||||
w.html = '<div><p id="moo" align="justify">Testing <em>a</em> link.</p><p align="justify">\xa0</p><p align="justify">ss</p></div>'
|
w.html = '<div><p id="moo" align="justify">Testing <em>a</em> link.</p><p align="justify">\xa0</p><p align="justify">ss</p></div>'
|
||||||
|
w.html = '<p>Testing <img src="file:///home/kovid/work/calibre/resources/images/donate.png"> img</p>'
|
||||||
app.exec()
|
app.exec()
|
||||||
# print w.html
|
# print w.html
|
||||||
|
Loading…
x
Reference in New Issue
Block a user