Browse files

Merge branch 'keyboard-shortcuts'

  • Loading branch information...
2 parents 2d2b49b + 935357b commit a25d288ad3049da8608b4feed653dd4392164dad @MikeMcQuaid committed Jul 17, 2012
Showing with 48 additions and 1 deletion.
  1. +48 −1 qsearchfield_mac.mm
View
49 qsearchfield_mac.mm
@@ -28,6 +28,14 @@ of this software and associated documentation files (the "Software"), to deal
#import "Foundation/NSNotification.h"
#import "AppKit/NSSearchField.h"
+#include <QApplication>
+#include <QClipboard>
+
+#define KEYCODE_A 0
+#define KEYCODE_X 7
+#define KEYCODE_C 8
+#define KEYCODE_V 9
+
class QSearchFieldPrivate : public QObject
{
public:
@@ -83,11 +91,50 @@ -(void)controlTextDidEndEditing:(NSNotification*)notification {
}
@end
+@interface QocoaSearchField : NSSearchField
+-(BOOL)performKeyEquivalent:(NSEvent*)event;
+@end
+
+@implementation QocoaSearchField
+-(BOOL)performKeyEquivalent:(NSEvent*)event {
+ if ([event type] == NSKeyDown && [event modifierFlags] & NSCommandKeyMask)
+ {
+ const unsigned short keyCode = [event keyCode];
+ if (keyCode == KEYCODE_A)
+ {
+ [self performSelector:@selector(selectText:)];
+ return YES;
+ }
+ else if (keyCode == KEYCODE_C)
+ {
+ QClipboard* clipboard = QApplication::clipboard();
+ clipboard->setText(toQString([self stringValue]));
+ return YES;
+ }
+ else if (keyCode == KEYCODE_V)
+ {
+ QClipboard* clipboard = QApplication::clipboard();
+ [self setStringValue:fromQString(clipboard->text())];
+ return YES;
+ }
+ else if (keyCode == KEYCODE_X)
+ {
+ QClipboard* clipboard = QApplication::clipboard();
+ clipboard->setText(toQString([self stringValue]));
+ [self setStringValue:@""];
+ return YES;
+ }
+ }
+
+ return NO;
+}
+@end
+
QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSSearchField *search = [[NSSearchField alloc] init];
+ NSSearchField *search = [[QocoaSearchField alloc] init];
QSearchFieldDelegate *delegate = [[QSearchFieldDelegate alloc] init];
pimpl = delegate->pimpl = new QSearchFieldPrivate(this, search);

0 comments on commit a25d288

Please sign in to comment.