| 344 | } |
| 345 | |
| 346 | void 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(); |
no test coverage detected