| 443 | } |
| 444 | |
| 445 | void MainWindow::toolSelected() |
| 446 | { |
| 447 | ui->actionsMenu->clear(); |
| 448 | QModelIndexList list = ui->toolSelector->selectionModel()->selectedRows(); |
| 449 | int row = -1; |
| 450 | |
| 451 | if (!list.isEmpty()) |
| 452 | row = list[0].row(); |
| 453 | |
| 454 | if (row == -1) |
| 455 | return; |
| 456 | |
| 457 | const QModelIndex mi = ui->toolSelector->model()->index(row, 0); |
| 458 | QWidget *toolWidget = mi.data(ToolModelRole::ToolWidget).value<QWidget *>(); |
| 459 | if (!toolWidget) { |
| 460 | toolWidget = createErrorPage(mi); |
| 461 | ui->toolSelector->model()->setData(mi, QVariant::fromValue(toolWidget), ToolModelRole::ToolWidget); |
| 462 | } |
| 463 | |
| 464 | Q_ASSERT(toolWidget); |
| 465 | if (ui->toolStack->indexOf(toolWidget) < 0) { // newly created |
| 466 | if (toolWidget->layout()) { |
| 467 | #ifndef Q_OS_MAC |
| 468 | toolWidget->layout()->setContentsMargins(11, 0, 0, 0); |
| 469 | #else |
| 470 | QMargins margins = toolWidget->layout()->contentsMargins(); |
| 471 | margins.setLeft(0); |
| 472 | toolWidget->layout()->setContentsMargins(margins); |
| 473 | #endif |
| 474 | } |
| 475 | ui->toolStack->addWidget(toolWidget); |
| 476 | } |
| 477 | |
| 478 | ui->toolStack->setCurrentIndex(ui->toolStack->indexOf(toolWidget)); |
| 479 | |
| 480 | foreach (QAction *action, toolWidget->actions()) { |
| 481 | if (auto widgetAction = qobject_cast<QWidgetAction *>(action)) { |
| 482 | if (auto toolButton = qobject_cast<QToolButton *>(widgetAction->defaultWidget())) { |
| 483 | auto subMenu = ui->actionsMenu->addMenu(toolButton->text()); |
| 484 | if (auto defaultAction = toolButton->defaultAction()) { |
| 485 | subMenu->addAction(defaultAction); |
| 486 | subMenu->addSeparator(); |
| 487 | } |
| 488 | subMenu->addActions(toolButton->menu()->actions()); |
| 489 | } |
| 490 | } else { |
| 491 | ui->actionsMenu->addAction(action); |
| 492 | } |
| 493 | } |
| 494 | ui->actionsMenu->setEnabled(!ui->actionsMenu->isEmpty()); |
| 495 | ui->actionsMenu->setTitle(mi.data().toString()); |
| 496 | } |
| 497 | |
| 498 | void MainWindow::toolContextMenu(QPoint pos) |
| 499 | { |
nothing calls this directly
no test coverage detected