massive DPI improvements

This commit is contained in:
Syping 2019-01-13 14:32:12 +01:00
parent aeae6c9311
commit ea0526ae9d
8 changed files with 74 additions and 56 deletions

View File

@ -509,3 +509,12 @@ qreal AppEnv::screenRatio()
return (dpi / 96); return (dpi / 96);
#endif #endif
} }
qreal AppEnv::screenRatioPR()
{
#if QT_VERSION >= 0x050600
return QGuiApplication::primaryScreen()->devicePixelRatio();
#else
return 1;
#endif
}

View File

@ -56,6 +56,7 @@ public:
// Screen Stuff // Screen Stuff
static qreal screenRatio(); static qreal screenRatio();
static qreal screenRatioPR();
}; };
#endif // APPENV_H #endif // APPENV_H

View File

@ -142,6 +142,7 @@ void ImportDialog::processImage()
QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH); QPixmap snapmaticPixmap(snapmaticResolutionW, snapmaticResolutionH);
snapmaticPixmap.fill(selectedColour); snapmaticPixmap.fill(selectedColour);
QPainter snapmaticPainter(&snapmaticPixmap); QPainter snapmaticPainter(&snapmaticPixmap);
qreal screenRatioPR = AppEnv::screenRatioPR();
if (!backImage.isNull()) if (!backImage.isNull())
{ {
if (!ui->cbStretch->isChecked()) if (!ui->cbStretch->isChecked())
@ -225,7 +226,10 @@ void ImportDialog::processImage()
} }
snapmaticPainter.end(); snapmaticPainter.end();
newImage = snapmaticPixmap.toImage(); newImage = snapmaticPixmap.toImage();
ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW, snapmaticResolutionLH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); #if QT_VERSION >= 0x050600
snapmaticPixmap.setDevicePixelRatio(screenRatioPR);
#endif
ui->labPicture->setPixmap(snapmaticPixmap.scaled(snapmaticResolutionLW * screenRatioPR, snapmaticResolutionLH * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
} }
void ImportDialog::processWatermark(QPainter *snapmaticPainter) void ImportDialog::processWatermark(QPainter *snapmaticPainter)

View File

@ -94,6 +94,7 @@ JsonEditorDialog::JsonEditorDialog(SnapmaticPicture *picture, QWidget *parent) :
{ {
ui->lineJSON->setMinimumHeight(qRound(1 * screenRatio)); ui->lineJSON->setMinimumHeight(qRound(1 * screenRatio));
ui->lineJSON->setMaximumHeight(qRound(1 * screenRatio)); ui->lineJSON->setMaximumHeight(qRound(1 * screenRatio));
ui->lineJSON->setLineWidth(qRound(1 * screenRatio));
} }
resize(450 * screenRatio, 550 * screenRatio); resize(450 * screenRatio, 550 * screenRatio);
} }

View File

@ -138,9 +138,10 @@ void PictureDialog::setupPictureDialog()
// Avatar area // Avatar area
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
if (screenRatio != 1) qreal screenRatioPR = AppEnv::screenRatioPR();
if (screenRatio != 1 || screenRatioPR != 1)
{ {
avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(536 * screenRatio, Qt::FastTransformation); avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(536 * screenRatio * screenRatioPR, Qt::FastTransformation);
} }
else else
{ {
@ -150,6 +151,11 @@ void PictureDialog::setupPictureDialog()
avatarLocY = 66; avatarLocY = 66;
avatarSize = 470; avatarSize = 470;
// DPI calculation (picture)
ui->labPicture->setFixedSize(960 * screenRatio, 536 * screenRatio);
ui->labPicture->setFocusPolicy(Qt::StrongFocus);
ui->labPicture->setScaledContents(true);
// Overlay area // Overlay area
renderOverlayPicture(); renderOverlayPicture();
overlayEnabled = true; overlayEnabled = true;
@ -185,8 +191,6 @@ void PictureDialog::setupPictureDialog()
installEventFilter(this); installEventFilter(this);
installEventFilter(ui->labPicture); installEventFilter(ui->labPicture);
ui->labPicture->setFixedSize(960 * screenRatio, 536 * screenRatio);
ui->labPicture->setFocusPolicy(Qt::StrongFocus);
// DPI calculation // DPI calculation
ui->hlButtons->setSpacing(6 * screenRatio); ui->hlButtons->setSpacing(6 * screenRatio);
@ -343,7 +347,7 @@ LRESULT PictureDialog::HitTestNCA(HWND hWnd, LPARAM lParam)
void PictureDialog::resizeEvent(QResizeEvent *event) void PictureDialog::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
// int newDialogHeight = ui->labPicture->pixmap()->height(); // int newDialogHeight = (ui->labPicture->pixmap()->height() / AppEnv::screenRatioPR());
// newDialogHeight = newDialogHeight + ui->jsonFrame->height(); // newDialogHeight = newDialogHeight + ui->jsonFrame->height();
// if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height(); // if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height();
// int buttomBorderSize = (frameSize().height() - size().height()); // int buttomBorderSize = (frameSize().height() - size().height());
@ -364,7 +368,7 @@ void PictureDialog::resizeEvent(QResizeEvent *event)
void PictureDialog::adaptNewDialogSize(QSize newLabelSize) void PictureDialog::adaptNewDialogSize(QSize newLabelSize)
{ {
Q_UNUSED(newLabelSize) Q_UNUSED(newLabelSize)
int newDialogHeight = ui->labPicture->pixmap()->height(); int newDialogHeight = (ui->labPicture->pixmap()->height() / AppEnv::screenRatioPR());
newDialogHeight = newDialogHeight + ui->jsonFrame->height(); newDialogHeight = newDialogHeight + ui->jsonFrame->height();
if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height(); if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height();
setMaximumSize(width(), newDialogHeight); setMaximumSize(width(), newDialogHeight);
@ -566,24 +570,25 @@ void PictureDialog::renderOverlayPicture()
{ {
// Generating Overlay Preview // Generating Overlay Preview
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
QRect preferedRect = QRect(0, 0, 200 * screenRatio, 160 * screenRatio); qreal screenRatioPR = AppEnv::screenRatioPR();
QRect preferedRect = QRect(0, 0, 200 * screenRatio * screenRatioPR, 160 * screenRatio * screenRatioPR);
QString overlayText = tr("Key 1 - Avatar Preview Mode\nKey 2 - Toggle Overlay\nArrow Keys - Navigate"); QString overlayText = tr("Key 1 - Avatar Preview Mode\nKey 2 - Toggle Overlay\nArrow Keys - Navigate");
QFont overlayPainterFont; QFont overlayPainterFont;
overlayPainterFont.setPixelSize(12 * screenRatio); overlayPainterFont.setPixelSize(12 * screenRatio * screenRatioPR);
QFontMetrics fontMetrics(overlayPainterFont); QFontMetrics fontMetrics(overlayPainterFont);
QRect overlaySpace = fontMetrics.boundingRect(preferedRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextDontClip | Qt::TextWordWrap, overlayText); QRect overlaySpace = fontMetrics.boundingRect(preferedRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextDontClip | Qt::TextWordWrap, overlayText);
int hOverlay = Qt::AlignTop; int hOverlay = Qt::AlignTop;
if (overlaySpace.height() < 74 * screenRatio) if (overlaySpace.height() < 74 * screenRatio * screenRatioPR)
{ {
hOverlay = Qt::AlignVCenter; hOverlay = Qt::AlignVCenter;
preferedRect.setHeight(71 * screenRatio); preferedRect.setHeight(71 * screenRatio * screenRatioPR);
overlaySpace.setHeight(80 * screenRatio); overlaySpace.setHeight(80 * screenRatio * screenRatioPR);
} }
else else
{ {
overlaySpace.setHeight(overlaySpace.height() + 6 * screenRatio); overlaySpace.setHeight(overlaySpace.height() + 6 * screenRatio * screenRatioPR);
} }
QImage overlayImage(overlaySpace.size(), QImage::Format_ARGB32_Premultiplied); QImage overlayImage(overlaySpace.size(), QImage::Format_ARGB32_Premultiplied);
@ -595,13 +600,13 @@ void PictureDialog::renderOverlayPicture()
overlayPainter.drawText(preferedRect, Qt::AlignLeft | hOverlay | Qt::TextDontClip | Qt::TextWordWrap, overlayText); overlayPainter.drawText(preferedRect, Qt::AlignLeft | hOverlay | Qt::TextDontClip | Qt::TextWordWrap, overlayText);
overlayPainter.end(); overlayPainter.end();
if (overlaySpace.width() < 194 * screenRatio) if (overlaySpace.width() < 194 * screenRatio * screenRatioPR)
{ {
overlaySpace.setWidth(200 * screenRatio); overlaySpace.setWidth(200 * screenRatio * screenRatioPR);
} }
else else
{ {
overlaySpace.setWidth(overlaySpace.width() + 6 * screenRatio); overlaySpace.setWidth(overlaySpace.width() + 6 * screenRatio * screenRatioPR);
} }
QImage overlayBorderImage(overlaySpace.width(), overlaySpace.height(), QImage::Format_ARGB6666_Premultiplied); QImage overlayBorderImage(overlaySpace.width(), overlaySpace.height(), QImage::Format_ARGB6666_Premultiplied);
@ -611,7 +616,7 @@ void PictureDialog::renderOverlayPicture()
overlayTempImage.fill(Qt::transparent); overlayTempImage.fill(Qt::transparent);
QPainter overlayTempPainter(&overlayTempImage); QPainter overlayTempPainter(&overlayTempImage);
overlayTempPainter.drawImage(0, 0, overlayBorderImage); overlayTempPainter.drawImage(0, 0, overlayBorderImage);
overlayTempPainter.drawImage(3 * screenRatio, 3 * screenRatio, overlayImage); overlayTempPainter.drawImage(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, overlayImage);
overlayTempPainter.end(); overlayTempPainter.end();
} }
@ -684,63 +689,51 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture)
void PictureDialog::renderPicture() void PictureDialog::renderPicture()
{ {
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR();
if (!previewMode) if (!previewMode)
{ {
if (overlayEnabled) if (overlayEnabled)
{ {
QPixmap shownImagePixmap(960 * screenRatio, 536 * screenRatio); QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
shownImagePixmap.fill(Qt::transparent); shownImagePixmap.fill(Qt::transparent);
QPainter shownImagePainter(&shownImagePixmap); QPainter shownImagePainter(&shownImagePixmap);
if (screenRatio == 1) shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
{ shownImagePainter.drawImage(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, overlayTempImage);
shownImagePainter.drawImage(0, 0, snapmaticPicture);
shownImagePainter.drawImage(3 * screenRatio, 3 * screenRatio, overlayTempImage);
}
else
{
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaledToHeight(536 * screenRatio, Qt::SmoothTransformation));
shownImagePainter.drawImage(3 * screenRatio, 3 * screenRatio, overlayTempImage);
}
shownImagePainter.end(); shownImagePainter.end();
#if QT_VERSION >= 0x050600
shownImagePixmap.setDevicePixelRatio(screenRatioPR);
#endif
ui->labPicture->setPixmap(shownImagePixmap); ui->labPicture->setPixmap(shownImagePixmap);
} }
else else
{ {
if (screenRatio != 1) QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
{ shownImagePixmap.fill(Qt::transparent);
QPixmap shownImagePixmap(960 * screenRatio, 536 * screenRatio); QPainter shownImagePainter(&shownImagePixmap);
shownImagePixmap.fill(Qt::transparent); shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
QPainter shownImagePainter(&shownImagePixmap); shownImagePainter.end();
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaledToHeight(536 * screenRatio, Qt::SmoothTransformation)); #if QT_VERSION >= 0x050600
shownImagePainter.end(); shownImagePixmap.setDevicePixelRatio(screenRatioPR);
ui->labPicture->setPixmap(shownImagePixmap); #endif
} ui->labPicture->setPixmap(shownImagePixmap);
else
{
ui->labPicture->setPixmap(QPixmap::fromImage(snapmaticPicture));
}
} }
} }
else else
{ {
// Generating Avatar Preview // Generating Avatar Preview
QPixmap avatarPixmap(960 * screenRatio, 536 * screenRatio); QPixmap avatarPixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
QPainter snapPainter(&avatarPixmap); QPainter snapPainter(&avatarPixmap);
QFont snapPainterFont; QFont snapPainterFont;
snapPainterFont.setPixelSize(12 * screenRatio); snapPainterFont.setPixelSize(12 * screenRatio * screenRatioPR);
if (screenRatio == 1) snapPainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
{
snapPainter.drawImage(0, 0, snapmaticPicture);
}
else
{
snapPainter.drawImage(0, 0, snapmaticPicture.scaledToHeight(536 * screenRatio, Qt::SmoothTransformation));
}
snapPainter.drawImage(0, 0, avatarAreaPicture); snapPainter.drawImage(0, 0, avatarAreaPicture);
snapPainter.setPen(QColor::fromRgb(255, 255, 255, 255)); snapPainter.setPen(QColor::fromRgb(255, 255, 255, 255));
snapPainter.setFont(snapPainterFont); snapPainter.setFont(snapPainterFont);
snapPainter.drawText(QRect(3 * screenRatio, 3 * screenRatio, 140 * screenRatio, 536 * screenRatio), Qt::AlignLeft | Qt::TextWordWrap, tr("Avatar Preview Mode\nPress 1 for Default View")); snapPainter.drawText(QRect(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, 140 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR), Qt::AlignLeft | Qt::TextWordWrap, tr("Avatar Preview Mode\nPress 1 for Default View"));
snapPainter.end(); snapPainter.end();
#if QT_VERSION >= 0x050600
avatarPixmap.setDevicePixelRatio(screenRatioPR);
#endif
ui->labPicture->setPixmap(avatarPixmap); ui->labPicture->setPixmap(avatarPixmap);
} }
} }

View File

@ -58,9 +58,8 @@ SavegameWidget::SavegameWidget(QWidget *parent) :
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio); ui->labSavegamePic->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap savegamePixmap(":/img/savegame.svgz"); ui->labSavegamePic->setScaledContents(true);
savegamePixmap = savegamePixmap.scaledToHeight(ui->labSavegamePic->height(), Qt::SmoothTransformation); ui->labSavegamePic->setPixmap(QPixmap(":/img/savegame.svgz"));
ui->labSavegamePic->setPixmap(savegamePixmap);
QString exportSavegameStr = tr("Export Savegame..."); QString exportSavegameStr = tr("Export Savegame...");
Q_UNUSED(exportSavegameStr) Q_UNUSED(exportSavegameStr)

View File

@ -78,9 +78,16 @@ void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
QObject::connect(picture, SIGNAL(customSignal(QString)), this, SLOT(customSignal(QString))); QObject::connect(picture, SIGNAL(customSignal(QString)), this, SLOT(customSignal(QString)));
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR();
ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio); ui->labPicture->setFixedSize(48 * screenRatio, 27 * screenRatio);
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getImage().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor); ui->labPicture->setScaledContents(true);
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getImage().scaled(ui->labPicture->width() * screenRatioPR, ui->labPicture->height() * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::AutoColor);
#if QT_VERSION >= 0x050600
SnapmaticPixmap.setDevicePixelRatio(screenRatioPR);
#endif
ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl()); ui->labPicStr->setText(smpic->getPictureStr() % "\n" % smpic->getPictureTitl());
ui->labPicture->setPixmap(SnapmaticPixmap); ui->labPicture->setPixmap(SnapmaticPixmap);

View File

@ -65,6 +65,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if QT_VERSION >= 0x050600
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationName(GTA5SYNC_APPSTR); a.setApplicationName(GTA5SYNC_APPSTR);
a.setApplicationVersion(GTA5SYNC_APPVER); a.setApplicationVersion(GTA5SYNC_APPVER);