MCPcopy Create free account
hub / github.com/KDE/okular / addInPlaceTextAnnotation

Method addInPlaceTextAnnotation

part/pageviewannotator.cpp:195–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193 }
194
195 void addInPlaceTextAnnotation(Okular::Annotation *&ann, const QString &summary, const QString &content, Okular::TextAnnotation::InplaceIntent inplaceIntent)
196 {
197 Okular::TextAnnotation *ta = new Okular::TextAnnotation();
198 ann = ta;
199 ta->setFlags(ta->flags() | Okular::Annotation::FixedRotation);
200 ta->setContents(content);
201 ta->setTextType(Okular::TextAnnotation::InPlace);
202 ta->setInplaceIntent(inplaceIntent);
203 // set alignment
204 if (m_annotElement.hasAttribute(QStringLiteral("align"))) {
205 ta->setInplaceAlignment(m_annotElement.attribute(QStringLiteral("align")).toInt());
206 }
207 // set font
208 if (m_annotElement.hasAttribute(QStringLiteral("font"))) {
209 QFont f;
210 // Workaround broken old code that saved fonts incorrectly with extra backslashes
211 QString fontString = m_annotElement.attribute(QStringLiteral("font"));
212 if (fontString.count(QStringLiteral("\\\\,")) > 9) {
213 fontString.replace(QStringLiteral("\\\\,"), QStringLiteral(","));
214 }
215 f.fromString(fontString);
216 ta->setTextFont(f);
217 }
218 // set font color
219 if (m_annotElement.hasAttribute(QStringLiteral("textColor"))) {
220 if (inplaceIntent == Okular::TextAnnotation::TypeWriter) {
221 ta->setTextColor(m_annotElement.attribute(QStringLiteral("textColor")));
222 } else {
223 ta->setTextColor(Qt::black);
224 }
225 }
226 // set width
227 if (m_annotElement.hasAttribute(QStringLiteral("width"))) {
228 ta->style().setWidth(m_annotElement.attribute(QStringLiteral("width")).toDouble());
229 }
230 // set boundary
231 rect.left = qMin(startpoint.x, point.x);
232 rect.top = qMin(startpoint.y, point.y);
233 rect.right = qMax(startpoint.x, point.x);
234 rect.bottom = qMax(startpoint.y, point.y);
235 qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale;
236 static const int padding = 2;
237 const QFontMetricsF mf(ta->textFont());
238 const QRectF rcf =
239 mf.boundingRect(Okular::NormalizedRect(rect.left, rect.top, 1.0, 1.0).geometry((int)pagewidth, (int)pageheight).adjusted(padding, padding, -padding, -padding), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents());
240 rect.right = qMax(rect.right, rect.left + (rcf.width() + padding * 2) / pagewidth);
241 rect.bottom = qMax(rect.bottom, rect.top + (rcf.height() + padding * 2) / pageheight);
242 ta->window().setSummary(summary);
243 }
244
245 QList<Okular::Annotation *> end() override
246 {

Callers

nothing calls this directly

Calls 15

setFlagsMethod · 0.80
setContentsMethod · 0.80
setTextTypeMethod · 0.80
setInplaceIntentMethod · 0.80
setInplaceAlignmentMethod · 0.80
setTextFontMethod · 0.80
setTextColorMethod · 0.80
toDoubleMethod · 0.80
textFontMethod · 0.80
boundingRectMethod · 0.80
setSummaryMethod · 0.80
NormalizedRectClass · 0.70

Tested by

no test coverage detected