diff --git a/signalplotter/ksignalplotter.cpp b/signalplotter/ksignalplotter.cpp --- a/signalplotter/ksignalplotter.cpp +++ b/signalplotter/ksignalplotter.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #ifdef GRAPHICS_SIGNAL_PLOTTER @@ -676,18 +677,23 @@ //We draw the pixmap in two halves, wrapping around the window if(mScrollOffset > 1) { + const auto dpr = mScrollableImage.devicePixelRatio(); + const QPointF point = boundingBox.topRight() - QPointF(mScrollOffset - 2, 0); + const QRectF sourceRect(0, 0, (mScrollOffset - 1) * dpr, boundingBox.height() * dpr); #ifdef USE_QIMAGE - p->drawImage(boundingBox.right() - mScrollOffset+2, boundingBox.top(), mScrollableImage, 0, 0, mScrollOffset-1, boundingBox.height()); + p->drawImage(point, mScrollableImage, sourceRect); #else - p->drawPixmap(boundingBox.right() - mScrollOffset+2, boundingBox.top(), mScrollableImage, 0, 0, mScrollOffset-1, boundingBox.height()); + p->drawPixmap(point, mScrollableImage, sourceRect); #endif } int widthOfSecondHalf = boundingBox.width() - mScrollOffset + 1; if(widthOfSecondHalf > 0) { + const auto dpr = mScrollableImage.devicePixelRatio(); + const QRectF sourceRect(mScrollableImage.width() - (widthOfSecondHalf + 1) * dpr, 0, widthOfSecondHalf * dpr, boundingBox.height() * dpr); #ifdef USE_QIMAGE - p->drawImage(boundingBox.left(), boundingBox.top(), mScrollableImage, mScrollableImage.width() - widthOfSecondHalf-1, 0, widthOfSecondHalf, boundingBox.height()); + p->drawImage(boundingBox.topLeft(), mScrollableImage, sourceRect); #else - p->drawPixmap(boundingBox.left(), boundingBox.top(), mScrollableImage, mScrollableImage.width() - widthOfSecondHalf-1, 0, widthOfSecondHalf, boundingBox.height()); + p->drawPixmap(boundingBox.topLeft(), mScrollableImage, sourceRect); #endif } @@ -747,20 +753,23 @@ //Align width of bounding box to the size of the horizontal scale int alignedWidth = ((mPlottingArea.width() + 1) / mHorizontalScale + 1) * mHorizontalScale; //Redraw the whole thing + const auto dpr = qApp->devicePixelRatio(); + const QSize size = QSize(alignedWidth, mPlottingArea.height()); #ifdef USE_QIMAGE - mScrollableImage = QImage(alignedWidth, mPlottingArea.height(),QImage::Format_ARGB32_Premultiplied); + mScrollableImage = QImage(size * dpr, QImage::Format_ARGB32_Premultiplied); #else - mScrollableImage = QPixmap(alignedWidth, mPlottingArea.height()); + mScrollableImage = QPixmap(size * dpr); #endif Q_ASSERT(!mScrollableImage.isNull()); + mScrollableImage.setDevicePixelRatio(dpr); mScrollOffset = 0; mVerticalLinesOffset = mVerticalLinesDistance - mHorizontalScale+1; // mVerticalLinesDistance - alignedWidth % mVerticalLinesDistance; //We need to draw the background for areas without a beam int withoutBeamWidth = qMax(mBeamData.size()-1, 0) * mHorizontalScale; QPainter pCache(&mScrollableImage); - if(withoutBeamWidth < mScrollableImage.width()) - drawBackground(&pCache, QRect(withoutBeamWidth, 0, alignedWidth - withoutBeamWidth, mScrollableImage.height())); + if(withoutBeamWidth < size.width()) + drawBackground(&pCache, QRect(withoutBeamWidth, 0, alignedWidth - withoutBeamWidth, size.height())); /* Draw scope-like grid vertical lines */ mVerticalLinesOffset = 0; @@ -865,14 +874,15 @@ void KSignalPlotterPrivate::drawBeamToScrollableImage(QPainter *p, int index) { - QRect cacheBoundingBox = QRect(mScrollOffset, 0, mHorizontalScale, mScrollableImage.height()); + const QSize dipSize = mScrollableImage.size() / mScrollableImage.devicePixelRatio(); + QRect cacheBoundingBox = QRect(mScrollOffset, 0, mHorizontalScale, dipSize.height()); drawBackground(p, cacheBoundingBox); drawBeam(p, cacheBoundingBox, mHorizontalScale, index); mScrollOffset += mHorizontalScale; mVerticalLinesOffset = (mVerticalLinesOffset + mHorizontalScale) % mVerticalLinesDistance; - if(mScrollOffset >= mScrollableImage.width()-1) { + if(mScrollOffset >= dipSize.width()-1) { mScrollOffset = 0; mVerticalLinesOffset--; //We skip over the last pixel drawn } @@ -882,10 +892,11 @@ { if(mNiceRange == 0) return; QPen pen; + const auto dpr = qApp->devicePixelRatio(); if(mHorizontalScale == 1) //Don't use a pen width of 2 if there's only 1 pixel between points - pen.setWidth(1); + pen.setWidth(1.0 / dpr); else - pen.setWidth(2); + pen.setWidth(2.0 / dpr); pen.setCapStyle(Qt::FlatCap);