summaryrefslogtreecommitdiff
path: root/platform/macos/src
diff options
context:
space:
mode:
authorEimantas Vaiciunas <eimantas@walkingsmarts.com>2017-02-13 10:41:18 +0200
committerMinh Nguyễn <mxn@1ec5.org>2017-02-15 22:51:30 -0800
commitd8bdc7307d77b73651ec1a81b33c4fb4ace60e7c (patch)
tree65f568a2ebc468353f305bb631940a76b68d337e /platform/macos/src
parent685f237d0286ef13aac52cbbab93fed82a0b31b8 (diff)
downloadqtlocation-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.mm32
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.