Port global search & album cover search to QSearchField and remove MacLineEdit.
This commit is contained in:
parent
35a7c7284b
commit
20d740f385
|
@ -804,7 +804,6 @@ optional_source(APPLE
|
||||||
ui/globalshortcutgrabber.mm
|
ui/globalshortcutgrabber.mm
|
||||||
ui/macscreensaver.cpp
|
ui/macscreensaver.cpp
|
||||||
ui/macsystemtrayicon.mm
|
ui/macsystemtrayicon.mm
|
||||||
widgets/maclineedit.mm
|
|
||||||
widgets/osd_mac.mm
|
widgets/osd_mac.mm
|
||||||
HEADERS
|
HEADERS
|
||||||
core/macfslistener.h
|
core/macfslistener.h
|
||||||
|
@ -812,7 +811,6 @@ optional_source(APPLE
|
||||||
devices/macdevicelister.h
|
devices/macdevicelister.h
|
||||||
ui/macscreensaver.h
|
ui/macscreensaver.h
|
||||||
ui/macsystemtrayicon.h
|
ui/macsystemtrayicon.h
|
||||||
widgets/maclineedit.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Platform specific - Windows
|
# Platform specific - Windows
|
||||||
|
|
|
@ -234,7 +234,7 @@ void GlobalSearchView::UpdateSuggestions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSearchView::StartSearch(const QString& query) {
|
void GlobalSearchView::StartSearch(const QString& query) {
|
||||||
ui_->search->set_text(query);
|
ui_->search->setText(query);
|
||||||
TextEdited(query);
|
TextEdited(query);
|
||||||
|
|
||||||
// Swap models immediately
|
// Swap models immediately
|
||||||
|
@ -394,7 +394,7 @@ bool GlobalSearchView::SearchKeyEvent(QKeyEvent* event) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Escape:
|
||||||
static_cast<LineEditInterface*>(ui_->search)->clear();
|
ui_->search->clear();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -480,8 +480,8 @@ void GlobalSearchView::showEvent(QShowEvent* e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSearchView::FocusSearchField() {
|
void GlobalSearchView::FocusSearchField() {
|
||||||
ui_->search->set_focus();
|
ui_->search->setFocus();
|
||||||
ui_->search->selectAll();
|
//ui_->search->selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSearchView::hideEvent(QHideEvent* e) {
|
void GlobalSearchView::hideEvent(QHideEvent* e) {
|
||||||
|
@ -490,7 +490,7 @@ void GlobalSearchView::hideEvent(QHideEvent* e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSearchView::FocusOnFilter(QKeyEvent* event) {
|
void GlobalSearchView::FocusOnFilter(QKeyEvent* event) {
|
||||||
ui_->search->set_focus();
|
ui_->search->setFocus();
|
||||||
QApplication::sendEvent(ui_->search, event);
|
QApplication::sendEvent(ui_->search, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="LineEdit" name="search">
|
<widget class="QSearchField" name="search">
|
||||||
<property name="hint" stdset="0">
|
<property name="placeholderText" stdset="0">
|
||||||
<string>Search for anything</string>
|
<string>Search for anything</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -208,9 +208,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>LineEdit</class>
|
<class>QSearchField</class>
|
||||||
<extends>QLineEdit</extends>
|
<extends>QWidget</extends>
|
||||||
<header>widgets/lineedit.h</header>
|
<header>3rdparty/qocoa/qsearchfield.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>AutoExpandingTreeView</class>
|
<class>AutoExpandingTreeView</class>
|
||||||
|
|
|
@ -137,7 +137,7 @@ void AlbumCoverSearcher::Init(AlbumCoverFetcher* fetcher) {
|
||||||
QImage AlbumCoverSearcher::Exec(const QString& artist, const QString& album) {
|
QImage AlbumCoverSearcher::Exec(const QString& artist, const QString& album) {
|
||||||
ui_->artist->setText(artist);
|
ui_->artist->setText(artist);
|
||||||
ui_->album->setText(album);
|
ui_->album->setText(album);
|
||||||
ui_->artist->set_focus();
|
ui_->artist->setFocus();
|
||||||
|
|
||||||
if(!artist.isEmpty() || !album.isEmpty()) {
|
if(!artist.isEmpty() || !album.isEmpty()) {
|
||||||
Search();
|
Search();
|
||||||
|
|
|
@ -17,21 +17,21 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="LineEdit" name="artist">
|
<widget class="QSearchField" name="artist">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Artist</string>
|
<string>Artist</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="hint" stdset="0">
|
<property name="placeholderText" stdset="0">
|
||||||
<string>Artist</string>
|
<string>Artist</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="LineEdit" name="album">
|
<widget class="QSearchField" name="album">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Album</string>
|
<string>Album</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="hint" stdset="0">
|
<property name="placeholderText" stdset="0">
|
||||||
<string>Album</string>
|
<string>Album</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -81,9 +81,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>LineEdit</class>
|
<class>QSearchField</class>
|
||||||
<extends>QLineEdit</extends>
|
<extends>QWidget</extends>
|
||||||
<header>widgets/lineedit.h</header>
|
<header>3rdparty/qocoa/qsearchfield.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BusyIndicator</class>
|
<class>BusyIndicator</class>
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/* This file is part of Clementine.
|
|
||||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
||||||
|
|
||||||
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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MACLINEEDIT_H
|
|
||||||
#define MACLINEEDIT_H
|
|
||||||
|
|
||||||
#include <QMacCocoaViewContainer>
|
|
||||||
|
|
||||||
#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
|
|
|
@ -1,139 +0,0 @@
|
||||||
/* This file is part of Clementine.
|
|
||||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
||||||
|
|
||||||
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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "maclineedit.h"
|
|
||||||
|
|
||||||
#import <Foundation/NSAutoreleasePool.h>
|
|
||||||
|
|
||||||
#include <QtDebug>
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
Loading…
Reference in New Issue