QLabel QPixmap *pixmap() method is deprecated

const QPixmap should perform as fast as a pointer
there is a replacement version for Qt5 but it requires Qt5.15, so we are using indirection witch is unsafer but it should be ok as all the action is happen in the main thread
This commit is contained in:
Luis Ángel San Martín 2021-10-02 08:07:15 +02:00
parent 5fbd100449
commit a7e3c41f34
4 changed files with 25 additions and 20 deletions

View File

@ -38,9 +38,9 @@ void MagnifyingGlass::updateImage(int x, int y)
int zoomHeight = static_cast<int>(height() * zoomLevel);
auto p = (Viewer *)parent();
int currentPos = p->verticalScrollBar()->sliderPosition();
const QPixmap *image = p->pixmap();
int iWidth = image->width();
int iHeight = image->height();
const QPixmap image = p->pixmap();
int iWidth = image.width();
int iHeight = image.height();
float wFactor = static_cast<float>(iWidth) / p->widget()->width();
float hFactor = static_cast<float>(iHeight) / p->widget()->height();
zoomWidth *= wFactor;
@ -67,12 +67,12 @@ void MagnifyingGlass::updateImage(int x, int y)
outImage = true;
}
if (xp + zoomWidth >= image->width()) {
zw -= xp + zw - image->width();
if (xp + zoomWidth >= image.width()) {
zw -= xp + zw - image.width();
outImage = true;
}
if (yp + zoomHeight >= image->height()) {
zh -= yp + zh - image->height();
if (yp + zoomHeight >= image.height()) {
zh -= yp + zh - image.height();
outImage = true;
}
if (outImage) {
@ -81,11 +81,11 @@ void MagnifyingGlass::updateImage(int x, int y)
img.fill(Configuration::getConfiguration().getBackgroundColor());
if (zw > 0 && zh > 0) {
QPainter painter(&img);
painter.drawPixmap(xOffset, yOffset, image->copy(xp, yp, zw, zh));
painter.drawPixmap(xOffset, yOffset, image.copy(xp, yp, zw, zh));
}
setPixmap(QPixmap().fromImage(img));
} else
setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight));
setPixmap(image.copy(xp, yp, zoomWidth, zoomHeight));
} else {
int xp = static_cast<int>(((x - p->widget()->pos().x()) * wFactor) - zoomWidth / 2);
int yp = static_cast<int>((y + currentPos) * hFactor - zoomHeight / 2);
@ -108,12 +108,12 @@ void MagnifyingGlass::updateImage(int x, int y)
outImage = true;
}
if (xp + zoomWidth >= image->width()) {
zw -= xp + zw - image->width();
if (xp + zoomWidth >= image.width()) {
zw -= xp + zw - image.width();
outImage = true;
}
if (yp + zoomHeight >= image->height()) {
zh -= yp + zh - image->height();
if (yp + zoomHeight >= image.height()) {
zh -= yp + zh - image.height();
outImage = true;
}
if (outImage) {
@ -122,11 +122,11 @@ void MagnifyingGlass::updateImage(int x, int y)
img.fill(Configuration::getConfiguration().getBackgroundColor());
if (zw > 0 && zh > 0) {
QPainter painter(&img);
painter.drawPixmap(xOffset, yOffset, image->copy(xp, yp, zw, zh));
painter.drawPixmap(xOffset, yOffset, image.copy(xp, yp, zw, zh));
}
setPixmap(QPixmap().fromImage(img));
} else
setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight));
setPixmap(image.copy(xp, yp, zoomWidth, zoomHeight));
}
move(static_cast<int>(x - float(width()) / 2), static_cast<int>(y - float(height()) / 2));
}

View File

@ -978,9 +978,10 @@ void MainWindowViewer::saveImage()
if (!pathFile.isEmpty()) {
QFileInfo fi(pathFile);
currentDirectoryImgDest = fi.absolutePath();
const QPixmap *p = viewer->pixmap();
if (p != nullptr)
p->save(pathFile);
const QPixmap p = viewer->pixmap();
if (!p.isNull()) {
p.save(pathFile);
}
}
}

View File

@ -773,9 +773,13 @@ void Viewer::mouseMoveEvent(QMouseEvent *event)
}
}
const QPixmap *Viewer::pixmap()
const QPixmap Viewer::pixmap()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return content->pixmap();
#else
return *(content->pixmap());
#endif
}
void Viewer::magnifyingGlassSwitch()

View File

@ -178,7 +178,7 @@ private:
public:
Viewer(QWidget *parent = nullptr);
~Viewer();
const QPixmap *pixmap();
const QPixmap pixmap();
// Comic * getComic(){return comic;}
const BookmarksDialog *getBookmarksDialog() { return bd; }
// returns the current index starting in 1 [1,nPages]