From 4a240bb67e72b34c80af448e0a74846609fa6975 Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Thu, 1 Sep 2016 14:26:18 +0200 Subject: QTextDocument: Fix device scaling for QTextFrameFormat margins, padding and border Those values must be scaled to device coordinates - otherwise borders, margins etc. will be too small when rendered on high dpi devices (printers etc.). This change will add the scaling to those values. QTextDocument::print applies 2cm margins to the root frame of a unpaginated QTextDocument. Those margins were previously scaled to device coordinates in order to give the correct result. But because scaling is now done inside QTextDocumentLayout that scaling must be removed and pixel values based on qt_defaultDpi are provided instead. Fixes: QTBUG-78318 Change-Id: I6fe6dcc25f846341f6a2fe5df2f54baea473fdfd Reviewed-by: Shawn Rutledge --- src/gui/text/qtextdocument.cpp | 26 ++++++++++++++++---------- src/gui/text/qtextdocumentlayout.cpp | 12 ++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/gui') diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 3652a180a8..22c249d604 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1970,9 +1970,12 @@ void QTextDocument::print(QPagedPaintDevice *printer) const QRectF body = QRectF(QPointF(0, 0), d->pageSize); QPointF pageNumberPos; + qreal sourceDpiX = qt_defaultDpiX(); + qreal sourceDpiY = qt_defaultDpiY(); + const qreal dpiScaleX = qreal(printer->logicalDpiX()) / sourceDpiX; + const qreal dpiScaleY = qreal(printer->logicalDpiY()) / sourceDpiY; + if (documentPaginated) { - qreal sourceDpiX = qt_defaultDpi(); - qreal sourceDpiY = sourceDpiX; QPaintDevice *dev = doc->documentLayout()->paintDevice(); if (dev) { @@ -1980,9 +1983,6 @@ void QTextDocument::print(QPagedPaintDevice *printer) const sourceDpiY = dev->logicalDpiY(); } - const qreal dpiScaleX = qreal(printer->logicalDpiX()) / sourceDpiX; - const qreal dpiScaleY = qreal(printer->logicalDpiY()) / sourceDpiY; - // scale to dpi p.scale(dpiScaleX, dpiScaleY); @@ -2011,15 +2011,21 @@ void QTextDocument::print(QPagedPaintDevice *printer) const // copy the custom object handlers layout->d_func()->handlers = documentLayout()->d_func()->handlers; - int dpiy = p.device()->logicalDpiY(); - int margin = (int) ((2/2.54)*dpiy); // 2 cm margins + // 2 cm margins, scaled to device in QTextDocumentLayoutPrivate::layoutFrame + const int horizontalMargin = int((2/2.54)*sourceDpiX); + const int verticalMargin = int((2/2.54)*sourceDpiY); QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); - fmt.setMargin(margin); + fmt.setLeftMargin(horizontalMargin); + fmt.setRightMargin(horizontalMargin); + fmt.setTopMargin(verticalMargin); + fmt.setBottomMargin(verticalMargin); doc->rootFrame()->setFrameFormat(fmt); + // pageNumberPos must be in device coordinates, so scale to device here + const int dpiy = p.device()->logicalDpiY(); body = QRectF(0, 0, printer->width(), printer->height()); - pageNumberPos = QPointF(body.width() - margin, - body.height() - margin + pageNumberPos = QPointF(body.width() - horizontalMargin * dpiScaleX, + body.height() - verticalMargin * dpiScaleY + QFontMetrics(doc->defaultFont(), p.device()).ascent() + 5 * dpiy / 72.0); clonedDoc->setPageSize(body.size()); diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index b02723c047..a9a177da8b 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -2915,24 +2915,24 @@ QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, in { QTextFrameFormat fformat = f->frameFormat(); // set sizes of this frame from the format - QFixed tm = QFixed::fromReal(fformat.topMargin()); + QFixed tm = QFixed::fromReal(scaleToDevice(fformat.topMargin())).round(); if (tm != fd->topMargin) { fd->topMargin = tm; fullLayout = true; } - QFixed bm = QFixed::fromReal(fformat.bottomMargin()); + QFixed bm = QFixed::fromReal(scaleToDevice(fformat.bottomMargin())).round(); if (bm != fd->bottomMargin) { fd->bottomMargin = bm; fullLayout = true; } - fd->leftMargin = QFixed::fromReal(fformat.leftMargin()); - fd->rightMargin = QFixed::fromReal(fformat.rightMargin()); - QFixed b = QFixed::fromReal(fformat.border()); + fd->leftMargin = QFixed::fromReal(scaleToDevice(fformat.leftMargin())).round(); + fd->rightMargin = QFixed::fromReal(scaleToDevice(fformat.rightMargin())).round(); + QFixed b = QFixed::fromReal(scaleToDevice(fformat.border())).round(); if (b != fd->border) { fd->border = b; fullLayout = true; } - QFixed p = QFixed::fromReal(fformat.padding()); + QFixed p = QFixed::fromReal(scaleToDevice(fformat.padding())).round(); if (p != fd->padding) { fd->padding = p; fullLayout = true; -- cgit v1.2.3 From 217dd1b3b03cd40b4bb926631464c684f7f84a69 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 16 Sep 2019 13:55:57 +0200 Subject: Mark stationary touch points as updated if pressure or velocity changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to inform Qt Quick when a stationary touchpoint is delivered that it is because of a changed property. Qt Quick still needs to avoid delivering item-customized events (with only the touch points that occur inside the item) that contain only stationary touch points without changed properties. To be able to check this private flag, QQuickPointerTouchEvent needs to be a friend. Task-number: QTBUG-77142 Change-Id: I6ee0dffbbeca9e513c77227b757252e2eec6a4ef Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qevent.h | 1 + src/gui/kernel/qevent_p.h | 4 +++- src/gui/kernel/qguiapplication.cpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index b73d90529a..bf00d4a9a3 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -959,6 +959,7 @@ public: friend class QGuiApplicationPrivate; friend class QApplication; friend class QApplicationPrivate; + friend class QQuickPointerTouchEvent; }; #if QT_DEPRECATED_SINCE(5, 0) diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index c2d8bd72b9..b7645496f8 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -67,7 +67,8 @@ public: state(Qt::TouchPointReleased), pressure(-1), rotation(0), - ellipseDiameters(0, 0) + ellipseDiameters(0, 0), + stationaryWithModifiedProperty(false) { } inline QTouchEventTouchPointPrivate *detach() @@ -91,6 +92,7 @@ public: QSizeF ellipseDiameters; QVector2D velocity; QTouchEvent::TouchPoint::InfoFlags flags; + bool stationaryWithModifiedProperty : 1; QVector rawScreenPositions; }; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a3ef3b2314..83ca337aaa 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2843,10 +2843,12 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To if (touchPoint.state() == Qt::TouchPointStationary) { if (touchInfo.touchPoint.velocity() != touchPoint.velocity()) { touchInfo.touchPoint.setVelocity(touchPoint.velocity()); + touchPoint.d->stationaryWithModifiedProperty = true; stationaryTouchPointChangedProperty = true; } if (!qFuzzyCompare(touchInfo.touchPoint.pressure(), touchPoint.pressure())) { touchInfo.touchPoint.setPressure(touchPoint.pressure()); + touchPoint.d->stationaryWithModifiedProperty = true; stationaryTouchPointChangedProperty = true; } } else { -- cgit v1.2.3 From 7db335a77e9efcfc8e0d4c1bd0834100403ec3b1 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 9 Sep 2019 13:13:34 +0200 Subject: Add back QWheelEvent position() and globalPosition() docs Change 7d29807296cb7ccc7f3459e106d74f93a321c493 removed the docs for the obsolete pos() and globalPos() accessors, but the text should have been reused to document their replacements. Change-Id: If4d64e0f07666a99d9a0a4f0de9fca42d3acf0f8 Reviewed-by: Sona Kurazyan --- src/gui/kernel/qevent.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/gui') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 616cca1422..d41e3e5e3c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -931,6 +931,30 @@ QWheelEvent::~QWheelEvent() \endlist */ +/*! + \fn QPoint QWheelEvent::position() const + + Returns the position of the mouse cursor relative to the widget + that received the event. + + If you move your widgets around in response to mouse events, + use globalPosition() instead of this function. + + \sa globalPosition() +*/ + +/*! + \fn QPoint QWheelEvent::globalPosition() const + + Returns the global position of the mouse pointer \e{at the time + of the event}. This is important on asynchronous window systems + such as X11; whenever you move your widgets around in response to + mouse events, globalPosition() can differ a lot from the current + cursor position returned by QCursor::pos(). + + \sa position() +*/ + #if QT_DEPRECATED_SINCE(5, 15) /*! \fn int QWheelEvent::delta() const -- cgit v1.2.3 From 6096f9d0d5931405d142119e6e357f0fd6552e90 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 16 Sep 2019 15:39:13 +0200 Subject: Another load() -> loadRelaxed() Change-Id: Iab74325da3bd0a22c1f69856b038d0b5615e4e63 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Marc Mutz --- src/gui/rhi/qshaderdescription.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/rhi/qshaderdescription.cpp b/src/gui/rhi/qshaderdescription.cpp index c38a83c497..179d5f3a07 100644 --- a/src/gui/rhi/qshaderdescription.cpp +++ b/src/gui/rhi/qshaderdescription.cpp @@ -1022,7 +1022,7 @@ void QShaderDescriptionPrivate::loadDoc(const QJsonDocument &doc) return; } - Q_ASSERT(ref.load() == 1); // must be detached + Q_ASSERT(ref.loadRelaxed() == 1); // must be detached inVars.clear(); outVars.clear(); -- cgit v1.2.3