From 20d740f38527d9c6745e437d6b3bb89f6f0a9119 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 28 Jun 2012 11:22:31 +0200 Subject: [PATCH] Port global search & album cover search to QSearchField and remove MacLineEdit. --- src/CMakeLists.txt | 2 - src/globalsearch/globalsearchview.cpp | 10 +- src/globalsearch/globalsearchview.ui | 10 +- src/ui/albumcoversearcher.cpp | 2 +- src/ui/albumcoversearcher.ui | 14 +-- src/widgets/maclineedit.h | 61 ----------- src/widgets/maclineedit.mm | 139 -------------------------- 7 files changed, 18 insertions(+), 220 deletions(-) delete mode 100644 src/widgets/maclineedit.h delete mode 100644 src/widgets/maclineedit.mm diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f52416e64..0f10922da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -804,7 +804,6 @@ optional_source(APPLE ui/globalshortcutgrabber.mm ui/macscreensaver.cpp ui/macsystemtrayicon.mm - widgets/maclineedit.mm widgets/osd_mac.mm HEADERS core/macfslistener.h @@ -812,7 +811,6 @@ optional_source(APPLE devices/macdevicelister.h ui/macscreensaver.h ui/macsystemtrayicon.h - widgets/maclineedit.h ) # Platform specific - Windows diff --git a/src/globalsearch/globalsearchview.cpp b/src/globalsearch/globalsearchview.cpp index ac93c2426..61233b1de 100644 --- a/src/globalsearch/globalsearchview.cpp +++ b/src/globalsearch/globalsearchview.cpp @@ -234,7 +234,7 @@ void GlobalSearchView::UpdateSuggestions() { } void GlobalSearchView::StartSearch(const QString& query) { - ui_->search->set_text(query); + ui_->search->setText(query); TextEdited(query); // Swap models immediately @@ -394,7 +394,7 @@ bool GlobalSearchView::SearchKeyEvent(QKeyEvent* event) { break; case Qt::Key_Escape: - static_cast(ui_->search)->clear(); + ui_->search->clear(); break; default: @@ -480,8 +480,8 @@ void GlobalSearchView::showEvent(QShowEvent* e) { } void GlobalSearchView::FocusSearchField() { - ui_->search->set_focus(); - ui_->search->selectAll(); + ui_->search->setFocus(); + //ui_->search->selectAll(); } void GlobalSearchView::hideEvent(QHideEvent* e) { @@ -490,7 +490,7 @@ void GlobalSearchView::hideEvent(QHideEvent* e) { } void GlobalSearchView::FocusOnFilter(QKeyEvent* event) { - ui_->search->set_focus(); + ui_->search->setFocus(); QApplication::sendEvent(ui_->search, event); } diff --git a/src/globalsearch/globalsearchview.ui b/src/globalsearch/globalsearchview.ui index b2f7ca921..fdf6ea711 100644 --- a/src/globalsearch/globalsearchview.ui +++ b/src/globalsearch/globalsearchview.ui @@ -23,8 +23,8 @@ 0 - - + + Search for anything @@ -208,9 +208,9 @@ - LineEdit - QLineEdit -
widgets/lineedit.h
+ QSearchField + QWidget +
3rdparty/qocoa/qsearchfield.h
AutoExpandingTreeView diff --git a/src/ui/albumcoversearcher.cpp b/src/ui/albumcoversearcher.cpp index 04727db22..230314d95 100644 --- a/src/ui/albumcoversearcher.cpp +++ b/src/ui/albumcoversearcher.cpp @@ -137,7 +137,7 @@ void AlbumCoverSearcher::Init(AlbumCoverFetcher* fetcher) { QImage AlbumCoverSearcher::Exec(const QString& artist, const QString& album) { ui_->artist->setText(artist); ui_->album->setText(album); - ui_->artist->set_focus(); + ui_->artist->setFocus(); if(!artist.isEmpty() || !album.isEmpty()) { Search(); diff --git a/src/ui/albumcoversearcher.ui b/src/ui/albumcoversearcher.ui index f7029d602..cc41bf79f 100644 --- a/src/ui/albumcoversearcher.ui +++ b/src/ui/albumcoversearcher.ui @@ -17,21 +17,21 @@ - + Artist - + Artist - + Album - + Album @@ -81,9 +81,9 @@ - LineEdit - QLineEdit -
widgets/lineedit.h
+ QSearchField + QWidget +
3rdparty/qocoa/qsearchfield.h
BusyIndicator diff --git a/src/widgets/maclineedit.h b/src/widgets/maclineedit.h deleted file mode 100644 index 5282d63af..000000000 --- a/src/widgets/maclineedit.h +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of Clementine. - Copyright 2010, David Sansome - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef MACLINEEDIT_H -#define MACLINEEDIT_H - -#include - -#include "lineedit.h" - -class SearchTargetWrapper; - -class MacLineEdit : public QMacCocoaViewContainer, public LineEditInterface { - Q_OBJECT - Q_PROPERTY(QString hint READ hint WRITE set_hint); - - public: - MacLineEdit(QWidget* parent = 0); - ~MacLineEdit(); - - QString hint() const { return hint_; } - void set_hint(const QString& hint); - void clear_hint() { set_hint(QString()); } - - void paintEvent(QPaintEvent* e); - - void set_text(const QString&); - QString text() const; - void set_focus() {} - - void set_enabled(bool enabled); - - signals: - void textChanged(const QString& text); - void textEdited(const QString& text); - - private: - // Called by NSSearchFieldCell when the text changes. - void TextChanged(const QString& text); - - QString hint_; - - friend class SearchTargetWrapper; - SearchTargetWrapper* wrapper_; -}; - -#endif // MACLINEEDIT_H diff --git a/src/widgets/maclineedit.mm b/src/widgets/maclineedit.mm deleted file mode 100644 index c05ef0014..000000000 --- a/src/widgets/maclineedit.mm +++ /dev/null @@ -1,139 +0,0 @@ -/* This file is part of Clementine. - Copyright 2010, David Sansome - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "maclineedit.h" - -#import - -#include - -@interface SearchTarget : NSObject { - SearchTargetWrapper* wrapper_; -} - -- (id) initWithWrapper: (SearchTargetWrapper*)wrapper; -- (void) action; -@end - -class SearchTargetWrapper { - public: - explicit SearchTargetWrapper(NSSearchField* search, MacLineEdit* lineedit); - void TextChanged(); - - QString text() const; - void setText(const QString& text); - - void SetHint(const QString& hint); - - void SetEnabled(bool enabled); - - private: - NSSearchField* search_; - SearchTarget* target_; - MacLineEdit* lineedit_; -}; - - -@implementation SearchTarget -- (id) initWithWrapper: (SearchTargetWrapper*)wrapper { - wrapper_ = wrapper; - return self; -} - -- (void) action { - wrapper_->TextChanged(); -} -@end - -SearchTargetWrapper::SearchTargetWrapper(NSSearchField* search, MacLineEdit* lineedit) - : search_(search), - lineedit_(lineedit) { - target_ = [[SearchTarget alloc] initWithWrapper:this]; - - [[search cell] setTarget:target_]; - [[search cell] setAction:@selector(action)]; -} - -void SearchTargetWrapper::TextChanged() { - NSString* text = [[search_ cell] stringValue]; - lineedit_->TextChanged(QString::fromUtf8([text UTF8String])); -} - -QString SearchTargetWrapper::text() const { - NSString* text = [[search_ cell] stringValue]; - return QString::fromUtf8([text UTF8String]); -} - -void SearchTargetWrapper::setText(const QString& text) { - NSString* t = [[NSString alloc] initWithUTF8String:text.toUtf8().constData()]; - [[search_ cell] setStringValue:t]; - [t release]; -} - -void SearchTargetWrapper::SetHint(const QString& hint) { - NSString* t = [[NSString alloc] initWithUTF8String:hint.toUtf8().constData()]; - [[search_ cell] setPlaceholderString:t]; - [t release]; -} - -void SearchTargetWrapper::SetEnabled(bool enabled) { - [search_ setEnabled:enabled]; -} - -MacLineEdit::MacLineEdit(QWidget* parent) - : QMacCocoaViewContainer(0, parent), - LineEditInterface(this) { - setAttribute(Qt::WA_NativeWindow); - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - NSSearchField* search = [[NSSearchField alloc] init]; - setCocoaView(search); - - wrapper_ = new SearchTargetWrapper(search, this); - - [search release]; - [pool release]; // Pool's closed. -} - -MacLineEdit::~MacLineEdit() { - delete wrapper_; -} - -void MacLineEdit::paintEvent(QPaintEvent* e) { - QMacCocoaViewContainer::paintEvent(e); -} - -void MacLineEdit::TextChanged(const QString& text) { - emit textChanged(text); - emit textEdited(text); -} - -QString MacLineEdit::text() const { - return wrapper_->text(); -} - -void MacLineEdit::set_text(const QString& text) { - wrapper_->setText(text); -} - -void MacLineEdit::set_enabled(bool enabled) { - wrapper_->SetEnabled(enabled); -} - -void MacLineEdit::set_hint(const QString& hint) { - wrapper_->SetHint(hint); -}