diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-01-21 15:23:26 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-22 16:48:40 +0100 |
commit | b077e67fd2538bc972eb5f050c7e0d28681a30ca (patch) | |
tree | 57b02e266fe7e320ee0b019d2c61f2547fee0fce /src/plugins/platforms/cocoa/qnsview.mm | |
parent | 5e5bc779c3e3099159503f989de6baf589ea90d7 (diff) |
Cocoa: Backport Qt 4's QCocoaView tracking areas into QNSView
Task-number: QTBUG-29153
Change-Id: Ib190c074defaa459a8acc738f09af4a65e5d91d1
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 678f88baa0..5060d7dc25 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -472,6 +472,39 @@ static QTouchDevice *touchDevice = 0; [self handleMouseEvent:theEvent]; } +- (void)updateTrackingAreas +{ + [super updateTrackingAreas]; + + // [NSView addTrackingArea] is slow, so bail out early if we can: + if (NSIsEmptyRect([self visibleRect])) + return; + + QCocoaAutoReleasePool pool; + if (NSArray *trackingArray = [self trackingAreas]) { + NSUInteger size = [trackingArray count]; + for (NSUInteger i = 0; i < size; ++i) { + NSTrackingArea *t = [trackingArray objectAtIndex:i]; + [self removeTrackingArea:t]; + } + } + + // Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should + // only be turned on if mouseTracking, hover is on or a tool tip is set. + // Unfortunately, Qt will send "tooltip" events on mouse moves, so we need to + // turn it on in ALL case. That means EVERY QCocoaView gets to pay the cost of + // mouse moves delivered to it (Apple recommends keeping it OFF because there + // is a performance hit). So it goes. + NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp + | NSTrackingInVisibleRect | NSTrackingMouseMoved; + NSTrackingArea *ta = [[[NSTrackingArea alloc] initWithRect:[self frame] + options:trackingOptions + owner:self + userInfo:nil] + autorelease]; + [self addTrackingArea:ta]; +} + - (void)mouseMoved:(NSEvent *)theEvent { [self handleMouseEvent:theEvent]; |