diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 9f9618177d..85d12040de 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -232,50 +232,37 @@ QString qt_mac_applicationName() return appName; } -int qt_mac_primaryScreenHeight() -{ - QMacAutoReleasePool pool; - NSArray *screens = [NSScreen screens]; - if ([screens count] > 0) { - // The first screen in the screens array is documented to - // have the (0,0) origin and is designated the primary screen. - NSRect screenFrame = [[screens objectAtIndex: 0] frame]; - return screenFrame.size.height; - } - return 0; -} +// ------------------------------------------------------------------------- -int qt_mac_flipYCoordinate(int y) -{ - return qt_mac_primaryScreenHeight() - y; -} +/*! + \fn QPointF qt_mac_flip(const QPointF &pos, const QRectF &reference) + \fn QRectF qt_mac_flip(const QRectF &rect, const QRectF &reference) -qreal qt_mac_flipYCoordinate(qreal y) -{ - return qt_mac_primaryScreenHeight() - y; -} + Flips the Y coordinate of the point/rect between quadrant I and IV. -QPointF qt_mac_flipPoint(const NSPoint &p) -{ - return QPointF(p.x, qt_mac_flipYCoordinate(p.y)); -} + The native coordinate system on macOS uses quadrant I, with origin + in bottom left, and Qt uses quadrant IV, with origin in top left. -NSPoint qt_mac_flipPoint(const QPoint &p) -{ - return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); -} + By flipping the Y coordinate, we can map the point/rect between + the two coordinate systems. -NSPoint qt_mac_flipPoint(const QPointF &p) + The flip is always in relation to a reference rectangle, e.g. + the frame of the parent view, or the screen geometry. In the + latter case the specialized QCocoaScreen::mapFrom/To functions + should be used instead. +*/ +QPointF qt_mac_flip(const QPointF &pos, const QRectF &reference) { - return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); + return QPointF(pos.x(), reference.height() - pos.y()); } -NSRect qt_mac_flipRect(const QRect &rect) +QRectF qt_mac_flip(const QRectF &rect, const QRectF &reference) { - int flippedY = qt_mac_flipYCoordinate(rect.y() + rect.height()); - return NSMakeRect(rect.x(), flippedY, rect.width(), rect.height()); + return QRectF(qt_mac_flip(rect.bottomLeft(), reference), rect.size()); } +// ------------------------------------------------------------------------- + Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) { if (buttonNum >= 0 && buttonNum <= 31) @@ -408,4 +395,19 @@ QT_END_NAMESPACE [super layout]; } +// ------------------------------------------------------------------------- + +io_object_t q_IOObjectRetain(io_object_t obj) +{ + kern_return_t ret = IOObjectRetain(obj); + Q_ASSERT(!ret); + return obj; +} + +void q_IOObjectRelease(io_object_t obj) +{ + kern_return_t ret = IOObjectRelease(obj); + Q_ASSERT(!ret); +} + @end |