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

Method populateQuickAnnotations

part/annotationactionhandler.cpp:346–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346void AnnotationActionHandlerPrivate::populateQuickAnnotations()
347{
348 if (!aQuickTools->isEnabled()) {
349 return;
350 }
351
352 const QList<int> numberKeys = {Qt::Key_1, Qt::Key_2, Qt::Key_3, Qt::Key_4, Qt::Key_5, Qt::Key_6, Qt::Key_7, Qt::Key_8, Qt::Key_9, Qt::Key_0};
353 const bool isFirstTimePopulated = aQuickTools->menu()->actions().isEmpty();
354
355 // to be safe and avoid undefined states of the currently selected quick annotation
356 if (isQuickToolAction(agTools->checkedAction())) {
357 q->deselectAllAnnotationActions();
358 }
359
360 for (QAction *action : std::as_const(quickTools)) {
361 aQuickTools->removeAction(action);
362 aQuickToolsBar->removeAction(action);
363 delete action;
364 }
365 quickTools.clear();
366 textQuickTools.clear();
367
368 int favToolId = 1;
369 QList<int>::const_iterator shortcutNumber = numberKeys.begin();
370 QDomElement favToolElement = annotator->quickTool(favToolId);
371 int actionBarInsertPosition = 0;
372 QAction *aSeparator = aQuickTools->menu()->actions().constFirst();
373 while (!favToolElement.isNull()) {
374 QString itemText = favToolElement.attribute(QStringLiteral("name"));
375 if (favToolElement.attribute(QStringLiteral("default"), QStringLiteral("false")) == QLatin1String("true")) {
376 itemText = i18n(itemText.toLatin1().constData());
377 }
378 if (itemText.isEmpty()) {
379 itemText = PageViewAnnotator::defaultToolName(favToolElement);
380 }
381 QIcon toolIcon = QIcon(PageViewAnnotator::makeToolPixmap(favToolElement));
382 QAction *annFav = new KToggleAction(toolIcon, itemText, q);
383 aQuickTools->insertAction(aSeparator, annFav);
384 aQuickToolsBar->insertAction(actionBarInsertPosition++, annFav);
385 agTools->addAction(annFav);
386 quickTools.append(annFav);
387 if (shortcutNumber != numberKeys.end()) {
388 annFav->setShortcut(QKeySequence(*(shortcutNumber++)));
389 annFav->setShortcutContext(Qt::WidgetWithChildrenShortcut);
390 }
391 QObject::connect(annFav, &KToggleAction::toggled, q, [this, favToolId](bool checked) {
392 if (checked) {
393 slotQuickToolSelected(favToolId);
394 }
395 });
396 QDomElement engineElement = favToolElement.firstChildElement(QStringLiteral("engine"));
397 if (engineElement.attribute(QStringLiteral("type")) == QStringLiteral("TextSelector")) {
398 textQuickTools.append(annFav);
399 annFav->setEnabled(textToolsEnabled);
400 }
401 favToolElement = annotator->quickTool(++favToolId);
402 }
403 aQuickToolsBar->recreateWidgets();

Callers 2

Calls 15

isEmptyMethod · 0.80
actionsMethod · 0.80
removeActionMethod · 0.80
quickToolMethod · 0.80
insertActionMethod · 0.80
appendMethod · 0.80
recreateWidgetsMethod · 0.80
setDefaultActionMethod · 0.80
QIconClass · 0.70
clearMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected