diff options
author | Eimantas Vaiciunas <eimantas@walkingsmarts.com> | 2017-02-13 10:41:18 +0200 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-02-15 22:51:30 -0800 |
commit | d8bdc7307d77b73651ec1a81b33c4fb4ace60e7c (patch) | |
tree | 65f568a2ebc468353f305bb631940a76b68d337e /platform/macos/src | |
parent | 685f237d0286ef13aac52cbbab93fed82a0b31b8 (diff) | |
download | qtlocation-mapboxgl-d8bdc7307d77b73651ec1a81b33c4fb4ace60e7c.tar.gz |
[macos] Make + and - keys zoom the map
Override `insertText:`
- send all `keyDown:` events to `interpretKeyEvents:` method;
- in `insertText:` method check for the text to be sent and
adjust zoom level if needed;
Diffstat (limited to 'platform/macos/src')
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 654ca84fd0..98f4a0569d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1633,13 +1633,16 @@ public: #pragma mark Keyboard events - (void)keyDown:(NSEvent *)event { - if (event.modifierFlags & NSNumericPadKeyMask) { - // This is the recommended way to handle arrow key presses, causing - // methods like -moveUp: and -moveToBeginningOfParagraph: to be called - // for various standard keybindings. - [self interpretKeyEvents:@[event]]; + [self interpretKeyEvents:@[event]]; +} + +- (void)insertText:(NSString *)text { + BOOL textIsZoomCharacter = [@[@"-", @"=", @"+"] containsObject:text]; + + if (textIsZoomCharacter) { + [self adjustZoomLevelForKey:text]; } else { - [super keyDown:event]; + [super insertText:text]; } } @@ -1695,6 +1698,23 @@ public: _compass.hidden = !rotateEnabled; } +- (void)adjustZoomLevelForKey:(NSString *)key { + double newZoomLevel = self.zoomLevel; + unichar keyUnichar = [key characterAtIndex:0]; + switch(keyUnichar) { + case '-': { + newZoomLevel -= 1; + break; + } + case '=': + case '+': { + newZoomLevel += 1; + } + } + + [self setZoomLevel:newZoomLevel animated:YES]; +} + #pragma mark Ornaments /// Updates the zoom controls’ enabled state based on the current zoom level. |