From c049cdfe8dba50dad5b30a4d41e7687fbb1b0566 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 28 Nov 2014 12:04:15 +0530 Subject: [PATCH] Fix #1397183 [Stand Alone Comments - Editor OK button & cell highlight](https://bugs.launchpad.net/calibre/+bug/1397183) --- src/calibre/gui2/dialogs/comments_dialog.py | 10 ++++++++-- src/calibre/gui2/library/delegates.py | 18 ++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/dialogs/comments_dialog.py b/src/calibre/gui2/dialogs/comments_dialog.py index 30c096262b..c262b33ff7 100644 --- a/src/calibre/gui2/dialogs/comments_dialog.py +++ b/src/calibre/gui2/dialogs/comments_dialog.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' from PyQt5.Qt import Qt, QDialog, QDialogButtonBox -from calibre.gui2 import gprefs +from calibre.gui2 import gprefs, Application from calibre.gui2.dialogs.comments_dialog_ui import Ui_CommentsDialog from calibre.library.comments import comments_to_html @@ -23,7 +23,7 @@ class CommentsDialog(QDialog, Ui_CommentsDialog): self.textbox.html = comments_to_html(text) if text else '' self.textbox.wyswyg_dirtied() # self.textbox.setTabChangesFocus(True) - self.buttonBox.button(QDialogButtonBox.Ok).setText(_('&OK')) + self.buttonBox.button(QDialogButtonBox.Ok).setText(_('O&K')) self.buttonBox.button(QDialogButtonBox.Cancel).setText(_('&Cancel')) if column_name: @@ -48,3 +48,9 @@ class CommentsDialog(QDialog, Ui_CommentsDialog): self.save_geometry() return QDialog.closeEvent(self, ev) +if __name__ == '__main__': + app = Application([]) + d = CommentsDialog(None, 'testing', 'Comments') + d.exec_() + del d + del app diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 385f0e2d4e..f137e5ed99 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -416,17 +416,15 @@ class CcCommentsDelegate(QStyledItemDelegate): # {{{ else option.widget.style() self.document.setHtml(option.text) option.text = u'' - if hasattr(QStyle, 'CE_ItemViewItem'): - style.drawControl(QStyle.CE_ItemViewItem, option, painter) + style.drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter, widget=option.widget) ctx = QAbstractTextDocumentLayout.PaintContext() - ctx.palette = option.palette # .setColor(QPalette.Text, QColor("red")); - if hasattr(QStyle, 'SE_ItemViewItemText'): - textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option) - painter.save() - painter.translate(textRect.topLeft()) - painter.setClipRect(textRect.translated(-textRect.topLeft())) - self.document.documentLayout().draw(painter, ctx) - painter.restore() + ctx.palette = option.palette + textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option) + painter.save() + painter.translate(textRect.topLeft()) + painter.setClipRect(textRect.translated(-textRect.topLeft())) + self.document.documentLayout().draw(painter, ctx) + painter.restore() def createEditor(self, parent, option, index): m = index.model()