fix broken Map drawing on some platforms
This commit is contained in:
parent
cb8793f3b3
commit
c936fed2f8
4 changed files with 46 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* gta5view Grand Theft Auto V Profile Viewer
|
* gta5view Grand Theft Auto V Profile Viewer
|
||||||
* Copyright (C) 2017-2019 Syping
|
* Copyright (C) 2017-2020 Syping
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -60,40 +60,10 @@ MapLocationDialog::~MapLocationDialog()
|
||||||
|
|
||||||
void MapLocationDialog::drawPointOnMap(double xpos_d, double ypos_d)
|
void MapLocationDialog::drawPointOnMap(double xpos_d, double ypos_d)
|
||||||
{
|
{
|
||||||
qreal screenRatio = AppEnv::screenRatio();
|
ui->labPos->setText(tr("X: %1\nY: %2", "X and Y position").arg(QString::number(xpos_d), QString::number(ypos_d)));
|
||||||
qreal screenRatioPR = AppEnv::screenRatioPR();
|
|
||||||
int pointMakerSize = 8 * screenRatio * screenRatioPR;
|
|
||||||
QPixmap pointMakerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMakerSize, pointMakerSize));
|
|
||||||
QSize mapPixelSize = QSize(width() * screenRatioPR, height() * screenRatioPR);
|
|
||||||
|
|
||||||
int pointMakerHalfSize = pointMakerSize / 2;
|
|
||||||
long xpos_ms = qRound(xpos_d);
|
|
||||||
long ypos_ms = qRound(ypos_d);
|
|
||||||
double xpos_ma = xpos_ms + 4000;
|
|
||||||
double ypos_ma = ypos_ms + 4000;
|
|
||||||
double xrat = (double)mapPixelSize.width() / 10000;
|
|
||||||
double yrat = (double)mapPixelSize.height() / 12000;
|
|
||||||
long xpos_mp = qRound(xpos_ma * xrat);
|
|
||||||
long ypos_mp = qRound(ypos_ma * yrat);
|
|
||||||
long xpos_pr = xpos_mp - pointMakerHalfSize;
|
|
||||||
long ypos_pr = ypos_mp + pointMakerHalfSize;
|
|
||||||
|
|
||||||
QPixmap mapPixmap(mapPixelSize);
|
|
||||||
QPainter mapPainter(&mapPixmap);
|
|
||||||
mapPainter.drawPixmap(0, 0, mapPixelSize.width(), mapPixelSize.height(), QPixmap(":/img/mappreview.jpg").scaled(mapPixelSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
||||||
mapPainter.drawPixmap(xpos_pr, mapPixelSize.height() - ypos_pr, pointMakerSize, pointMakerSize, pointMakerPixmap);
|
|
||||||
mapPainter.end();
|
|
||||||
#if QT_VERSION >= 0x050600
|
|
||||||
mapPixmap.setDevicePixelRatio(screenRatioPR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QPalette backgroundPalette;
|
|
||||||
backgroundPalette.setBrush(backgroundRole(), QBrush(mapPixmap));
|
|
||||||
setPalette(backgroundPalette);
|
|
||||||
|
|
||||||
xpos_new = xpos_d;
|
xpos_new = xpos_d;
|
||||||
ypos_new = ypos_d;
|
ypos_new = ypos_d;
|
||||||
ui->labPos->setText(tr("X: %1\nY: %2", "X and Y position").arg(QString::number(xpos_d), QString::number(ypos_d)));
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationDialog::on_cmdChange_clicked()
|
void MapLocationDialog::on_cmdChange_clicked()
|
||||||
|
@ -139,6 +109,43 @@ void MapLocationDialog::updatePosFromEvent(int x, int y)
|
||||||
drawPointOnMap(xpos_fp, ypos_fp);
|
drawPointOnMap(xpos_fp, ypos_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapLocationDialog::paintEvent(QPaintEvent *ev)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
qreal screenRatio = AppEnv::screenRatio();
|
||||||
|
qreal screenRatioPR = AppEnv::screenRatioPR();
|
||||||
|
|
||||||
|
// Paint Map
|
||||||
|
QSize mapPixelSize = QSize(width() * screenRatioPR, height() * screenRatioPR);
|
||||||
|
painter.drawPixmap(0, 0, width(), height(), QPixmap(":/img/mappreview.jpg").scaled(mapPixelSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
|
|
||||||
|
// Paint Marker
|
||||||
|
int pointMarkerSize = 8 * screenRatio;
|
||||||
|
int pointMarkerHalfSize = pointMarkerSize / 2;
|
||||||
|
long xpos_ms = qRound(xpos_new);
|
||||||
|
long ypos_ms = qRound(ypos_new);
|
||||||
|
double xpos_ma = xpos_ms + 4000;
|
||||||
|
double ypos_ma = ypos_ms + 4000;
|
||||||
|
double xrat = (double)width() / 10000;
|
||||||
|
double yrat = (double)height() / 12000;
|
||||||
|
long xpos_mp = qRound(xpos_ma * xrat);
|
||||||
|
long ypos_mp = qRound(ypos_ma * yrat);
|
||||||
|
long xpos_pr;
|
||||||
|
long ypos_pr;
|
||||||
|
if (screenRatioPR != 1) {
|
||||||
|
xpos_pr = xpos_mp - pointMarkerHalfSize + screenRatioPR;
|
||||||
|
ypos_pr = ypos_mp + pointMarkerHalfSize - screenRatioPR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
xpos_pr = xpos_mp - pointMarkerHalfSize;
|
||||||
|
ypos_pr = ypos_mp + pointMarkerHalfSize;
|
||||||
|
}
|
||||||
|
QPixmap mapMarkerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMarkerSize, pointMarkerSize));
|
||||||
|
painter.drawPixmap(xpos_pr, height() - ypos_pr, pointMarkerSize, pointMarkerSize, mapMarkerPixmap);
|
||||||
|
|
||||||
|
QDialog::paintEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev)
|
void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev)
|
||||||
{
|
{
|
||||||
if (!changeMode) { ev->ignore(); }
|
if (!changeMode) { ev->ignore(); }
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
~MapLocationDialog();
|
~MapLocationDialog();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *ev);
|
||||||
void mouseMoveEvent(QMouseEvent *ev);
|
void mouseMoveEvent(QMouseEvent *ev);
|
||||||
void mouseReleaseEvent(QMouseEvent *ev);
|
void mouseReleaseEvent(QMouseEvent *ev);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,11 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Snapmatic Map Viewer</string>
|
<string>Snapmatic Map Viewer</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">QDialog#MapLocationDialog {
|
||||||
|
background-color: transparent;
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
<layout class="QVBoxLayout" name="vlMapPreview">
|
<layout class="QVBoxLayout" name="vlMapPreview">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
|
|
@ -1690,7 +1690,6 @@ void ProfileInterface::retranslateUi()
|
||||||
|
|
||||||
bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
|
bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
qDebug() << "event filter" << event;
|
|
||||||
if (event->type() == QEvent::KeyPress)
|
if (event->type() == QEvent::KeyPress)
|
||||||
{
|
{
|
||||||
if (isProfileLoaded)
|
if (isProfileLoaded)
|
||||||
|
|
Loading…
Reference in a new issue