Fix default hotspot of a hidpi QCursor
The hotspot is defined in device independent coordinates, so the default coordinates need to be divided by device pixel ratio. Also, modify the scaling of cursor's pixmap to use SmoothTransformation to generate cleaner looking lodpi cursors from hidpi cursors. Change-Id: Ia938fd1e476e19e796f30712e23b06a5efed9964 Task-number: QTBUG-34116 Reviewed-by: Jake Petroules <jake.petroules@theqtcompany.com>
This commit is contained in:
parent
cb12da0387
commit
6413ceeccf
@ -387,7 +387,7 @@ QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)
|
||||
bmm.fill(Qt::color1);
|
||||
}
|
||||
|
||||
d = QCursorData::setBitmap(bm, bmm, hotX, hotY);
|
||||
d = QCursorData::setBitmap(bm, bmm, hotX, hotY, pixmap.devicePixelRatio());
|
||||
d->pixmap = pixmap;
|
||||
}
|
||||
|
||||
@ -430,7 +430,7 @@ QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)
|
||||
QCursor::QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
|
||||
: d(0)
|
||||
{
|
||||
d = QCursorData::setBitmap(bitmap, mask, hotX, hotY);
|
||||
d = QCursorData::setBitmap(bitmap, mask, hotX, hotY, 1.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -650,7 +650,7 @@ void QCursorData::initialize()
|
||||
QCursorData::initialized = true;
|
||||
}
|
||||
|
||||
QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
|
||||
QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio)
|
||||
{
|
||||
if (!QCursorData::initialized)
|
||||
QCursorData::initialize();
|
||||
@ -664,8 +664,8 @@ QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask,
|
||||
d->bm = new QBitmap(bitmap);
|
||||
d->bmm = new QBitmap(mask);
|
||||
d->cshape = Qt::BitmapCursor;
|
||||
d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
|
||||
d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
|
||||
d->hx = hotX >= 0 ? hotX : bitmap.width() / 2 / devicePixelRatio;
|
||||
d->hy = hotY >= 0 ? hotY : bitmap.height() / 2 / devicePixelRatio;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
@ -70,7 +70,8 @@ public:
|
||||
short hx, hy;
|
||||
static bool initialized;
|
||||
void update();
|
||||
static QCursorData *setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY);
|
||||
static QCursorData *setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY,
|
||||
qreal devicePixelRatio);
|
||||
};
|
||||
|
||||
extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
|
||||
|
@ -304,7 +304,7 @@ NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoin
|
||||
NSImage *nsimage;
|
||||
if (pixmap.devicePixelRatio() > 1.0) {
|
||||
QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio();
|
||||
QPixmap scaledPixmap = pixmap.scaled(layoutSize);
|
||||
QPixmap scaledPixmap = pixmap.scaled(layoutSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(scaledPixmap));
|
||||
CGImageRef cgImage = qt_mac_toCGImage(pixmap.toImage());
|
||||
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
|
||||
|
Loading…
Reference in New Issue
Block a user