| 2394 | } |
| 2395 | |
| 2396 | void MapEditorController::selectedSymbolsChanged() |
| 2397 | { |
| 2398 | Symbol* symbol = symbol_widget->getSingleSelectedSymbol(); |
| 2399 | |
| 2400 | if (mobile_mode) |
| 2401 | { |
| 2402 | auto* symbol_button = bottom_action_bar->getButtonForAction(mobile_symbol_selector_action); |
| 2403 | |
| 2404 | // (Re-)create the mobile_symbol_selector_action icon |
| 2405 | QSize icon_size = bottom_action_bar->getIconSize(2, 2); |
| 2406 | QPixmap pixmap(icon_size); |
| 2407 | pixmap.fill(Qt::white); |
| 2408 | if (symbol_widget->selectedSymbolsCount() != 1) |
| 2409 | { |
| 2410 | QFont font(window->font()); |
| 2411 | font.setPixelSize(icon_size.height() / 5); |
| 2412 | QPainter painter(&pixmap); |
| 2413 | painter.setFont(font); |
| 2414 | QString text = (symbol_widget->selectedSymbolsCount() == 0) ? |
| 2415 | //: Keep it short. Should not be much longer per line than the longest word in the original. |
| 2416 | tr("No\nsymbol\nselected") : |
| 2417 | //: Keep it short. Should not be much longer per line than the longest word in the original. |
| 2418 | tr("Multiple\nsymbols\nselected"); |
| 2419 | painter.drawText(pixmap.rect(), Qt::AlignCenter, text); |
| 2420 | |
| 2421 | symbol_button->setMenu(nullptr); |
| 2422 | } |
| 2423 | else //if (symbol_widget->getNumSelectedSymbols() == 1) |
| 2424 | { |
| 2425 | auto image = symbol->getCustomIcon(); |
| 2426 | if (image.isNull()) |
| 2427 | image = symbol->createIcon(*map, qMin(icon_size.width(), icon_size.height())); |
| 2428 | else |
| 2429 | image = image.scaled(icon_size.width(), icon_size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); |
| 2430 | if (symbol->isHidden() || symbol->isProtected()) |
| 2431 | { |
| 2432 | QPainter p(&image); |
| 2433 | if (symbol->isHidden()) |
| 2434 | HiddenSymbolDecorator(icon_size.width()).draw(p); |
| 2435 | if (symbol->isProtected()) |
| 2436 | ProtectedSymbolDecorator(icon_size.width()).draw(p); |
| 2437 | } |
| 2438 | pixmap = QPixmap::fromImage(image); |
| 2439 | |
| 2440 | symbol_button->setMenu(mobile_symbol_button_menu); |
| 2441 | const auto actions = mobile_symbol_button_menu->actions(); |
| 2442 | int i = 0; |
| 2443 | actions[i]->setText(symbol->getNumberAsString() + QLatin1Char(' ') + symbol->getPlainTextName()); |
| 2444 | actions[++i]->setVisible(!symbol->getDescription().isEmpty()); |
| 2445 | ++i; // separator |
| 2446 | actions[++i]->setChecked(symbol->isHidden()); |
| 2447 | actions[++i]->setChecked(symbol->isProtected()); |
| 2448 | } |
| 2449 | mobile_symbol_selector_action->setIcon(QIcon(pixmap)); |
| 2450 | } |
| 2451 | |
| 2452 | // FIXME: Postpone switch of active symbol while editing is progress |
| 2453 | if (active_symbol != symbol) |
nothing calls this directly
no test coverage detected