| 849 | } |
| 850 | |
| 851 | void MapWidget::paintEvent(QPaintEvent* event) |
| 852 | { |
| 853 | // Draw on the widget |
| 854 | QPainter painter(this); |
| 855 | QRect exposed = event->rect(); |
| 856 | |
| 857 | if (!view) |
| 858 | { |
| 859 | painter.fillRect(exposed, QColor(Qt::gray)); |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | // No colors, symbols, or objects? Provide a little help message ... |
| 864 | bool no_contents = view->getMap()->getNumObjects() == 0 && view->getMap()->getNumTemplates() == 0 && !view->isGridVisible(); |
| 865 | |
| 866 | QTransform transform = painter.worldTransform(); |
| 867 | |
| 868 | // Update all dirty caches |
| 869 | // TODO: It would be an idea to do these updates in a background thread and use the old caches in the meantime |
| 870 | updateAllDirtyCaches(); |
| 871 | |
| 872 | QRect target = exposed; |
| 873 | if (pinching) |
| 874 | { |
| 875 | // Just draw the scaled map and templates |
| 876 | painter.fillRect(exposed, QColor(Qt::gray)); |
| 877 | painter.translate(pinching_center.x(), pinching_center.y()); |
| 878 | painter.scale(pinching_factor, pinching_factor); |
| 879 | painter.translate(-drag_start_pos.x(), -drag_start_pos.y()); |
| 880 | } |
| 881 | else if (pan_offset != QPoint()) |
| 882 | { |
| 883 | // Background color |
| 884 | if (pan_offset.x() > 0) |
| 885 | painter.fillRect(QRect(0, pan_offset.y(), pan_offset.x(), height() - pan_offset.y()), QColor(Qt::gray)); |
| 886 | else if (pan_offset.x() < 0) |
| 887 | painter.fillRect(QRect(width() + pan_offset.x(), pan_offset.y(), -pan_offset.x(), height() - pan_offset.y()), QColor(Qt::gray)); |
| 888 | |
| 889 | if (pan_offset.y() > 0) |
| 890 | painter.fillRect(QRect(0, 0, width(), pan_offset.y()), QColor(Qt::gray)); |
| 891 | else if (pan_offset.y() < 0) |
| 892 | painter.fillRect(QRect(0, height() + pan_offset.y(), width(), -pan_offset.y()), QColor(Qt::gray)); |
| 893 | |
| 894 | target.translate(pan_offset); |
| 895 | } |
| 896 | |
| 897 | if (!view->areAllTemplatesHidden() && isBelowTemplateVisible() && !below_template_cache.isNull() && view->getMap()->getFirstFrontTemplate() > 0) |
| 898 | { |
| 899 | painter.drawImage(target, below_template_cache, exposed); |
| 900 | } |
| 901 | else if (show_help && no_contents) |
| 902 | { |
| 903 | painter.save(); |
| 904 | painter.setTransform(transform); |
| 905 | if (view->getMap()->getNumColors() == 0) |
| 906 | showHelpMessage(&painter, tr("Empty map!\n\nStart by defining some colors:\nSelect Symbols -> Color window to\nopen the color dialog and\ndefine the colors there.")); |
| 907 | else if (view->getMap()->getNumSymbols() == 0) |
| 908 | showHelpMessage(&painter, tr("No symbols!\n\nNow define some symbols:\nRight-click in the symbol bar\nand select \"New symbol\"\nto create one.")); |
nothing calls this directly
no test coverage detected