mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
Update to newer Qocoa versions of QSearchField.
This commit is contained in:
@@ -138,16 +138,14 @@ void QSearchField::setFocus(Qt::FocusReason reason)
|
|||||||
pimpl.data()->lineEdit->setFocus(reason);
|
pimpl.data()->lineEdit->setFocus(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QSearchField::setMenu(QMenu *menu)
|
||||||
|
{
|
||||||
|
//FIXME nop
|
||||||
|
}
|
||||||
|
|
||||||
void QSearchField::resizeEvent(QResizeEvent* e)
|
void QSearchField::resizeEvent(QResizeEvent* e)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(e);
|
QWidget::resizeEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QSearchField::eventFilter(QObject *o, QEvent *e)
|
|
||||||
{
|
|
||||||
return QWidget::eventFilter(o, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "qsearchfield.moc"
|
#include "qsearchfield.moc"
|
||||||
|
15
src/libtomahawk/thirdparty/Qocoa/qsearchfield.h
vendored
15
src/libtomahawk/thirdparty/Qocoa/qsearchfield.h
vendored
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
@@ -10,12 +11,17 @@ class QSearchFieldPrivate;
|
|||||||
class DLLEXPORT QSearchField : public QWidget
|
class DLLEXPORT QSearchField : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true);
|
||||||
|
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QSearchField(QWidget *parent);
|
explicit QSearchField(QWidget *parent);
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
QString placeholderText() const;
|
QString placeholderText() const;
|
||||||
void setFocus(Qt::FocusReason reason);
|
void setFocus(Qt::FocusReason);
|
||||||
|
void setMenu(QMenu *menu);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
@@ -29,15 +35,16 @@ signals:
|
|||||||
void editingFinished();
|
void editingFinished();
|
||||||
void returnPressed();
|
void returnPressed();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void popupMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void changeEvent(QEvent*);
|
||||||
void resizeEvent(QResizeEvent*);
|
void resizeEvent(QResizeEvent*);
|
||||||
bool eventFilter(QObject*, QEvent*);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QSearchFieldPrivate;
|
friend class QSearchFieldPrivate;
|
||||||
QPointer <QSearchFieldPrivate> pimpl;
|
QPointer <QSearchFieldPrivate> pimpl;
|
||||||
|
|
||||||
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QSEARCHFIELD_H
|
#endif // QSEARCHFIELD_H
|
||||||
|
185
src/libtomahawk/thirdparty/Qocoa/qsearchfield_mac.mm
vendored
185
src/libtomahawk/thirdparty/Qocoa/qsearchfield_mac.mm
vendored
@@ -24,13 +24,13 @@ THE SOFTWARE.
|
|||||||
#include "moc_qsearchfield.cpp"
|
#include "moc_qsearchfield.cpp"
|
||||||
|
|
||||||
#include "qocoa_mac.h"
|
#include "qocoa_mac.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
|
|
||||||
#import "Foundation/NSAutoreleasePool.h"
|
#import "Foundation/NSAutoreleasePool.h"
|
||||||
#import "Foundation/NSNotification.h"
|
#import "Foundation/NSNotification.h"
|
||||||
#import "AppKit/NSSearchField.h"
|
#import "AppKit/NSSearchField.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QKeyEvent>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
|
||||||
class QSearchFieldPrivate : public QObject
|
class QSearchFieldPrivate : public QObject
|
||||||
@@ -53,8 +53,27 @@ public:
|
|||||||
|
|
||||||
void returnPressed()
|
void returnPressed()
|
||||||
{
|
{
|
||||||
if (qSearchField)
|
if (qSearchField) {
|
||||||
emit qSearchField->returnPressed();
|
emit qSearchField->returnPressed();
|
||||||
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
||||||
|
QApplication::postEvent(qSearchField, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyDownPressed()
|
||||||
|
{
|
||||||
|
if (qSearchField) {
|
||||||
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
|
||||||
|
QApplication::postEvent(qSearchField, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyUpPressed()
|
||||||
|
{
|
||||||
|
if (qSearchField) {
|
||||||
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);
|
||||||
|
QApplication::postEvent(qSearchField, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<QSearchField> qSearchField;
|
QPointer<QSearchField> qSearchField;
|
||||||
@@ -78,6 +97,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)controlTextDidEndEditing:(NSNotification*)notification {
|
-(void)controlTextDidEndEditing:(NSNotification*)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)
|
||||||
pimpl->textDidEndEditing();
|
pimpl->textDidEndEditing();
|
||||||
@@ -85,49 +105,60 @@ public:
|
|||||||
if ([[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement)
|
if ([[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement)
|
||||||
pimpl->returnPressed();
|
pimpl->returnPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(BOOL)control: (NSControl *)control textView:
|
||||||
|
(NSTextView *)textView doCommandBySelector:
|
||||||
|
(SEL)commandSelector {
|
||||||
|
Q_ASSERT(pimpl);
|
||||||
|
if (!pimpl) return NO;
|
||||||
|
|
||||||
|
if (commandSelector == @selector(moveDown:)) {
|
||||||
|
pimpl->keyDownPressed();
|
||||||
|
return YES;
|
||||||
|
} else if (commandSelector == @selector(moveUp:)) {
|
||||||
|
pimpl->keyUpPressed();
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
static const unsigned short kKeycodeA = 0;
|
|
||||||
static const unsigned short kKeycodeX = 7;
|
|
||||||
static const unsigned short kKeycodeC = 8;
|
|
||||||
static const unsigned short kKeycodeV = 9;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
@interface QocoaSearchField : NSSearchField
|
@interface QocoaSearchField : NSSearchField
|
||||||
-(BOOL)performKeyEquivalent:(NSEvent*)event;
|
-(BOOL)performKeyEquivalent:(NSEvent*)event;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation QocoaSearchField
|
@implementation QocoaSearchField
|
||||||
-(BOOL)performKeyEquivalent:(NSEvent*)event {
|
-(BOOL)performKeyEquivalent:(NSEvent*)event {
|
||||||
if ([event type] == NSKeyDown && [event modifierFlags] & NSCommandKeyMask)
|
// First, check if we have the focus.
|
||||||
{
|
// If no, it probably means this event isn't for us.
|
||||||
const unsigned short keyCode = [event keyCode];
|
NSResponder* firstResponder = [[NSApp keyWindow] firstResponder];
|
||||||
/* if (keyCode == kKeycodeA) // Cmd+a
|
if ([firstResponder isKindOfClass:[NSText class]] &&
|
||||||
|
[(NSText*)firstResponder delegate] == self) {
|
||||||
|
|
||||||
|
if ([event type] == NSKeyDown && [event modifierFlags] & NSCommandKeyMask)
|
||||||
{
|
{
|
||||||
[self performSelector:@selector(selectText:)];
|
QString keyString = toQString([event characters]);
|
||||||
return YES;
|
if (keyString == "a") // Cmd+a
|
||||||
}
|
{
|
||||||
else*/ if (keyCode == kKeycodeC) // Cmd+c
|
[self performSelector:@selector(selectText:)];
|
||||||
{
|
return YES;
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
}
|
||||||
clipboard->setText(toQString([self stringValue]));
|
else if (keyString == "c") // Cmd+c
|
||||||
return YES;
|
{
|
||||||
}
|
[[self currentEditor] copy: nil];
|
||||||
else if (keyCode == kKeycodeV) // Cmd+v
|
return YES;
|
||||||
{
|
}
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
else if (keyString == "v") // Cmd+v
|
||||||
[self setStringValue:fromQString(clipboard->text())];
|
{
|
||||||
return YES;
|
[[self currentEditor] paste: nil];
|
||||||
}
|
return YES;
|
||||||
else if (keyCode == kKeycodeX) // Cmd+x
|
}
|
||||||
{
|
else if (keyString == "x") // Cmd+x
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
{
|
||||||
clipboard->setText(toQString([self stringValue]));
|
[[self currentEditor] cut: nil];
|
||||||
[self setStringValue:@""];
|
return YES;
|
||||||
return YES;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +186,25 @@ QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
|
|||||||
[pool drain];
|
[pool drain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QSearchField::setMenu(QMenu *menu)
|
||||||
|
{
|
||||||
|
Q_ASSERT(pimpl);
|
||||||
|
if (!pimpl)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
|
NSMenu *nsMenu = menu->macMenu();
|
||||||
|
#else
|
||||||
|
NSMenu *nsMenu = menu->toNSMenu();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[[pimpl->nsSearchField cell] setSearchMenuTemplate:nsMenu];
|
||||||
|
}
|
||||||
|
|
||||||
|
void QSearchField::popupMenu()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void QSearchField::setText(const QString &text)
|
void QSearchField::setText(const QString &text)
|
||||||
{
|
{
|
||||||
Q_ASSERT(pimpl);
|
Q_ASSERT(pimpl);
|
||||||
@@ -177,27 +227,6 @@ void QSearchField::setPlaceholderText(const QString &text)
|
|||||||
[pool drain];
|
[pool drain];
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QSearchField::placeholderText() const {
|
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
NSString* placeholder = [[pimpl->nsSearchField cell] placeholderString];
|
|
||||||
return toQString(placeholder);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSearchField::setFocus(Qt::FocusReason reason)
|
|
||||||
{
|
|
||||||
Q_ASSERT(pimpl);
|
|
||||||
if (!pimpl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ([pimpl->nsSearchField acceptsFirstResponder])
|
|
||||||
[[pimpl->nsSearchField window] makeFirstResponder: pimpl->nsSearchField];
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSearchField::setFocus()
|
|
||||||
{
|
|
||||||
setFocus(Qt::OtherFocusReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSearchField::clear()
|
void QSearchField::clear()
|
||||||
{
|
{
|
||||||
Q_ASSERT(pimpl);
|
Q_ASSERT(pimpl);
|
||||||
@@ -226,12 +255,44 @@ QString QSearchField::text() const
|
|||||||
return toQString([pimpl->nsSearchField stringValue]);
|
return toQString([pimpl->nsSearchField stringValue]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QSearchField::placeholderText() const
|
||||||
|
{
|
||||||
|
Q_ASSERT(pimpl);
|
||||||
|
if (!pimpl)
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
return toQString([[pimpl->nsSearchField cell] placeholderString]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QSearchField::setFocus(Qt::FocusReason)
|
||||||
|
{
|
||||||
|
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)
|
void QSearchField::resizeEvent(QResizeEvent *resizeEvent)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(resizeEvent);
|
QWidget::resizeEvent(resizeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QSearchField::eventFilter(QObject *o, QEvent *e)
|
|
||||||
{
|
|
||||||
return QWidget::eventFilter(o, e);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user