Fix qocoa mac build
This commit is contained in:
parent
1119c87b2f
commit
9e4f3f9867
327
3rdparty/qocoa/qsearchfield_mac.mm
vendored
327
3rdparty/qocoa/qsearchfield_mac.mm
vendored
@ -32,57 +32,50 @@ THE SOFTWARE.
|
|||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
|
||||||
class QSearchFieldPrivate : public QObject
|
class QSearchFieldPrivate : public QObject {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
QSearchFieldPrivate(QSearchField *qSearchField, NSSearchField *nsSearchField)
|
QSearchFieldPrivate(QSearchField *qSearchField, NSSearchField *nsSearchField)
|
||||||
: QObject(qSearchField), qSearchField(qSearchField), nsSearchField(nsSearchField) {}
|
: QObject(qSearchField), qSearchField(qSearchField), nsSearchField(nsSearchField) {}
|
||||||
|
|
||||||
void textDidChange(const QString &text)
|
void textDidChange(const QString &text) {
|
||||||
{
|
if (qSearchField) emit qSearchField->textChanged(text);
|
||||||
if (qSearchField)
|
}
|
||||||
emit qSearchField->textChanged(text);
|
|
||||||
|
void textDidEndEditing() {
|
||||||
|
if (qSearchField)
|
||||||
|
emit qSearchField->editingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void textDidEndEditing()
|
void returnPressed() {
|
||||||
{
|
if (qSearchField) {
|
||||||
if (qSearchField)
|
emit qSearchField->returnPressed();
|
||||||
emit qSearchField->editingFinished();
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
||||||
|
QApplication::postEvent(qSearchField, event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void returnPressed()
|
void keyDownPressed() {
|
||||||
{
|
if (qSearchField) {
|
||||||
if (qSearchField) {
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
|
||||||
emit qSearchField->returnPressed();
|
QApplication::postEvent(qSearchField, event);
|
||||||
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
|
||||||
QApplication::postEvent(qSearchField, event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void keyDownPressed()
|
void keyUpPressed() {
|
||||||
{
|
if (qSearchField) {
|
||||||
if (qSearchField) {
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);
|
||||||
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
|
QApplication::postEvent(qSearchField, event);
|
||||||
QApplication::postEvent(qSearchField, event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void keyUpPressed()
|
QPointer<QSearchField> qSearchField;
|
||||||
{
|
NSSearchField *nsSearchField;
|
||||||
if (qSearchField) {
|
|
||||||
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);
|
|
||||||
QApplication::postEvent(qSearchField, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointer<QSearchField> qSearchField;
|
|
||||||
NSSearchField *nsSearchField;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface QSearchFieldDelegate : NSObject<NSTextFieldDelegate>
|
@interface QSearchFieldDelegate : NSObject<NSTextFieldDelegate> {
|
||||||
{
|
|
||||||
@public
|
@public
|
||||||
QPointer<QSearchFieldPrivate> pimpl;
|
QPointer<QSearchFieldPrivate> pimpl;
|
||||||
}
|
}
|
||||||
-(void)controlTextDidChange:(NSNotification*)notification;
|
-(void)controlTextDidChange:(NSNotification*)notification;
|
||||||
-(void)controlTextDidEndEditing:(NSNotification*)notification;
|
-(void)controlTextDidEndEditing:(NSNotification*)notification;
|
||||||
@ -90,35 +83,33 @@ public:
|
|||||||
|
|
||||||
@implementation QSearchFieldDelegate
|
@implementation QSearchFieldDelegate
|
||||||
-(void)controlTextDidChange:(NSNotification*)notification {
|
-(void)controlTextDidChange:(NSNotification*)notification {
|
||||||
Q_ASSERT(pimpl);
|
Q_ASSERT(pimpl);
|
||||||
if (pimpl)
|
if (pimpl) pimpl->textDidChange(toQString([[notification object] stringValue]));
|
||||||
pimpl->textDidChange(toQString([[notification object] stringValue]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)controlTextDidEndEditing:(NSNotification*)notification {
|
-(void)controlTextDidEndEditing:(NSNotification*)notification {
|
||||||
Q_UNUSED(notification);
|
Q_UNUSED(notification);
|
||||||
// No Q_ASSERT here as it is called on destruction.
|
// No Q_ASSERT here as it is called on destruction.
|
||||||
if (pimpl)
|
if (!pimpl) return;
|
||||||
pimpl->textDidEndEditing();
|
pimpl->textDidEndEditing();
|
||||||
|
if ([[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement)
|
||||||
if ([[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement)
|
pimpl->returnPressed();
|
||||||
pimpl->returnPressed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)control: (NSControl *)control textView:
|
-(BOOL)control: (NSControl *)control textView:
|
||||||
(NSTextView *)textView doCommandBySelector:
|
(NSTextView *)textView doCommandBySelector:
|
||||||
(SEL)commandSelector {
|
(SEL)commandSelector {
|
||||||
Q_ASSERT(pimpl);
|
Q_ASSERT(pimpl);
|
||||||
if (!pimpl) return NO;
|
if (!pimpl) return NO;
|
||||||
|
if (commandSelector == @selector(moveDown:)) {
|
||||||
if (commandSelector == @selector(moveDown:)) {
|
pimpl->keyDownPressed();
|
||||||
pimpl->keyDownPressed();
|
return YES;
|
||||||
return YES;
|
}
|
||||||
} else if (commandSelector == @selector(moveUp:)) {
|
else if (commandSelector == @selector(moveUp:)) {
|
||||||
pimpl->keyUpPressed();
|
pimpl->keyUpPressed();
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -129,169 +120,109 @@ public:
|
|||||||
|
|
||||||
@implementation QocoaSearchField
|
@implementation QocoaSearchField
|
||||||
-(BOOL)performKeyEquivalent:(NSEvent*)event {
|
-(BOOL)performKeyEquivalent:(NSEvent*)event {
|
||||||
// First, check if we have the focus.
|
// First, check if we have the focus.
|
||||||
// If no, it probably means this event isn't for us.
|
// If no, it probably means this event isn't for us.
|
||||||
NSResponder* firstResponder = [[NSApp keyWindow] firstResponder];
|
NSResponder* firstResponder = [[NSApp keyWindow] firstResponder];
|
||||||
if ([firstResponder isKindOfClass:[NSText class]] &&
|
if ([firstResponder isKindOfClass:[NSText class]] && [(NSText*)firstResponder delegate] == self) {
|
||||||
[(NSText*)firstResponder delegate] == self) {
|
|
||||||
|
|
||||||
if ([event type] == NSEventTypeKeyDown && [event modifierFlags] & NSEventModifierFlagCommand)
|
if ([event type] == NSEventTypeKeyDown && [event modifierFlags] & NSEventModifierFlagCommand) {
|
||||||
{
|
QString keyString = toQString([event characters]);
|
||||||
QString keyString = toQString([event characters]);
|
if (keyString == "a") // Cmd+a
|
||||||
if (keyString == "a") // Cmd+a
|
{
|
||||||
{
|
[self performSelector:@selector(selectText:)];
|
||||||
[self performSelector:@selector(selectText:)];
|
return YES;
|
||||||
return YES;
|
}
|
||||||
}
|
else if (keyString == "c") // Cmd+c
|
||||||
else if (keyString == "c") // Cmd+c
|
{
|
||||||
{
|
[[self currentEditor] copy: nil];
|
||||||
[[self currentEditor] copy: nil];
|
return YES;
|
||||||
return YES;
|
}
|
||||||
}
|
else if (keyString == "v") // Cmd+v
|
||||||
else if (keyString == "v") // Cmd+v
|
{
|
||||||
{
|
[[self currentEditor] paste: nil];
|
||||||
[[self currentEditor] paste: nil];
|
return YES;
|
||||||
return YES;
|
}
|
||||||
}
|
else if (keyString == "x") // Cmd+x
|
||||||
else if (keyString == "x") // Cmd+x
|
{
|
||||||
{
|
[[self currentEditor] cut: nil];
|
||||||
[[self currentEditor] cut: nil];
|
return YES;
|
||||||
return YES;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
|
QSearchField::QSearchField(QWidget *parent) : QWidget(parent) {
|
||||||
{
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSSearchField *search = [[QocoaSearchField alloc] init];
|
||||||
|
QSearchFieldDelegate *delegate = [[QSearchFieldDelegate alloc] init];
|
||||||
NSSearchField *search = [[QocoaSearchField alloc] init];
|
pimpl = delegate->pimpl = new QSearchFieldPrivate(this, search);
|
||||||
|
[search setDelegate:delegate];
|
||||||
QSearchFieldDelegate *delegate = [[QSearchFieldDelegate alloc] init];
|
setupLayout(search, this);
|
||||||
pimpl = delegate->pimpl = new QSearchFieldPrivate(this, search);
|
setFixedHeight(24);
|
||||||
[search setDelegate:delegate];
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
[search release];
|
||||||
setupLayout(search, this);
|
[pool drain];
|
||||||
|
|
||||||
setFixedHeight(24);
|
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
[search release];
|
|
||||||
|
|
||||||
[pool drain];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::setMenu(QMenu *menu)
|
void QSearchField::setText(const QString &text) {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
Q_ASSERT(pimpl);
|
if (!pimpl) return;
|
||||||
if (!pimpl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSMenu *nsMenu = menu->macMenu();
|
[pimpl->nsSearchField setStringValue:fromQString(text)];
|
||||||
#else
|
if (!text.isEmpty()) {
|
||||||
NSMenu *nsMenu = menu->toNSMenu();
|
[pimpl->nsSearchField selectText:pimpl->nsSearchField];
|
||||||
#endif
|
[[pimpl->nsSearchField currentEditor] setSelectedRange:NSMakeRange([[pimpl->nsSearchField stringValue] length], 0)];
|
||||||
|
}
|
||||||
[[pimpl->nsSearchField cell] setSearchMenuTemplate:nsMenu];
|
[pool drain];
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::popupMenu()
|
void QSearchField::setPlaceholderText(const QString &text) {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
|
if (!pimpl) return;
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
[[pimpl->nsSearchField cell] setPlaceholderString:fromQString(text)];
|
||||||
|
[pool drain];
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::setText(const QString &text)
|
void QSearchField::clear() {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
Q_ASSERT(pimpl);
|
if (!pimpl) return;
|
||||||
if (!pimpl)
|
[pimpl->nsSearchField setStringValue:@""];
|
||||||
return;
|
emit textChanged(QString());
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
[pimpl->nsSearchField setStringValue:fromQString(text)];
|
|
||||||
[pool drain];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::setPlaceholderText(const QString &text)
|
void QSearchField::selectAll() {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
Q_ASSERT(pimpl);
|
if (!pimpl) return;
|
||||||
if (!pimpl)
|
[pimpl->nsSearchField performSelector:@selector(selectText:)];
|
||||||
return;
|
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
[[pimpl->nsSearchField cell] setPlaceholderString:fromQString(text)];
|
|
||||||
[pool drain];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::clear()
|
QString QSearchField::text() const {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
Q_ASSERT(pimpl);
|
if (!pimpl) return QString();
|
||||||
if (!pimpl)
|
return toQString([pimpl->nsSearchField stringValue]);
|
||||||
return;
|
|
||||||
|
|
||||||
[pimpl->nsSearchField setStringValue:@""];
|
|
||||||
emit textChanged(QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::selectAll()
|
QString QSearchField::placeholderText() const {
|
||||||
{
|
Q_ASSERT(pimpl);
|
||||||
Q_ASSERT(pimpl);
|
return toQString([[pimpl->nsSearchField cell] placeholderString]);
|
||||||
if (!pimpl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
[pimpl->nsSearchField performSelector:@selector(selectText:)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QSearchField::text() const
|
void QSearchField::setFocus(Qt::FocusReason) {}
|
||||||
{
|
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
if (!pimpl)
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
return toQString([pimpl->nsSearchField stringValue]);
|
void QSearchField::setFocus() {
|
||||||
|
setFocus(Qt::OtherFocusReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QSearchField::placeholderText() const
|
void QSearchField::resizeEvent(QResizeEvent *resizeEvent) {
|
||||||
{
|
QWidget::resizeEvent(resizeEvent);
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
if (!pimpl)
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
return toQString([[pimpl->nsSearchField cell] placeholderString]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::setFocus(Qt::FocusReason)
|
bool QSearchField::eventFilter(QObject *o, QEvent *e) {
|
||||||
{
|
return QWidget::eventFilter(o, e);
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
if (!pimpl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ([pimpl->nsSearchField acceptsFirstResponder])
|
|
||||||
[[pimpl->nsSearchField window] makeFirstResponder: pimpl->nsSearchField];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSearchField::setFocus()
|
|
||||||
{
|
|
||||||
setFocus(Qt::OtherFocusReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSearchField::changeEvent(QEvent* event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::EnabledChange) {
|
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
if (!pimpl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const bool enabled = isEnabled();
|
|
||||||
[pimpl->nsSearchField setEnabled: enabled];
|
|
||||||
}
|
|
||||||
QWidget::changeEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSearchField::resizeEvent(QResizeEvent *resizeEvent)
|
|
||||||
{
|
|
||||||
QWidget::resizeEvent(resizeEvent);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user