# Path: qutepart/htmldelegate.py
# class HTMLDelegate(QStyledItemDelegate):
#     """QStyledItemDelegate implementation. Draws HTML
# 
#     http://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt/1956781#1956781
#     """
# 
#     def paint(self, painter, option, index):
#         """QStyledItemDelegate.paint implementation
#         """
#         option.state &= ~QStyle.State_HasFocus  # never draw focus rect
# 
#         options = QStyleOptionViewItem(option)
#         self.initStyleOption(options,index)
# 
#         style = QApplication.style() if options.widget is None else options.widget.style()
# 
#         doc = QTextDocument()
#         doc.setDocumentMargin(1)
#         doc.setHtml(options.text)
#         if options.widget is not None:
#             doc.setDefaultFont(options.widget.font())
#         #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
# 
#         options.text = ""
#         style.drawControl(QStyle.CE_ItemViewItem, options, painter);
# 
#         ctx = QAbstractTextDocumentLayout.PaintContext()
# 
#         # Highlighting text if item is selected
#         if option.state & QStyle.State_Selected:
#             ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))
# 
#         textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
#         painter.save()
#         painter.translate(textRect.topLeft())
#         """Original example contained line
#             painter.setClipRect(textRect.translated(-textRect.topLeft()))
#         but text is drawn clipped with it on kubuntu 12.04
#         """
#         doc.documentLayout().draw(painter, ctx)
# 
#         painter.restore()
# 
#     def sizeHint(self, option, index):
#         """QStyledItemDelegate.sizeHint implementation
#         """
#         options = QStyleOptionViewItem(option)
#         self.initStyleOption(options,index)
# 
#         doc = QTextDocument()
#         doc.setDocumentMargin(1)
#         #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
#         doc.setHtml(options.text)
#         return QSize(int(doc.idealWidth()),
#                      int(QStyledItemDelegate.sizeHint(self, option, index).height()))


import re
import time
from PyQt5.QtCore import pyqtSignal, QAbstractItemModel, QEvent, QModelIndex, QObject, QSize, Qt, QTimer
from PyQt5.QtWidgets import QListView
from PyQt5.QtGui import QCursor
from qutepart.htmldelegate import HTMLDelegate
        return sorted(onlySuitable)

    """Trivial QAbstractItemModel methods implementation
    """
    def flags(self, index):                                 return Qt.ItemIsEnabled | Qt.ItemIsSelectable
    def headerData(self, index):                            return None
    def columnCount(self, index):                           return 1
    def index(self, row, column, parent = QModelIndex()):   return self.createIndex(row, column)
    def parent(self, index):                                return QModelIndex()


class _CompletionList(QListView):
    """Completion list widget
    """
    closeMe = pyqtSignal()
    itemSelected = pyqtSignal(int)
    tabPressed = pyqtSignal()

    _MAX_VISIBLE_ROWS = 20  # no any technical reason, just for better UI

    def __init__(self, qpart, model):
        QListView.__init__(self, qpart.viewport())

        # ensure good selected item background on Windows
        palette = self.palette()
        palette.setColor(palette.Inactive, palette.Highlight, palette.color(palette.Active, palette.Highlight))
        self.setPalette(palette)

        self.setAttribute(Qt.WA_DeleteOnClose)


# Path: qutepart/htmldelegate.py
# class HTMLDelegate(QStyledItemDelegate):
#     """QStyledItemDelegate implementation. Draws HTML
# 
#     http://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt/1956781#1956781
#     """
# 
#     def paint(self, painter, option, index):
#         """QStyledItemDelegate.paint implementation
#         """
#         option.state &= ~QStyle.State_HasFocus  # never draw focus rect
# 
#         options = QStyleOptionViewItem(option)
#         self.initStyleOption(options,index)
# 
#         style = QApplication.style() if options.widget is None else options.widget.style()
# 
#         doc = QTextDocument()
#         doc.setDocumentMargin(1)
#         doc.setHtml(options.text)
#         if options.widget is not None:
#             doc.setDefaultFont(options.widget.font())
#         #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
# 
#         options.text = ""
#         style.drawControl(QStyle.CE_ItemViewItem, options, painter);
# 
#         ctx = QAbstractTextDocumentLayout.PaintContext()
# 
#         # Highlighting text if item is selected
#         if option.state & QStyle.State_Selected:
#             ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))
# 
#         textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
#         painter.save()
#         painter.translate(textRect.topLeft())
#         """Original example contained line
#             painter.setClipRect(textRect.translated(-textRect.topLeft()))
#         but text is drawn clipped with it on kubuntu 12.04
#         """
#         doc.documentLayout().draw(painter, ctx)
# 
#         painter.restore()
# 
#     def sizeHint(self, option, index):
#         """QStyledItemDelegate.sizeHint implementation
#         """
#         options = QStyleOptionViewItem(option)
#         self.initStyleOption(options,index)
# 
#         doc = QTextDocument()
#         doc.setDocumentMargin(1)
#         #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
#         doc.setHtml(options.text)
#         return QSize(int(doc.idealWidth()),
#                      int(QStyledItemDelegate.sizeHint(self, option, index).height()))


# Path: qutepart/completer.py
import re
import time
from PyQt5.QtCore import pyqtSignal, QAbstractItemModel, QEvent, QModelIndex, QObject, QSize, Qt, QTimer
from PyQt5.QtWidgets import QListView
from PyQt5.QtGui import QCursor
from qutepart.htmldelegate import HTMLDelegate

        return sorted(onlySuitable)

    """Trivial QAbstractItemModel methods implementation
    """
    def flags(self, index):                                 return Qt.ItemIsEnabled | Qt.ItemIsSelectable
    def headerData(self, index):                            return None
    def columnCount(self, index):                           return 1
    def index(self, row, column, parent = QModelIndex()):   return self.createIndex(row, column)
    def parent(self, index):                                return QModelIndex()


class _CompletionList(QListView):
    """Completion list widget
    """
    closeMe = pyqtSignal()
    itemSelected = pyqtSignal(int)
    tabPressed = pyqtSignal()

    _MAX_VISIBLE_ROWS = 20  # no any technical reason, just for better UI

    def __init__(self, qpart, model):
        QListView.__init__(self, qpart.viewport())

        # ensure good selected item background on Windows
        palette = self.palette()
        palette.setColor(palette.Inactive, palette.Highlight, palette.color(palette.Active, palette.Highlight))
        self.setPalette(palette)

        self.setAttribute(Qt.WA_DeleteOnClose)


        self.setItemDelegate(HTMLDelegate(self))