From 58a7d8c9cf50d4b2a9ae321684ca9d4ce4504260 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 10 May 2024 00:04:04 -0400 Subject: Disable automatic hidpi scaling on maps. Add zoom option. --- mapman/src/painter.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'mapman/src/painter.cpp') diff --git a/mapman/src/painter.cpp b/mapman/src/painter.cpp index 3dafee6..bfd2f79 100644 --- a/mapman/src/painter.cpp +++ b/mapman/src/painter.cpp @@ -14,7 +14,7 @@ class drop_rect : public QGraphicsRectItem { public: - drop_rect(int pos, map_painter *painter); + drop_rect(int pos, double dim, map_painter *painter); signals: void dropped(int pos, int id); protected: @@ -25,8 +25,8 @@ private: map_painter *pt; }; -drop_rect::drop_rect(int pos, map_painter *painter) : - QGraphicsRectItem(QRectF(0, 0, 128, 128), nullptr), +drop_rect::drop_rect(int pos, double dim, map_painter *painter) : + QGraphicsRectItem(QRectF(0, 0, dim, dim), nullptr), p(pos), pt(painter) { @@ -51,10 +51,11 @@ void drop_rect::dropEvent(QGraphicsSceneDragDropEvent *e) else e->setDropAction(Qt::DropAction::IgnoreAction); } -map_painter::map_painter() : l(nullptr) +map_painter::map_painter(QWidget *parent) : l(nullptr) { s = new QGraphicsScene(0, 0, 0, 0); - v = new QGraphicsView(s); + v = new QGraphicsView(s, parent); + slice_dim = 128 / parent->devicePixelRatio(); hc = vc = 0; } @@ -68,7 +69,7 @@ void map_painter::set_dimension(int h, int v) { hc = h; vc = v; - s->setSceneRect(0, 0, hc * 128, vc * 128); + s->setSceneRect(0, 0, hc * slice_dim, vc * slice_dim); s->clear(); slices.clear(); slices.resize(hc * vc, nullptr); @@ -78,11 +79,11 @@ void map_painter::set_dimension(int h, int v) for (int j = 0; j < hc; ++j) { auto t = s->addSimpleText(QString::number(i * hc + j)); - t->setPos(j * 128 + 64 - t->boundingRect().width() / 2, i * 128 + 64 - t->boundingRect().height() / 2); - auto r = new drop_rect(i * hc + j, this); + t->setPos(j * slice_dim + slice_dim / 2 - t->boundingRect().width() / 2, i * slice_dim + slice_dim / 2 - t->boundingRect().height() / 2); + auto r = new drop_rect(i * hc + j, slice_dim, this); s->addItem(r); bgspr[i * hc + j] = {t, r}; - r->setPos(j * 128, i * 128); + r->setPos(j * slice_dim, i * slice_dim); } } @@ -101,7 +102,7 @@ void map_painter::set_map_id(int pos, bool populated, int id, bool user_input) QPixmap pm; if (!QPixmapCache::find(QString("map_%1").arg(id), &pm)) { - pm = pixmap_of_map_data(l->get_map(id).map_data); + pm = pixmap_of_map_data(l->get_map(id).map_data, this->v->devicePixelRatio()); QPixmapCache::insert(QString("map_%1").arg(id), pm); } auto p = s->addPixmap(pm); @@ -112,7 +113,7 @@ void map_painter::set_map_id(int pos, bool populated, int id, bool user_input) .arg(m.locked ? "\nLocked" : "")); int x = pos / hc; int y = pos % hc; - p->setPos(y * 128, x * 128); + p->setPos(y * slice_dim, x * slice_dim); slices[pos] = p; static_cast(t)->setPen(QColor(Qt::GlobalColor::transparent)); static_cast(r)->setPen(QColor(Qt::GlobalColor::transparent)); @@ -121,4 +122,9 @@ void map_painter::set_map_id(int pos, bool populated, int id, bool user_input) emit map_id_changed(pos, populated, id); } +void map_painter::set_scaling(double scale) +{ + v->setTransform(QTransform::fromScale(scale, scale)); +} + void map_painter::set_map_library(map_library *lib) { l = lib; } -- cgit v1.2.3