mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-11-22 14:33:02 -05:00
Comments editor: Add colors
This commit is contained in:
parent
cddf207277
commit
c235e3745c
BIN
resources/images/format-fill-color.png
Normal file
BIN
resources/images/format-fill-color.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
resources/images/format-text-color.png
Normal file
BIN
resources/images/format-text-color.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
@ -11,7 +11,7 @@ from lxml.html import soupparser
|
|||||||
|
|
||||||
from PyQt4.Qt import QApplication, QFontInfo, QSize, QWidget, QPlainTextEdit, \
|
from PyQt4.Qt import QApplication, QFontInfo, QSize, QWidget, QPlainTextEdit, \
|
||||||
QToolBar, QVBoxLayout, QAction, QIcon, QWebPage, Qt, QTabWidget, \
|
QToolBar, QVBoxLayout, QAction, QIcon, QWebPage, Qt, QTabWidget, \
|
||||||
QSyntaxHighlighter, QColor, QChar
|
QSyntaxHighlighter, QColor, QChar, QColorDialog
|
||||||
from PyQt4.QtWebKit import QWebView
|
from PyQt4.QtWebKit import QWebView
|
||||||
|
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
@ -90,9 +90,37 @@ class EditorWidget(QWebView): # {{{
|
|||||||
ac = PageAction(wac, icon, text, checkable, self)
|
ac = PageAction(wac, icon, text, checkable, self)
|
||||||
setattr(self, 'action_'+name, ac)
|
setattr(self, 'action_'+name, ac)
|
||||||
|
|
||||||
|
self.action_color = QAction(QIcon(I('format-text-color')), _('Foreground color'),
|
||||||
|
self)
|
||||||
|
self.action_color.triggered.connect(self.foreground_color)
|
||||||
|
|
||||||
|
self.action_background = QAction(QIcon(I('format-fill-color')),
|
||||||
|
_('Background color'), self)
|
||||||
|
self.action_background.triggered.connect(self.background_color)
|
||||||
|
|
||||||
|
def foreground_color(self):
|
||||||
|
col = QColorDialog.getColor(Qt.black, self,
|
||||||
|
_('Choose foreground color'), QColorDialog.ShowAlphaChannel)
|
||||||
|
if col.isValid():
|
||||||
|
self.exec_command('foreColor', unicode(col.name()))
|
||||||
|
|
||||||
|
def background_color(self):
|
||||||
|
col = QColorDialog.getColor(Qt.white, self,
|
||||||
|
_('Choose background color'), QColorDialog.ShowAlphaChannel)
|
||||||
|
if col.isValid():
|
||||||
|
self.exec_command('hiliteColor', unicode(col.name()))
|
||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
return QSize(150, 150)
|
return QSize(150, 150)
|
||||||
|
|
||||||
|
def exec_command(self, cmd, arg=None):
|
||||||
|
frame = self.page().mainFrame()
|
||||||
|
if arg is not None:
|
||||||
|
js = 'document.execCommand("%s", false, "%s");' % (cmd, arg)
|
||||||
|
else:
|
||||||
|
js = 'document.execCommand("%s", false, null);' % cmd
|
||||||
|
frame.evaluateJavaScript(js)
|
||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def html(self):
|
def html(self):
|
||||||
|
|
||||||
@ -404,6 +432,10 @@ class Editor(QWidget):
|
|||||||
self.toolbar1.addAction(ac)
|
self.toolbar1.addAction(ac)
|
||||||
self.toolbar1.addSeparator()
|
self.toolbar1.addSeparator()
|
||||||
|
|
||||||
|
self.toolbar1.addAction(self.editor.action_color)
|
||||||
|
self.toolbar1.addAction(self.editor.action_background)
|
||||||
|
self.toolbar1.addSeparator()
|
||||||
|
|
||||||
self.code_edit.textChanged.connect(self.code_dirtied)
|
self.code_edit.textChanged.connect(self.code_dirtied)
|
||||||
self.editor.page().contentsChanged.connect(self.wyswyg_dirtied)
|
self.editor.page().contentsChanged.connect(self.wyswyg_dirtied)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user