2 #include <QFramedTextAttribute> 3 #include <QSyntaxStyle> 6 #include <QFontMetrics> 13 return QTextFormat::UserFormat + 1;
45 auto textCharFormat =
reinterpret_cast<const QTextCharFormat&
>(
format);
48 auto font = textCharFormat.font();
49 QFontMetrics metrics(font);
53 auto stringSize = metrics.boundingRect(
string).size();
56 QRectF drawRect(rect.topLeft(), stringSize);
57 drawRect.moveTop(rect.top() - stringSize.height());
58 drawRect.adjust(0, 4, 0, 4);
62 painter->setRenderHint(QPainter::Antialiasing);
63 painter->drawRoundedRect(drawRect, 4, 4);
68 auto text = cursor.document()->findBlockByNumber(cursor.blockNumber()).text();
71 format.setObjectType(
type());
74 if (cursor.selectionEnd() > cursor.selectionStart())
76 cursor.setPosition(cursor.selectionStart());
80 cursor.setPosition(cursor.selectionEnd());
84 QString(QChar::ObjectReplacementCharacter),
91 auto doc = cursor.document();
93 for (
auto blockIndex = 0;
94 blockIndex < doc->blockCount();
97 auto block = doc->findBlockByNumber(blockIndex);
99 auto formats =
block.textFormats();
102 for (
auto&
format : formats)
106 cursor.setPosition(
block.position() +
format.start - offset);
void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) override
Method for drawing frame.
QFramedTextAttribute(QObject *parent=nullptr)
Constructor.
void frame(QTextCursor cursor)
Method for creating frame in cursor selection.
QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override
Method for getting custom element (frame) size. Though frame symbol has no size, this method returns ...
static int type()
Static method for getting framed text attribute type.
static void block(LexState *ls)
Class, that describes Qt style parser for QCodeEditor.
QTextCharFormat getFormat(QString name) const
Method for getting format for property name.
void clear(QTextCursor cursor)
Method for clearing all frames with desired cursor.
QSyntaxStyle * syntaxStyle() const
Method for getting syntax style.
void setSyntaxStyle(QSyntaxStyle *style)
Method for setting syntax style for rendering.
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)