mirror of https://gitee.com/cxasm/notepad--.git
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
|
#include "ndstyleditemdelegate.h"
|
|||
|
#include <QTextDocument>
|
|||
|
#include <QApplication>
|
|||
|
#include <QAbstractTextDocumentLayout>
|
|||
|
#include <QPainter>
|
|||
|
#include <QTextEdit>
|
|||
|
|
|||
|
NdStyledItemDelegate::NdStyledItemDelegate(QObject *parent)
|
|||
|
: QStyledItemDelegate(parent)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
NdStyledItemDelegate::~NdStyledItemDelegate()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>֧<EFBFBD>ָ<EFBFBD><D6B8>ı<EFBFBD><C4B1><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void NdStyledItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
|||
|
{
|
|||
|
QStyleOptionViewItem viewOption(option);
|
|||
|
initStyleOption(&viewOption, index);
|
|||
|
if (option.state.testFlag(QStyle::State_HasFocus))
|
|||
|
viewOption.state = viewOption.state ^ QStyle::State_HasFocus;
|
|||
|
|
|||
|
// ... ʡ<><CAA1>
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ı<EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>ʹ<EFBFBD><CAB9>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>ʽ
|
|||
|
QStyle *pStyle = viewOption.widget ? viewOption.widget->style() : QApplication::style();
|
|||
|
|
|||
|
QTextDocument doc;
|
|||
|
doc.setHtml(viewOption.text);
|
|||
|
|
|||
|
viewOption.text.clear();
|
|||
|
|
|||
|
pStyle->drawControl(QStyle::CE_ItemViewItem, &viewOption, painter, viewOption.widget);
|
|||
|
|
|||
|
QAbstractTextDocumentLayout::PaintContext paintContext;
|
|||
|
|
|||
|
QRect textRect = pStyle->subElementRect(QStyle::SE_ItemViewItemText, &viewOption);
|
|||
|
painter->save();
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD>Ϊԭ<CEAA><D4AD>
|
|||
|
painter->translate(textRect.topLeft());
|
|||
|
// <20><><EFBFBD><EFBFBD>HTML<4D><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
|||
|
|
|||
|
doc.documentLayout()->draw(painter, paintContext);
|
|||
|
|
|||
|
painter->restore();
|
|||
|
}
|