mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-29 10:39:47 +01:00
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/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
|
||||
|
@ -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<LineEditInterface*>(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);
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="LineEdit" name="search">
|
||||
<property name="hint" stdset="0">
|
||||
<widget class="QSearchField" name="search">
|
||||
<property name="placeholderText" stdset="0">
|
||||
<string>Search for anything</string>
|
||||
</property>
|
||||
</widget>
|
||||
@ -208,9 +208,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>widgets/lineedit.h</header>
|
||||
<class>QSearchField</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>3rdparty/qocoa/qsearchfield.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AutoExpandingTreeView</class>
|
||||
|
@ -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();
|
||||
|
@ -17,21 +17,21 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="LineEdit" name="artist">
|
||||
<widget class="QSearchField" name="artist">
|
||||
<property name="toolTip">
|
||||
<string>Artist</string>
|
||||
</property>
|
||||
<property name="hint" stdset="0">
|
||||
<property name="placeholderText" stdset="0">
|
||||
<string>Artist</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineEdit" name="album">
|
||||
<widget class="QSearchField" name="album">
|
||||
<property name="toolTip">
|
||||
<string>Album</string>
|
||||
</property>
|
||||
<property name="hint" stdset="0">
|
||||
<property name="placeholderText" stdset="0">
|
||||
<string>Album</string>
|
||||
</property>
|
||||
</widget>
|
||||
@ -81,9 +81,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>widgets/lineedit.h</header>
|
||||
<class>QSearchField</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>3rdparty/qocoa/qsearchfield.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<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…
x
Reference in New Issue
Block a user