| 1 | // QCodeEditorcxx . . $ `<file>/src/internal/QFramedTextAttribute.cpp`/ |
| 2 | #include <QFramedTextAttribute>cxx . . $ `<file>/include/QFramedTextAttribute`/ |
| 3 | #include <QSyntaxStyle>cxx . . $ `<file>/include/QSyntaxStyle`/ |
| 4 | |
| 5 | // Qt |
| 6 | #include <QFontMetrics> |
| 7 | #include <QPainter> |
| 8 | #include <QDebug> |
| 9 | #include <QTextBlock> |
| 10 | |
| 11 | int QFramedTextAttributecxx . . $ QFramedTextAttribute#::typecxx . . $ QFramedTextAttribute#type(b126dc7c1de90089).() |
| 12 | { |
| 13 | return QTextFormatcxx . . $ QTextFormat#::UserFormatcxx . . $ QTextFormat#UserFormat. + 1; |
| 14 | } |
| 15 | |
| 16 | QFramedTextAttributecxx . . $ QFramedTextAttribute#::QFramedTextAttributecxx . . $ QFramedTextAttribute#QFramedTextAttribute(749de1b6ae65bddd).(QObjectcxx . . $ QObject#* parent) : |
| 17 | QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), |
| 18 | m_stylecxx . . $ QFramedTextAttribute#m_style.(nullptr) |
| 19 | { |
| 20 | |
| 21 | } |
| 22 | |
| 23 | void QFramedTextAttributecxx . . $ QFramedTextAttribute#::setSyntaxStylecxx . . $ QFramedTextAttribute#setSyntaxStyle(1fc7b27a9b6cc29c).(QSyntaxStylecxx . . $ QSyntaxStyle#* style) |
| 24 | { |
| 25 | m_stylecxx . . $ QFramedTextAttribute#m_style. = style; |
| 26 | } |
| 27 | |
| 28 | QSyntaxStylecxx . . $ QSyntaxStyle#* QFramedTextAttributecxx . . $ QFramedTextAttribute#::syntaxStylecxx . . $ QFramedTextAttribute#syntaxStyle(8b4bb56ba20b4a4a).() const |
| 29 | { |
| 30 | return m_stylecxx . . $ QFramedTextAttribute#m_style.; |
| 31 | } |
| 32 | |
| 33 | QSizeFcxx . . $ QSizeF# QFramedTextAttributecxx . . $ QFramedTextAttribute#::intrinsicSizecxx . . $ QFramedTextAttribute#intrinsicSize(45bb4137873cd2e0).(QTextDocumentcxx . . $ QTextDocument#*, int, const QTextFormatcxx . . $ QTextFormat#&) |
| 34 | { |
| 35 | return {cxx . . $ QSizeF#QSizeF(bc12c9ec15586e6a).0, 0}; |
| 36 | } |
| 37 | |
| 38 | void QFramedTextAttributecxx . . $ QFramedTextAttribute#::drawObjectcxx . . $ QFramedTextAttribute#drawObject(b64e36186978ada4).(QPaintercxx . . $ QPainter#* painter, |
| 39 | const QRectFcxx . . $ QRectF#& rect, |
| 40 | QTextDocumentcxx . . $ QTextDocument#*, |
| 41 | int, |
| 42 | const QTextFormatcxx . . $ QTextFormat#& format) |
| 43 | { |
| 44 | // Casting |
| 45 | auto textCharFormat = reinterpret_cast<const QTextCharFormatcxx . . $ QTextCharFormat#&>(format); |
| 46 | |
| 47 | // Getting font data |
| 48 | auto font = textCharFormatcxx . . $ QFont#QFont(d0a4bd0c8524b912)..fontcxx . . $ QTextCharFormat#font(9958934e48c66a6a).(); |
| 49 | QFontMetricscxx . . $ QFontMetrics# metricscxx . . $ QFontMetrics#QFontMetrics(d0a4bd0c8524b912).(font); |
| 50 | |
| 51 | // Getting required size |
| 52 | auto string = formatcxx . . $ QString#QString(e1217c004a86c950)..propertycxx . . $ QTextFormat#property(fb36142a814bbf95).(FramedStringcxx . . $ QFramedTextAttribute#FramedString.).toStringcxx . . $ QVariant#toString(6ef7b6c27b00b43d).(); |
| 53 | auto stringSize = metrics.boundingRectcxx . . $ QFontMetrics#boundingRect(d8b0a2d97d69e4b8).(string).sizecxx . . $ QRect#size(4b3b776e5ee2b367).(); |
| 54 | |
| 55 | // Creating frame rect |
| 56 | QRectFcxx . . $ QRectF# drawRectcxx . . $ QRectF#QRectF(51e855f46410d443).(rect.topLeftcxx . . $ QRectF#topLeft(a5b3784bf6777acb).(), stringSizecxx . . $ QSizeF#QSizeF(1c5f201b4c2f0aba).); |
| 57 | drawRect.moveTopcxx . . $ QRectF#moveTop(ba8836b59fb42830).(rect.topcxx . . $ QRectF#top(21b6c25e127938e2).() - stringSize.heightcxx . . $ QSize#height(455f465bc33b4cdf).()); |
| 58 | drawRect.adjustcxx . . $ QRectF#adjust(52a61fa14d44b641).(0, 4, 0, 4); |
| 59 | |
| 60 | // Drawing |
| 61 | painter->setPencxx . . $ QPainter#setPen(129a55e114526ad3).(m_stylecxx . . $ QFramedTextAttribute#m_style.->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Occurrences"cxx . . $ QString#QString(e1217c004a86c950).).backgroundcxx . . $ QTextFormat#background(583354ac483a5b23).().colorcxx . . $ QBrush#color(a1044652a6e0ddd).()); |
| 62 | painter->setRenderHintcxx . . $ QPainter#setRenderHint(df747a77a7bbbce1).(QPaintercxx . . $ QPainter#::Antialiasingcxx . . $ QPainter#Antialiasing.); |
| 63 | painter->drawRoundedRectcxx . . $ QPainter#drawRoundedRect(4097802b0bac5cc0).(drawRect, 4, 4); |
| 64 | } |
| 65 | |
| 66 | void QFramedTextAttributecxx . . $ QFramedTextAttribute#::framecxx . . $ QFramedTextAttribute#frame(2dee62e7021fdd8c).(QTextCursorcxx . . $ QTextCursor# cursor) |
| 67 | { |
| 68 | auto text = cursorcxx . . $ QString#QString(e1217c004a86c950)..documentcxx . . $ QTextCursor#document(f21741221844491e).()->findBlockByNumbercxx . . $ QTextDocument#findBlockByNumber(c1425046715037b8).(cursor.blockNumbercxx . . $ QTextCursor#blockNumber(455f465bc33b4cdf).()).textcxx . . $ QTextBlock#text(6ef7b6c27b00b43d).(); |
| 69 | |
| 70 | QTextCharFormatcxx . . $ QTextCharFormat# formatcxx . . $ QTextCharFormat#QTextCharFormat(49f6e7a06ebc5aa8).; |
| 71 | format.setObjectTypecxx . . $ QTextFormat#setObjectType(d4f767463ce0a6b3).(typecxx . . $ QFramedTextAttribute#type(b126dc7c1de90089).()); |
| 72 | format.setPropertycxx . . $ QTextFormat#setProperty(e71f85060bf8a055).(FramedStringcxx . . $ QFramedTextAttribute#FramedString., cursorcxx . . $ QVariant#QVariant(3520e46b33348bf6)..selectedTextcxx . . $ QTextCursor#selectedText(6ef7b6c27b00b43d).()); |
| 73 | |
| 74 | if (cursor.selectionEndcxx . . $ QTextCursor#selectionEnd(455f465bc33b4cdf).() > cursor.selectionStartcxx . . $ QTextCursor#selectionStart(455f465bc33b4cdf).()) |
| 75 | { |
| 76 | cursor.setPositioncxx . . $ QTextCursor#setPosition(f2a23d9eedd3abdd).(cursor.selectionStartcxx . . $ QTextCursor#selectionStart(455f465bc33b4cdf).()); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | cursor.setPositioncxx . . $ QTextCursor#setPosition(f2a23d9eedd3abdd).(cursor.selectionEndcxx . . $ QTextCursor#selectionEnd(455f465bc33b4cdf).()); |
| 81 | } |
| 82 | |
| 83 | cursor.insertTextcxx . . $ QTextCursor#insertText(7bceaa91d413d1d2).( |
| 84 | QStringcxx . . $ QString#QString(f2c90172ce699d92).(QCharcxx . . $ QChar#QChar(5e6be82812882b23).::ObjectReplacementCharactercxx . . $ QChar#ObjectReplacementCharacter.), |
| 85 | format |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | void QFramedTextAttributecxx . . $ QFramedTextAttribute#::clearcxx . . $ QFramedTextAttribute#clear(2dee62e7021fdd8c).(QTextCursorcxx . . $ QTextCursor# cursor) |
| 90 | { |
| 91 | auto doc = cursor.documentcxx . . $ QTextCursor#document(f21741221844491e).(); |
| 92 | |
| 93 | for (auto blockIndex = 0; |
| 94 | blockIndex < doc->blockCountcxx . . $ QTextDocument#blockCount(455f465bc33b4cdf).(); |
| 95 | ++blockIndex) |
| 96 | { |
| 97 | auto block = doccxx . . $ QTextBlock#QTextBlock(ca9d602f58d4ee04).->findBlockByNumbercxx . . $ QTextDocument#findBlockByNumber(c1425046715037b8).(blockIndex); |
| 98 | |
| 99 | auto formats = blockcxx . . $ QVector#QVector(aa2185ac2a214c82)..textFormatscxx . . $ QTextBlock#textFormats(baa231c563df30c).(); |
| 100 | int offset = 0; |
| 101 | |
| 102 | for (auto& format : formats) |
| 103 | { |
| 104 | if (format.formatcxx . . $ QTextLayout#FormatRange#format..objectTypecxx . . $ QTextFormat#objectType(455f465bc33b4cdf).() == typecxx . . $ QFramedTextAttribute#type(b126dc7c1de90089).()) |
| 105 | { |
| 106 | cursor.setPositioncxx . . $ QTextCursor#setPosition(f2a23d9eedd3abdd).(block.positioncxx . . $ QTextBlock#position(455f465bc33b4cdf).() + format.startcxx . . $ QTextLayout#FormatRange#start. - offset); |
| 107 | cursor.deleteCharcxx . . $ QTextCursor#deleteChar(49f6e7a06ebc5aa8).(); |
| 108 | ++offset; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |