Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/5.15' into dev
Browse files Browse the repository at this point in the history
 Conflicts:
	src/corelib/kernel/qmetatype.cpp

Change-Id: I88eb0d3e9c9a38abf7241a51e370c655ae74e38a
  • Loading branch information
tronical committed Mar 16, 2020
2 parents e464e1e + 75f52bd commit ff922e7
Show file tree
Hide file tree
Showing 140 changed files with 26,344 additions and 24,023 deletions.
25 changes: 19 additions & 6 deletions examples/corelib/threads/doc/src/mandelbrot.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
generate more and more precise (and computationally expensive)
approximations of the fractal.

We create a high resolution pixmap by applying the device
pixel ratio to the target size (see
\l{Drawing High Resolution Versions of Pixmaps and Images}).

If we discover inside the loop that \c restart has been set to \c
true (by \c render()), we break out of the loop immediately, so
that the control quickly returns to the very top of the outer
Expand Down Expand Up @@ -273,12 +277,21 @@
\snippet threads/mandelbrot/mandelbrotwidget.cpp 8

If the pixmap has the right scale factor, we draw the pixmap directly onto
the widget. Otherwise, we scale and translate the \l{Coordinate
System}{coordinate system} before we draw the pixmap. By reverse mapping
the widget's rectangle using the scaled painter matrix, we also make sure
that only the exposed areas of the pixmap are drawn. The calls to
QPainter::save() and QPainter::restore() make sure that any painting
performed afterwards uses the standard coordinate system.
the widget.

Otherwise, we create a preview pixmap to be shown until the calculation
finishes and translate the \l{Coordinate System}{coordinate system}
accordingly.

Since we are going to use transformations on the painter
and use an overload of QPainter::drawPixmap() that does not support
high resolution pixmaps in that case, we create a pixmap with device pixel
ratio 1.

By reverse mapping the widget's rectangle using the scaled painter matrix,
we also make sure that only the exposed areas of the pixmap are drawn.
The calls to QPainter::save() and QPainter::restore() make sure that any
painting performed afterwards uses the standard coordinate system.

\snippet threads/mandelbrot/mandelbrotwidget.cpp 9

Expand Down
2 changes: 2 additions & 0 deletions examples/corelib/threads/mandelbrot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
//! [0]
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication app(argc, argv);
MandelbrotWidget widget;
widget.show();
Expand Down
25 changes: 15 additions & 10 deletions examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,22 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
//! [6] //! [7]
} else {
//! [7] //! [8]
auto previewPixmap = qFuzzyCompare(pixmap.devicePixelRatioF(), qreal(1))
? pixmap
: pixmap.scaled(pixmap.size() / pixmap.devicePixelRatioF(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
double scaleFactor = pixmapScale / curScale;
int newWidth = int(pixmap.width() * scaleFactor);
int newHeight = int(pixmap.height() * scaleFactor);
int newX = pixmapOffset.x() + (pixmap.width() - newWidth) / 2;
int newY = pixmapOffset.y() + (pixmap.height() - newHeight) / 2;
int newWidth = int(previewPixmap.width() * scaleFactor);
int newHeight = int(previewPixmap.height() * scaleFactor);
int newX = pixmapOffset.x() + (previewPixmap.width() - newWidth) / 2;
int newY = pixmapOffset.y() + (previewPixmap.height() - newHeight) / 2;

painter.save();
painter.translate(newX, newY);
painter.scale(scaleFactor, scaleFactor);

QRectF exposed = painter.transform().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
painter.drawPixmap(exposed, pixmap, exposed);
painter.drawPixmap(exposed, previewPixmap, exposed);
painter.restore();
}
//! [8] //! [9]
Expand All @@ -139,7 +143,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
//! [10]
void MandelbrotWidget::resizeEvent(QResizeEvent * /* event */)
{
thread.render(centerX, centerY, curScale, size());
thread.render(centerX, centerY, curScale, size(), devicePixelRatioF());
}
//! [10]

Expand Down Expand Up @@ -208,8 +212,9 @@ void MandelbrotWidget::mouseReleaseEvent(QMouseEvent *event)
pixmapOffset += event->pos() - lastDragPos;
lastDragPos = QPoint();

int deltaX = (width() - pixmap.width()) / 2 - pixmapOffset.x();
int deltaY = (height() - pixmap.height()) / 2 - pixmapOffset.y();
const auto pixmapSize = pixmap.size() / pixmap.devicePixelRatioF();
int deltaX = (width() - pixmapSize.width()) / 2 - pixmapOffset.x();
int deltaY = (height() - pixmapSize.height()) / 2 - pixmapOffset.y();
scroll(deltaX, deltaY);
}
}
Expand All @@ -234,7 +239,7 @@ void MandelbrotWidget::zoom(double zoomFactor)
{
curScale *= zoomFactor;
update();
thread.render(centerX, centerY, curScale, size());
thread.render(centerX, centerY, curScale, size(), devicePixelRatioF());
}
//! [17]

Expand All @@ -244,6 +249,6 @@ void MandelbrotWidget::scroll(int deltaX, int deltaY)
centerX += deltaX * curScale;
centerY += deltaY * curScale;
update();
thread.render(centerX, centerY, curScale, size());
thread.render(centerX, centerY, curScale, size(), devicePixelRatioF());
}
//! [18]
12 changes: 8 additions & 4 deletions examples/corelib/threads/mandelbrot/renderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ RenderThread::~RenderThread()

//! [2]
void RenderThread::render(double centerX, double centerY, double scaleFactor,
QSize resultSize)
QSize resultSize, double devicePixelRatio)
{
QMutexLocker locker(&mutex);

this->centerX = centerX;
this->centerY = centerY;
this->scaleFactor = scaleFactor;
this->devicePixelRatio = devicePixelRatio;
this->resultSize = resultSize;

if (!isRunning()) {
Expand All @@ -99,8 +100,10 @@ void RenderThread::run()
{
forever {
mutex.lock();
const QSize resultSize = this->resultSize;
const double scaleFactor = this->scaleFactor;
const double devicePixelRatio = this->devicePixelRatio;
const QSize resultSize = this->resultSize * devicePixelRatio;
const double requestedScaleFactor = this->scaleFactor;
const double scaleFactor = requestedScaleFactor / devicePixelRatio;
const double centerX = this->centerX;
const double centerY = this->centerY;
mutex.unlock();
Expand All @@ -111,6 +114,7 @@ void RenderThread::run()
//! [4] //! [5]
int halfHeight = resultSize.height() / 2;
QImage image(resultSize, QImage::Format_RGB32);
image.setDevicePixelRatio(devicePixelRatio);

const int NumPasses = 8;
int pass = 0;
Expand Down Expand Up @@ -162,7 +166,7 @@ void RenderThread::run()
pass = 4;
} else {
if (!restart)
emit renderedImage(image, scaleFactor);
emit renderedImage(image, requestedScaleFactor);
//! [5] //! [6]
++pass;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/corelib/threads/mandelbrot/renderthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class RenderThread : public QThread
RenderThread(QObject *parent = nullptr);
~RenderThread();

void render(double centerX, double centerY, double scaleFactor, QSize resultSize);
void render(double centerX, double centerY, double scaleFactor, QSize resultSize,
double devicePixelRatio);

signals:
void renderedImage(const QImage &image, double scaleFactor);
Expand All @@ -85,6 +86,7 @@ class RenderThread : public QThread
double centerX;
double centerY;
double scaleFactor;
double devicePixelRatio;
QSize resultSize;
bool restart = false;
bool abort = false;
Expand Down
12 changes: 9 additions & 3 deletions examples/widgets/itemviews/spreadsheet/printview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@

#include "printview.h"

#ifndef QT_NO_PRINTER
#include <QPrinter>
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>

# if QT_CONFIG(printer)
# include <QPrinter>
# endif
#endif

PrintView::PrintView()
Expand All @@ -62,9 +66,11 @@ PrintView::PrintView()

void PrintView::print(QPrinter *printer)
{
#ifndef QT_NO_PRINTER
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
resize(printer->width(), printer->height());
render(printer);
#else
Q_UNUSED(printer)
#endif
}

2 changes: 1 addition & 1 deletion examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ QString encode_pos(int row, int col)

void SpreadSheet::print()
{
#if QT_CONFIG(printpreviewdialog)
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printpreviewdialog)
QPrinter printer(QPrinter::ScreenResolution);
QPrintPreviewDialog dlg(&printer);
PrintView view;
Expand Down
12 changes: 6 additions & 6 deletions examples/widgets/richtext/textedit/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void TextEdit::setupFileActions()
a->setPriority(QAction::LowPriority);
menu->addSeparator();

#ifndef QT_NO_PRINTER
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
const QIcon printIcon = QIcon::fromTheme("document-print", QIcon(rsrcPath + "/fileprint.png"));
a = menu->addAction(printIcon, tr("&Print..."), this, &TextEdit::filePrint);
a->setPriority(QAction::LowPriority);
Expand Down Expand Up @@ -559,7 +559,7 @@ void TextEdit::filePrint()

void TextEdit::filePrintPreview()
{
#if QT_CONFIG(printpreviewdialog)
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printpreviewdialog)
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this);
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &TextEdit::printPreview);
Expand All @@ -569,17 +569,17 @@ void TextEdit::filePrintPreview()

void TextEdit::printPreview(QPrinter *printer)
{
#ifdef QT_NO_PRINTER
Q_UNUSED(printer);
#else
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
textEdit->print(printer);
#else
Q_UNUSED(printer)
#endif
}


void TextEdit::filePrintPdf()
{
#ifndef QT_NO_PRINTER
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
//! [0]
QFileDialog fileDialog(this, tr("Export PDF"));
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
Expand Down
2 changes: 2 additions & 0 deletions examples/widgets/tutorials/notepad/notepad.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
TEMPLATE = app
TARGET = notepad

QT += widgets

qtHaveModule(printsupport): QT += printsupport
requires(qtConfig(fontdialog))

Expand Down
9 changes: 5 additions & 4 deletions examples/widgets/widgets/imageviewer/imageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@
#include <QStatusBar>

#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
#include <QPrintDialog>
#endif
# include <QtPrintSupport/qtprintsupportglobal.h>

# if QT_CONFIG(printdialog)
# include <QPrintDialog>
# endif
#endif

//! [0]
Expand Down
10 changes: 7 additions & 3 deletions examples/widgets/widgets/imageviewer/imageviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@

#include <QMainWindow>
#include <QImage>
#ifndef QT_NO_PRINTER
#include <QPrinter>
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>

# if QT_CONFIG(printer)
# include <QPrinter>
# endif
#endif

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -100,7 +104,7 @@ private slots:
QScrollArea *scrollArea;
double scaleFactor = 1;

#ifndef QT_NO_PRINTER
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer;
#endif

Expand Down
7 changes: 1 addition & 6 deletions qmake/Makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ QOBJS = \
$(QTOBJS) $(QTOBJS2)
# QTOBJS and QTOBJS2 are populated by Makefile.unix.* as for QTSRC (see below).
# Note: qlibraryinfo.o omitted deliberately - see below.
# Note: qcore_mac_objc.o is in SOURCES (see qmake.pri) but not QOBJS.

#all sources, used for the depend target (please keep alphabetic in each block)
DEPEND_SRC = \
Expand Down Expand Up @@ -92,7 +91,6 @@ DEPEND_SRC = \
$(SOURCE_PATH)/src/corelib/io/qiodevice.cpp \
$(SOURCE_PATH)/src/corelib/io/qsettings.cpp \
$(SOURCE_PATH)/src/corelib/io/qtemporaryfile.cpp \
$(SOURCE_PATH)/src/corelib/kernel/qcore_mac_objc.mm \
$(SOURCE_PATH)/src/corelib/kernel/qmetatype.cpp \
$(SOURCE_PATH)/src/corelib/kernel/qsystemerror.cpp \
$(SOURCE_PATH)/src/corelib/kernel/qvariant.cpp \
Expand Down Expand Up @@ -325,7 +323,7 @@ qbytearraymatcher.o: $(SOURCE_PATH)/src/corelib/text/qbytearraymatcher.cpp
qmetatype.o: $(SOURCE_PATH)/src/corelib/kernel/qmetatype.cpp
$(CXX) -c -o $@ $(CXXFLAGS) $<

qcore_mac.o: $(SOURCE_PATH)/src/corelib/kernel/qcore_mac.cpp
qcore_mac.o: $(SOURCE_PATH)/src/corelib/kernel/qcore_mac.mm
$(CXX) -c -o $@ $(CXXFLAGS) $<

qcore_unix.o: $(SOURCE_PATH)/src/corelib/kernel/qcore_unix.cpp
Expand All @@ -340,9 +338,6 @@ qoperatingsystemversion_win.o: $(SOURCE_PATH)/src/corelib/global/qoperatingsyste
qoperatingsystemversion_darwin.o: $(SOURCE_PATH)/src/corelib/global/qoperatingsystemversion_darwin.mm
$(CXX) -c -o $@ $(CXXFLAGS) $<

qcore_mac_objc.o: $(SOURCE_PATH)/src/corelib/kernel/qcore_mac_objc.mm
$(CXX) -c -o $@ $(CXXFLAGS) $<

qcore_foundation.o: $(SOURCE_PATH)/src/corelib/kernel/qcore_foundation.mm
$(CXX) -c -o $@ $(CXXFLAGS) $<

Expand Down
2 changes: 1 addition & 1 deletion qmake/Makefile.unix.macos
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ QTOBJS2 = \
qcore_foundation.o
QTSRCS2 = \
$(SOURCE_PATH)/src/corelib/io/qsettings_mac.cpp \
$(SOURCE_PATH)/src/corelib/kernel/qcore_mac.cpp \
$(SOURCE_PATH)/src/corelib/kernel/qcore_mac.mm \
$(SOURCE_PATH)/src/corelib/global/qoperatingsystemversion_darwin.mm \
$(SOURCE_PATH)/src/corelib/kernel/qcore_foundation.mm
Loading

0 comments on commit ff922e7

Please sign in to comment.