MCPcopy Create free account
hub / github.com/alpha-liu-01/SpeedyNote / ensureDocCache

Method ensureDocCache

source/objects/TextBoxObject.cpp:42–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42QTextDocument* TextBoxObject::ensureDocCache(qreal width) const
43{
44 if (m_cachedDoc
45 && qFuzzyCompare(1.0 + m_cachedDocWidth, 1.0 + width)
46 && m_cachedText == text
47 && m_cachedAlignment == alignment
48 && m_cachedFontColor == fontColor) {
49 return m_cachedDoc;
50 }
51
52 if (!m_cachedDoc)
53 m_cachedDoc = new QTextDocument();
54
55 m_cachedDoc->setMarkdown(text);
56
57 QTextCursor cursor(m_cachedDoc);
58 cursor.select(QTextCursor::Document);
59 QTextCharFormat fmt;
60 fmt.setForeground(QBrush(fontColor));
61 cursor.mergeCharFormat(fmt);
62
63 m_cachedDoc->setTextWidth(width);
64
65 QTextOption opt;
66 switch (alignment) {
67 case TextAlignment::Center: opt.setAlignment(Qt::AlignCenter); break;
68 case TextAlignment::Right: opt.setAlignment(Qt::AlignRight); break;
69 default: opt.setAlignment(Qt::AlignLeft); break;
70 }
71 m_cachedDoc->setDefaultTextOption(opt);
72
73 QFont docFont;
74 if (!fontFamily.isEmpty())
75 docFont.setFamily(fontFamily);
76 if (fontSize > 0.0)
77 docFont.setPixelSize(static_cast<int>(fontSize));
78 m_cachedDoc->setDefaultFont(docFont);
79
80 m_cachedDocWidth = width;
81 m_cachedText = text;
82 m_cachedAlignment = alignment;
83 m_cachedFontColor = fontColor;
84 return m_cachedDoc;
85}
86
87QTextDocument* TextBoxObject::cachedDocument() const
88{

Callers 1

Calls 1

isEmptyMethod · 0.45

Tested by

no test coverage detected