mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-20 04:41:36 +02:00
* Added native MacLineEdit widget and used it in TomahawkWindow's toolbar.
This commit is contained in:
@@ -422,10 +422,12 @@ IF( APPLE )
|
|||||||
SET( libSources ${libSources}
|
SET( libSources ${libSources}
|
||||||
infosystem/infoplugins/mac/adium.mm
|
infosystem/infoplugins/mac/adium.mm
|
||||||
infosystem/infoplugins/mac/adiumplugin.cpp
|
infosystem/infoplugins/mac/adiumplugin.cpp
|
||||||
|
widgets/maclineedit.mm
|
||||||
utils/tomahawkutils_mac.mm )
|
utils/tomahawkutils_mac.mm )
|
||||||
|
|
||||||
SET( libHeaders ${libHeaders}
|
SET( libHeaders ${libHeaders}
|
||||||
infosystem/infoplugins/mac/adiumplugin.h )
|
infosystem/infoplugins/mac/adiumplugin.h
|
||||||
|
widgets/maclineedit.h )
|
||||||
|
|
||||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
${OS_SPECIFIC_LINK_LIBRARIES}
|
||||||
|
@@ -67,4 +67,3 @@ SearchButton *SearchLineEdit::searchButton() const
|
|||||||
{
|
{
|
||||||
return m_searchButton;
|
return m_searchButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
class ClearButton;
|
class ClearButton;
|
||||||
class SearchButton;
|
class SearchButton;
|
||||||
|
|
||||||
class DLLEXPORT SearchLineEdit : public LineEdit
|
class DLLEXPORT SearchLineEdit : public LineEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -47,7 +48,6 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
ClearButton *m_clearButton;
|
ClearButton *m_clearButton;
|
||||||
SearchButton *m_searchButton;
|
SearchButton *m_searchButton;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SEARCHLINEEDIT_H
|
#endif // SEARCHLINEEDIT_H
|
||||||
|
82
src/libtomahawk/widgets/maclineedit.h
Normal file
82
src/libtomahawk/widgets/maclineedit.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/* 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>
|
||||||
|
|
||||||
|
class SearchTargetWrapper;
|
||||||
|
|
||||||
|
class LineEditInterface {
|
||||||
|
public:
|
||||||
|
LineEditInterface(QWidget* widget) : widget_(widget) {}
|
||||||
|
|
||||||
|
QWidget* widget() const { return widget_; }
|
||||||
|
|
||||||
|
virtual ~LineEditInterface() {}
|
||||||
|
|
||||||
|
virtual void clear() { set_text(QString()); }
|
||||||
|
virtual void set_focus() = 0;
|
||||||
|
virtual QString text() const = 0;
|
||||||
|
virtual void set_text(const QString& text) = 0;
|
||||||
|
|
||||||
|
virtual QString hint() const = 0;
|
||||||
|
virtual void set_hint(const QString& hint) = 0;
|
||||||
|
virtual void clear_hint() = 0;
|
||||||
|
|
||||||
|
virtual void set_enabled(bool enabled) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QWidget* widget_;
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
140
src/libtomahawk/widgets/maclineedit.mm
Normal file
140
src/libtomahawk/widgets/maclineedit.mm
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/* 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] setSendsWholeSearchString:true];
|
||||||
|
|
||||||
|
[[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) {
|
||||||
|
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);
|
||||||
|
}
|
@@ -65,6 +65,9 @@
|
|||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
#include <qtsparkle/Updater>
|
#include <qtsparkle/Updater>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
#include "widgets/maclineedit.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
@@ -210,35 +213,49 @@ TomahawkWindow::setupSideBar()
|
|||||||
ui->splitter->setHandleWidth( 1 );
|
ui->splitter->setHandleWidth( 1 );
|
||||||
|
|
||||||
ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() );
|
ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkWindow::setupToolBar()
|
TomahawkWindow::setupToolBar()
|
||||||
{
|
{
|
||||||
m_searchBox = new QWidget();
|
|
||||||
m_searchWidget->setupUi( m_searchBox );
|
|
||||||
|
|
||||||
QToolBar* toolbar = addToolBar( "TomahawkToolbar" );
|
QToolBar* toolbar = addToolBar( "TomahawkToolbar" );
|
||||||
toolbar->setObjectName( "TomahawkToolbar" );
|
toolbar->setObjectName( "TomahawkToolbar" );
|
||||||
toolbar->setMovable( false );
|
toolbar->setMovable( false );
|
||||||
toolbar->setFloatable( false );
|
toolbar->setFloatable( false );
|
||||||
toolbar->setIconSize( QSize( 32, 32 ) );
|
toolbar->setIconSize( QSize( 28, 28 ) );
|
||||||
toolbar->setToolButtonStyle( Qt::ToolButtonFollowStyle );
|
toolbar->setToolButtonStyle( Qt::ToolButtonFollowStyle );
|
||||||
toolbar->installEventFilter( new WidgetDragFilter( toolbar ) );
|
toolbar->installEventFilter( new WidgetDragFilter( toolbar ) );
|
||||||
|
toolbar->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
||||||
|
|
||||||
m_backAvailable = toolbar->addAction( QIcon( RESPATH "images/back.png" ), tr( "Back" ), ViewManager::instance(), SLOT( historyBack() ) );
|
m_backAvailable = toolbar->addAction( QIcon( RESPATH "images/back.png" ), tr( "Back" ), ViewManager::instance(), SLOT( historyBack() ) );
|
||||||
m_backAvailable->setToolTip( tr( "Go back one page" ) );
|
m_backAvailable->setToolTip( tr( "Go back one page" ) );
|
||||||
m_forwardAvailable = toolbar->addAction( QIcon( RESPATH "images/forward.png" ), tr( "Forward" ), ViewManager::instance(), SLOT( historyForward() ) );
|
m_forwardAvailable = toolbar->addAction( QIcon( RESPATH "images/forward.png" ), tr( "Forward" ), ViewManager::instance(), SLOT( historyForward() ) );
|
||||||
m_forwardAvailable->setToolTip( tr( "Go forward one page" ) );
|
m_forwardAvailable->setToolTip( tr( "Go forward one page" ) );
|
||||||
|
|
||||||
|
m_searchBox = new QWidget( toolbar );
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QWidget *spacerWidget = new QWidget( this );
|
||||||
|
spacerWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
||||||
|
spacerWidget->setVisible( true );
|
||||||
|
toolbar->addWidget( spacerWidget );
|
||||||
|
|
||||||
|
m_searchBox->setLayout( new QHBoxLayout() );
|
||||||
|
|
||||||
|
MacLineEdit* lineEdit = new MacLineEdit( m_searchBox );
|
||||||
|
lineEdit->setFixedSize( 256, 28 );
|
||||||
|
lineEdit->set_hint( tr( "Search" ) );
|
||||||
|
m_searchBox->layout()->addWidget( lineEdit );
|
||||||
|
|
||||||
|
connect( lineEdit, SIGNAL( textChanged( QString ) ), SLOT( onSearch( QString ) ) );
|
||||||
|
#else
|
||||||
|
m_searchWidget->setupUi( m_searchBox );
|
||||||
m_searchWidget->searchEdit->setStyleSheet( "QLineEdit { border: 1px solid gray; border-radius: 6px; margin-right: 2px; }" );
|
m_searchWidget->searchEdit->setStyleSheet( "QLineEdit { border: 1px solid gray; border-radius: 6px; margin-right: 2px; }" );
|
||||||
#ifdef Q_WS_MAC
|
|
||||||
m_searchWidget->searchEdit->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
connect( m_searchWidget->searchEdit, SIGNAL( returnPressed() ), SLOT( onFilterEdited() ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect( m_searchWidget->searchEdit, SIGNAL( returnPressed() ), SLOT( onSearch() ) );
|
|
||||||
toolbar->addWidget( m_searchBox );
|
toolbar->addWidget( m_searchBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,9 +694,16 @@ TomahawkWindow::checkForUpdates()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkWindow::onSearch()
|
TomahawkWindow::onSearch( const QString& search )
|
||||||
{
|
{
|
||||||
ViewManager::instance()->show( new SearchWidget( m_searchWidget->searchEdit->text(), this ) );
|
ViewManager::instance()->show( new SearchWidget( search, this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TomahawkWindow::onFilterEdited()
|
||||||
|
{
|
||||||
|
onSearch( m_searchWidget->searchEdit->text() );
|
||||||
m_searchWidget->searchEdit->clear();
|
m_searchWidget->searchEdit->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,8 @@ private slots:
|
|||||||
void onSipPluginAdded( SipPlugin* p );
|
void onSipPluginAdded( SipPlugin* p );
|
||||||
void onSipPluginRemoved( SipPlugin* p );
|
void onSipPluginRemoved( SipPlugin* p );
|
||||||
|
|
||||||
void onSearch();
|
void onSearch( const QString& search );
|
||||||
|
void onFilterEdited();
|
||||||
|
|
||||||
void minimize();
|
void minimize();
|
||||||
void maximize();
|
void maximize();
|
||||||
|
Reference in New Issue
Block a user