fix some deprecations, more compatibility
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Syping 2020-08-25 17:29:41 +02:00
parent a882738735
commit 28fedfdd0b
5 changed files with 49 additions and 14 deletions

View file

@ -77,7 +77,11 @@ JsonEditorDialog::JsonEditorDialog(SnapmaticPicture *picture, QWidget *parent) :
ui->txtJSON->setFont(jsonFont);
#endif
QFontMetrics fontMetrics(ui->txtJSON->font());
#if QT_VERSION >= 0x050B00
ui->txtJSON->setTabStopDistance(fontMetrics.horizontalAdvance(" "));
#else
ui->txtJSON->setTabStopWidth(fontMetrics.width(" "));
#endif
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonCode.toUtf8());
ui->txtJSON->setStyleSheet("QPlainTextEdit{background-color: rgb(46, 47, 48); color: rgb(238, 231, 172);}");

View file

@ -135,12 +135,15 @@ void PictureDialog::setupPictureDialog()
smpic = nullptr;
crewStr = "";
// Get Snapmatic Resolution
QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
// Avatar area
qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR();
if (screenRatio != 1 || screenRatioPR != 1)
{
avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(536 * screenRatio * screenRatioPR, Qt::FastTransformation);
avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::FastTransformation);
}
else
{
@ -151,7 +154,7 @@ void PictureDialog::setupPictureDialog()
avatarSize = 470;
// DPI calculation (picture)
ui->labPicture->setFixedSize(960 * screenRatio, 536 * screenRatio);
ui->labPicture->setFixedSize(snapmaticResolution.width() * screenRatio, snapmaticResolution.height() * screenRatio);
ui->labPicture->setFocusPolicy(Qt::StrongFocus);
ui->labPicture->setScaledContents(true);
@ -198,8 +201,8 @@ void PictureDialog::setupPictureDialog()
ui->jsonLayout->setContentsMargins(4 * screenRatio, 10 * screenRatio, 4 * screenRatio, 4 * screenRatio);
// Pre-adapt window for DPI
setFixedWidth(960 * screenRatio);
setFixedHeight(536 * screenRatio);
setFixedWidth(snapmaticResolution.width() * screenRatio);
setFixedHeight(snapmaticResolution.height() * screenRatio);
}
PictureDialog::~PictureDialog()
@ -389,7 +392,11 @@ void PictureDialog::resizeEvent(QResizeEvent *event)
void PictureDialog::adaptNewDialogSize(QSize newLabelSize)
{
Q_UNUSED(newLabelSize)
#if QT_VERSION >= 0x050F00
int newDialogHeight = SnapmaticPicture::getSnapmaticResolution().height();
#else
int newDialogHeight = (ui->labPicture->pixmap()->height() / AppEnv::screenRatioPR());
#endif
newDialogHeight = newDialogHeight + ui->jsonFrame->height();
if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height();
setMaximumSize(width(), newDialogHeight);
@ -715,10 +722,11 @@ void PictureDialog::renderPicture()
{
if (overlayEnabled)
{
QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap shownImagePixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
shownImagePixmap.fill(Qt::transparent);
QPainter shownImagePainter(&shownImagePixmap);
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.drawImage(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, overlayTempImage);
shownImagePainter.end();
#if QT_VERSION >= 0x050600
@ -728,10 +736,11 @@ void PictureDialog::renderPicture()
}
else
{
QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap shownImagePixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
shownImagePixmap.fill(Qt::transparent);
QPainter shownImagePainter(&shownImagePixmap);
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.end();
#if QT_VERSION >= 0x050600
shownImagePixmap.setDevicePixelRatio(screenRatioPR);
@ -742,15 +751,16 @@ void PictureDialog::renderPicture()
else
{
// Generating Avatar Preview
QPixmap avatarPixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR);
QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap avatarPixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
QPainter snapPainter(&avatarPixmap);
QFont snapPainterFont;
snapPainterFont.setPixelSize(12 * screenRatio * screenRatioPR);
snapPainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
snapPainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
snapPainter.drawImage(0, 0, avatarAreaPicture);
snapPainter.setPen(QColor::fromRgb(255, 255, 255, 255));
snapPainter.setFont(snapPainterFont);
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.drawText(QRect(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, 140 * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR), Qt::AlignLeft | Qt::TextWordWrap, tr("Avatar Preview Mode\nPress 1 for Default View"));
snapPainter.end();
#if QT_VERSION >= 0x050600
avatarPixmap.setDevicePixelRatio(screenRatioPR);

View file

@ -264,7 +264,11 @@ void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
@ -284,7 +288,11 @@ void ProfileInterface::insertSavegameIPI(QWidget *widget)
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList savegameKeyList = widgetsKeyList.filter("SGD", Qt::CaseSensitive);
#if QT_VERSION >= 0x050F00
std::sort(savegameKeyList.begin(), savegameKeyList.end());
#else
qSort(savegameKeyList.begin(), savegameKeyList.end());
#endif
int sgdIndex = savegameKeyList.indexOf(QRegExp(widgetKey));
ui->vlSavegame->insertWidget(sgdIndex, proWidget);
@ -303,7 +311,11 @@ void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
@ -338,7 +350,11 @@ void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog)
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
@ -369,7 +385,12 @@ void ProfileInterface::sortingProfileInterface()
ui->vlSnapmatic->setEnabled(false);
QStringList widgetsKeyList = widgets.values();
#if QT_VERSION >= 0x050F00
std::sort(widgetsKeyList.begin(), widgetsKeyList.end());
#else
qSort(widgetsKeyList.begin(), widgetsKeyList.end());
#endif
for (QString widgetKey : widgetsKeyList)
{

View file

@ -433,8 +433,8 @@ QString SnapmaticPicture::getSnapmaticHeaderString(const QByteArray &snapmaticHe
QString SnapmaticPicture::getSnapmaticJSONString(const QByteArray &jsonBytes)
{
QByteArray jsonUsefulBytes = jsonBytes;
jsonUsefulBytes.replace('\x00', QString());
jsonUsefulBytes.replace('\x0c', QString());
jsonUsefulBytes.replace('\x00', "");
jsonUsefulBytes.replace('\x0c', "");
return QString::fromUtf8(jsonUsefulBytes.trimmed());
}

View file

@ -120,7 +120,7 @@ public:
bool setVisible() { return setPictureVisible(); } // Please use setPictureVisible instead
// PREDEFINED PROPERTIES
QSize getSnapmaticResolution();
static QSize getSnapmaticResolution();
// SNAPMATIC DEFAULTS
bool isSnapmaticDefaultsEnforced();