| 364 | } |
| 365 | |
| 366 | void MapView::showContextMenu(const QPoint &pos) |
| 367 | { |
| 368 | QMenu *menu = new QMenu(this); |
| 369 | menu->setFont(font()); |
| 370 | // this is a contextual temporary menu so shortcuts are only indicated here, |
| 371 | // but will not function - see keyReleaseEvent() for shortcut implementation |
| 372 | |
| 373 | if (world) |
| 374 | { |
| 375 | mstart = pos; |
| 376 | world->setSelectPos(mstart); |
| 377 | grab(); // invokes an immediate paint call |
| 378 | } |
| 379 | |
| 380 | struct _cpy_dat { QString txt, cpy; }; |
| 381 | std::vector<_cpy_dat> cpy_dat; |
| 382 | |
| 383 | VarPos vp = getActivePos(); |
| 384 | const QPixmap *icon = 0; |
| 385 | |
| 386 | if (vp.type != -1) |
| 387 | { // structure has a known size / location |
| 388 | int midx, midy, midz; |
| 389 | if (vp.pieces.size() > 0) |
| 390 | { |
| 391 | const Piece& pc = vp.pieces[0]; |
| 392 | midx = (pc.bb0.x + pc.bb1.x) >> 1; |
| 393 | midy = (pc.bb0.y) + 1; |
| 394 | midz = (pc.bb0.z + pc.bb1.z) >> 1; |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | midx = vp.p.x + vp.v.x + vp.v.sx / 2; |
| 399 | midy = vp.v.y; |
| 400 | midz = vp.p.z + vp.v.z + vp.v.sz / 2; |
| 401 | if (midy >= 320 && world) |
| 402 | { |
| 403 | midy = world->estimateSurface(Pos{midx, midz}) + 8; |
| 404 | if (midy < 63) |
| 405 | midy = 63; |
| 406 | } |
| 407 | } |
| 408 | cpy_dat.push_back({ tr("Copy tp:"), QString::asprintf("/tp @p %d %d %d", midx, midy, midz) }); |
| 409 | icon = &getMapIcon(world ? world->selopt : -1, &vp); |
| 410 | } |
| 411 | cpy_dat.push_back({ tr("Copy tp:"), QString::asprintf("/tp @p %d ~ %d", vp.p.x, vp.p.z) }); |
| 412 | cpy_dat.push_back({ tr("Copy coords:"), QString::asprintf("%d %d", vp.p.x, vp.p.z) }); |
| 413 | cpy_dat.push_back({ tr("Copy chunk:"), QString::asprintf("%d %d", vp.p.x >> 4, vp.p.z >> 4) }); |
| 414 | cpy_dat.push_back({ tr("Copy region:"), QString::asprintf("%d %d", vp.p.x >> 9, vp.p.z >> 9) }); |
| 415 | |
| 416 | int wmax = 0; |
| 417 | for (auto& it : cpy_dat) |
| 418 | { |
| 419 | int w = txtWidth(menu->fontMetrics(), it.txt + " "); |
| 420 | if (w > wmax) |
| 421 | wmax = w; |
| 422 | } |
| 423 |
nothing calls this directly
no test coverage detected