diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 57253016c..aefe951f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,6 +122,8 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui} resolversmodel.h delegateconfigwrapper.h tomahawkwindow.h + + Qocoa/qsearchfield.h ) SET( tomahawkUI ${tomahawkUI} @@ -129,7 +131,6 @@ SET( tomahawkUI ${tomahawkUI} diagnosticsdialog.ui stackedsettingsdialog.ui proxydialog.ui - searchbox.ui audiocontrols.ui ) @@ -173,12 +174,13 @@ IF( APPLE ) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/thirdparty/SPMediaKeyTap ) SET( tomahawkHeaders ${tomahawkHeaders} mac/tomahawkapp_mac.h mac/macshortcuthandler.h ) - SET( tomahawkSources ${tomahawkSources} mac/tomahawkapp_mac.mm mac/macshortcuthandler.cpp ) + SET( tomahawkSources ${tomahawkSources} mac/tomahawkapp_mac.mm mac/macshortcuthandler.cpp Qocoa/qsearchfield_mac.mm ) IF(HAVE_SPARKLE) SET( tomahawkHeaders ${tomahawkHeaders} ${SPARKLE}/Headers ) ENDIF(HAVE_SPARKLE) - +ELSE( APPLE ) + SET( tomahawkSources ${tomahawkSources} mac/tomahawkapp_mac.mm mac/macshortcuthandler.cpp Qocoa/qsearchfield.mm ) ENDIF( APPLE ) IF(GLOOX_FOUND) diff --git a/src/Qocoa/qocoa_mac.h b/src/Qocoa/qocoa_mac.h new file mode 100644 index 000000000..d86f9ad27 --- /dev/null +++ b/src/Qocoa/qocoa_mac.h @@ -0,0 +1,51 @@ +/* +Copyright (C) 2011 by Mike McQuaid + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef QCOCOA_MAC_H +#define QCOCOA_MAC_H + +#include +#include +#include +#include + +static inline NSString* fromQString(const QString &string) +{ + char* cString = string.toUtf8().data(); + return [[NSString alloc] initWithUTF8String:cString]; +} + +static inline QString toQString(NSString *string) +{ + if (!string) + return QString(); + return QString::fromUtf8([string UTF8String]); +} + +static inline void zeroLayout(void *cocoaView, QWidget *parent) +{ + QVBoxLayout *layout = new QVBoxLayout(parent); + layout->setMargin(0); + layout->addWidget(new QMacCocoaViewContainer(cocoaView, parent)); +} + +#endif diff --git a/src/Qocoa/qsearchfield.cpp b/src/Qocoa/qsearchfield.cpp new file mode 100644 index 000000000..4549a3e71 --- /dev/null +++ b/src/Qocoa/qsearchfield.cpp @@ -0,0 +1,75 @@ +/* +Copyright (C) 2011 by Mike McQuaid +Copyright (C) 2011 by Leo Franchi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "qsearchfield.h" + +#include +#include + +#include "playlist/topbar/searchlineedit.h" +#include "utils/tomahawkutils.h" + +class QSearchFieldPrivate +{ +public: + QSearchFieldPrivate(SearchLineEdit *lineEdit) : lineEdit(lineEdit) {} + SearchLineEdit *lineEdit; +}; + +QSearchField::QSearchField(QWidget *parent) : QWidget(parent) +{ + SearchLineEdit *lineEdit = new SearchLineEdit(this); + connect(lineEdit, SIGNAL(textChanged(QString)), + this, SIGNAL(textChanged(QString))); + connect(lineEdit, SIGNAL(returnPressed()), + this, SIGNAL(returnPressed())); + + pimpl = new QSearchFieldPrivate(lineEdit); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(lineEdit); +// TomahawkUtils::unmarginLayout(layout); + + lineEdit->setStyleSheet( "QLineEdit { border: 1px solid gray; border-radius: 6px; margin-right: 2px; }" ); + lineEdit->setContentsMargins(0, 0, 0, 0); +} + +void QSearchField::setText(const QString &text) +{ + pimpl->lineEdit->setText(text); +} + +void QSearchField::setInputHint(const QString& text) +{ + pimpl->lineEdit->setPlaceholderText( text ); +} + +void QSearchField::clear() +{ + pimpl->lineEdit->clear(); +} + +QString QSearchField::text() const +{ + return pimpl->lineEdit->text(); +} diff --git a/src/Qocoa/qsearchfield.h b/src/Qocoa/qsearchfield.h new file mode 100644 index 000000000..4e2ba42fa --- /dev/null +++ b/src/Qocoa/qsearchfield.h @@ -0,0 +1,29 @@ +#ifndef QSEARCHFIELD_H +#define QSEARCHFIELD_H + +#include + +class QSearchFieldPrivate; +class QSearchField : public QWidget +{ + Q_OBJECT +public: + explicit QSearchField(QWidget* parent); + + QString text() const; + +public slots: + void setText(const QString &text); + void setPlaceholderText(const QString& text); + + void clear(); +signals: + void textChanged(const QString &text); + void returnPressed(); + +private: + friend class QSearchFieldPrivate; + QSearchFieldPrivate *pimpl; +}; + +#endif // QSEARCHFIELD_H diff --git a/src/Qocoa/qsearchfield_mac.mm b/src/Qocoa/qsearchfield_mac.mm new file mode 100644 index 000000000..5f60cf1e8 --- /dev/null +++ b/src/Qocoa/qsearchfield_mac.mm @@ -0,0 +1,118 @@ +/* +Copyright (C) 2011 by Mike McQuaid +Copyright (C) 2011 by Leo Franchi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "qsearchfield.h" + +#include "qocoa_mac.h" + +#include "qsearchfield.h" + +#import "Foundation/NSAutoreleasePool.h" +#import "Foundation/NSNotification.h" +#import "AppKit/NSSearchField.h" + +class QSearchFieldPrivate +{ +public: + QSearchFieldPrivate(QSearchField *qSearchField, NSSearchField *nsSearchField) + : qSearchField(qSearchField), nsSearchField(nsSearchField) {} + + void textDidChange(const QString &text) + { + emit qSearchField->textChanged(text); + } + + void textDidEndEditing() + { + emit qSearchField->returnPressed(); + } + + QSearchField *qSearchField; + NSSearchField *nsSearchField; +}; + +@interface QSearchFieldDelegate : NSObject +{ +@public + QSearchFieldPrivate* pimpl; +} +-(void)controlTextDidChange:(NSNotification*)notification; +-(void)controlTextDidEndEditing:(NSNotification*)aNotification; +@end + +@implementation QSearchFieldDelegate +-(void)controlTextDidChange:(NSNotification*)notification { + pimpl->textDidChange(toQString([[notification object] stringValue])); +} + +-(void)controlTextDidEndEditing:(NSNotification*)notification { + pimpl->textDidEndEditing(); +} +@end + +QSearchField::QSearchField(QWidget *parent) : QWidget(parent) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSSearchField *search = [[NSSearchField alloc] init]; + pimpl = new QSearchFieldPrivate(this, search); + + QSearchFieldDelegate *delegate = [[QSearchFieldDelegate alloc] init]; + delegate->pimpl = pimpl; + [search setDelegate:delegate]; + + zeroLayout(search, this); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + layout()->setContentsMargins(2, 0, 2, 0); + setStyleSheet( "* { background: #DDE4EB; }" ); + + setMinimumSize(layout()->sizeHint().width(), 20); + + [search release]; + [pool drain]; +} + +void QSearchField::setText(const QString &text) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [pimpl->nsSearchField setStringValue:fromQString(text)]; + [pool drain]; +} + +void QSearchField::setPlaceholderText(const QString& text) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [[pimpl->nsSearchField cell] setPlaceholderString:fromQString(text)]; + [pool drain]; +} + +void QSearchField::clear() +{ + [pimpl->nsSearchField setStringValue:@""]; +} + +QString QSearchField::text() const +{ + return toQString([pimpl->nsSearchField stringValue]); +} diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 90c324245..e67e6f5f3 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -73,7 +73,6 @@ ViewManager::ViewManager( QObject* parent ) { s_instance = this; - setHistoryPosition( -1 ); m_widget->setLayout( new QVBoxLayout() ); m_topbar = new TopBar(); @@ -174,13 +173,14 @@ Tomahawk::ViewPage* ViewManager::show( const Tomahawk::playlist_ptr& playlist ) { PlaylistView* view; - if ( !m_playlistViews.contains( playlist ) ) + + if ( !m_playlistViews.contains( playlist ) || !m_playlistViews.value( playlist ).isNull() ) { view = createPageForPlaylist( playlist ); } else { - view = m_playlistViews.value( playlist ); + view = m_playlistViews.value( playlist ).data(); } setPage( view ); @@ -194,14 +194,14 @@ ViewManager::show( const Tomahawk::playlist_ptr& playlist ) Tomahawk::ViewPage* ViewManager::show( const Tomahawk::dynplaylist_ptr& playlist ) { - if ( !m_dynamicWidgets.contains( playlist ) ) + if ( !m_dynamicWidgets.contains( playlist ) || m_dynamicWidgets.value( playlist ).isNull() ) { m_dynamicWidgets[ playlist ] = new Tomahawk::DynamicWidget( playlist, m_stack ); playlist->resolve(); } - setPage( m_dynamicWidgets.value( playlist ) ); + setPage( m_dynamicWidgets.value( playlist ).data() ); if ( playlist->mode() == Tomahawk::OnDemand ) m_queueView->hide(); @@ -210,7 +210,7 @@ ViewManager::show( const Tomahawk::dynplaylist_ptr& playlist ) emit numSourcesChanged( SourceList::instance()->count() ); - return m_dynamicWidgets.value( playlist ); + return m_dynamicWidgets.value( playlist ).data(); } @@ -218,14 +218,14 @@ Tomahawk::ViewPage* ViewManager::show( const Tomahawk::artist_ptr& artist ) { ArtistInfoWidget* swidget; - if ( !m_artistViews.contains( artist ) ) + if ( !m_artistViews.contains( artist ) || m_artistViews.value( artist ).isNull() ) { swidget = new ArtistInfoWidget( artist ); m_artistViews.insert( artist, swidget ); } else { - swidget = m_artistViews.value( artist ); + swidget = m_artistViews.value( artist ).data(); } setPage( swidget ); @@ -237,14 +237,14 @@ Tomahawk::ViewPage* ViewManager::show( const Tomahawk::album_ptr& album ) { AlbumInfoWidget* swidget; - if ( !m_albumViews.contains( album ) ) + if ( !m_albumViews.contains( album ) || m_albumViews.value( album ).isNull() ) { swidget = new AlbumInfoWidget( album ); m_albumViews.insert( album, swidget ); } else { - swidget = m_albumViews.value( album ); + swidget = m_albumViews.value( album ).data(); } setPage( swidget ); @@ -261,7 +261,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( m_currentMode == PlaylistInterface::Flat ) { CollectionView* view; - if ( !m_collectionViews.contains( collection ) ) + if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() ) { view = new CollectionView(); CollectionFlatModel* model = new CollectionFlatModel(); @@ -275,7 +275,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) } else { - view = m_collectionViews.value( collection ); + view = m_collectionViews.value( collection ).data(); } shown = view; @@ -285,7 +285,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( m_currentMode == PlaylistInterface::Tree ) { ArtistView* view; - if ( !m_treeViews.contains( collection ) ) + if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() ) { view = new ArtistView(); TreeModel* model = new TreeModel(); @@ -299,7 +299,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) } else { - view = m_treeViews.value( collection ); + view = m_treeViews.value( collection ).data(); } shown = view; @@ -309,7 +309,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( m_currentMode == PlaylistInterface::Album ) { AlbumView* aview; - if ( !m_collectionAlbumViews.contains( collection ) ) + if ( !m_collectionAlbumViews.contains( collection ) || m_collectionAlbumViews.value( collection ).isNull() ) { aview = new AlbumView(); AlbumModel* amodel = new AlbumModel( aview ); @@ -322,7 +322,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) } else { - aview = m_collectionAlbumViews.value( collection ); + aview = m_collectionAlbumViews.value( collection ).data(); } shown = aview; @@ -339,14 +339,14 @@ Tomahawk::ViewPage* ViewManager::show( const Tomahawk::source_ptr& source ) { SourceInfoWidget* swidget; - if ( !m_sourceViews.contains( source ) ) + if ( !m_sourceViews.contains( source ) || m_sourceViews.value( source ).isNull() ) { swidget = new SourceInfoWidget( source ); m_sourceViews.insert( source, swidget ); } else { - swidget = m_sourceViews.value( source ); + swidget = m_sourceViews.value( source ).data(); } setPage( swidget ); @@ -508,37 +508,13 @@ ViewManager::hideQueue() void ViewManager::historyBack() { - if ( m_historyPosition < 1 ) - return; + ViewPage* oldPage = m_pageHistory.takeFirst(); - showHistory( m_historyPosition - 1 ); -} + ViewPage* newPage = m_pageHistory.first(); + qDebug() << "Showing page after moving backwards in history:" << newPage->widget()->metaObject()->className(); + setPage( newPage, false ); - -void -ViewManager::historyForward() -{ - if ( m_historyPosition >= m_pageHistory.count() - 1 ) - return; - - showHistory( m_historyPosition + 1 ); -} - - -void -ViewManager::showHistory( int historyPosition ) -{ - if ( historyPosition < 0 || historyPosition >= m_pageHistory.count() ) - { - qDebug() << "History position out of bounds!" << historyPosition << m_pageHistory.count(); - Q_ASSERT( false ); - return; - } - - setHistoryPosition( historyPosition ); - ViewPage* page = m_pageHistory.at( historyPosition ); - qDebug() << "Showing page after a deleting:" << page->widget()->metaObject()->className(); - setPage( page, false ); + delete oldPage; } void @@ -547,10 +523,11 @@ ViewManager::removeFromHistory ( ViewPage* p ) if ( currentPage() == p ) { historyBack(); - m_pageHistory.removeAll( p ); } else - if ( m_pageHistory.removeAll( p ) ) - setHistoryPosition( m_historyPosition - 1 ); + { + m_pageHistory.removeAll( p ); + delete p; + } } @@ -598,8 +575,7 @@ ViewManager::setPage( ViewPage* page, bool trackHistory ) if ( trackHistory ) { - m_pageHistory << page; - setHistoryPosition( m_pageHistory.count() - 1 ); + m_pageHistory.insert( 0, page ); } qDebug() << "View page shown:" << page->title(); @@ -780,12 +756,9 @@ ViewManager::onWidgetDestroyed( QWidget* widget ) m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) ); } - if ( page->widget() == widget ) + if ( page->widget() == widget && !resetWidget ) { m_pageHistory.removeAt( i ); - if ( m_historyPosition > i ) - m_historyPosition--; - break; } } @@ -793,8 +766,7 @@ ViewManager::onWidgetDestroyed( QWidget* widget ) if ( resetWidget ) { - if ( m_pageHistory.count() ) - showHistory( m_pageHistory.count() - 1 ); + historyBack(); } } @@ -838,21 +810,21 @@ ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src, ViewPage* ViewManager::pageForCollection( const collection_ptr& col ) const { - return m_collectionViews.value( col, 0 ); + return m_collectionViews.value( col ).data(); } ViewPage* ViewManager::pageForDynPlaylist(const dynplaylist_ptr& pl) const { - return m_dynamicWidgets.value( pl, 0 ); + return m_dynamicWidgets.value( pl ).data(); } ViewPage* ViewManager::pageForPlaylist(const playlist_ptr& pl) const { - return m_playlistViews.value( pl, 0 ); + return m_playlistViews.value( pl ).data(); } @@ -869,20 +841,6 @@ ViewManager::pageForInterface( Tomahawk::PlaylistInterface* interface ) const return 0; } - -int -ViewManager::positionInHistory( ViewPage* page ) const -{ - for ( int i = 0; i < m_pageHistory.count(); i++ ) - { - if ( page == m_pageHistory.at( i ) ) - return i; - } - - return -1; -} - - PlaylistInterface* ViewManager::currentPlaylistInterface() const { @@ -896,29 +854,15 @@ ViewManager::currentPlaylistInterface() const Tomahawk::ViewPage* ViewManager::currentPage() const { - if ( m_historyPosition >= 0 ) - return m_pageHistory.at( m_historyPosition ); - else - return 0; + return m_pageHistory.isEmpty() ? 0 : m_pageHistory.front(); } - -void -ViewManager::setHistoryPosition( int position ) -{ - m_historyPosition = position; - - emit historyBackAvailable( m_historyPosition > 0 ); - emit historyForwardAvailable( m_historyPosition < m_pageHistory.count() - 1 ); -} - - Tomahawk::playlist_ptr ViewManager::playlistForInterface( Tomahawk::PlaylistInterface* interface ) const { - foreach ( PlaylistView* view, m_playlistViews.values() ) + foreach ( QWeakPointer view, m_playlistViews.values() ) { - if ( view->playlistInterface() == interface ) + if ( view.data()->playlistInterface() == interface ) { return m_playlistViews.key( view ); } @@ -931,9 +875,9 @@ ViewManager::playlistForInterface( Tomahawk::PlaylistInterface* interface ) cons Tomahawk::dynplaylist_ptr ViewManager::dynamicPlaylistForInterface( Tomahawk::PlaylistInterface* interface ) const { - foreach ( DynamicWidget* view, m_dynamicWidgets.values() ) + foreach ( QWeakPointer view, m_dynamicWidgets.values() ) { - if ( view->playlistInterface() == interface ) + if ( view.data()->playlistInterface() == interface ) { return m_dynamicWidgets.key( view ); } @@ -946,16 +890,16 @@ ViewManager::dynamicPlaylistForInterface( Tomahawk::PlaylistInterface* interface Tomahawk::collection_ptr ViewManager::collectionForInterface( Tomahawk::PlaylistInterface* interface ) const { - foreach ( CollectionView* view, m_collectionViews.values() ) + foreach ( QWeakPointer view, m_collectionViews.values() ) { - if ( view->playlistInterface() == interface ) + if ( view.data()->playlistInterface() == interface ) { return m_collectionViews.key( view ); } } - foreach ( AlbumView* view, m_collectionAlbumViews.values() ) + foreach ( QWeakPointer view, m_collectionAlbumViews.values() ) { - if ( view->playlistInterface() == interface ) + if ( view.data()->playlistInterface() == interface ) { return m_collectionAlbumViews.key( view ); } diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index 34ed0431f..8fd2320d4 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -78,7 +78,6 @@ public: Tomahawk::PlaylistInterface* currentPlaylistInterface() const; Tomahawk::ViewPage* currentPage() const; Tomahawk::ViewPage* pageForInterface( Tomahawk::PlaylistInterface* interface ) const; - int positionInHistory( Tomahawk::ViewPage* page ) const; Tomahawk::ViewPage* show( Tomahawk::ViewPage* page ); @@ -111,9 +110,6 @@ signals: void playClicked(); void pauseClicked(); - void historyBackAvailable( bool avail ); - void historyForwardAvailable( bool avail ); - void tempPageActivated( Tomahawk::ViewPage* ); void viewPageActivated( Tomahawk::ViewPage* ); @@ -131,8 +127,6 @@ public slots: Tomahawk::ViewPage* show( const Tomahawk::source_ptr& source ); void historyBack(); - void historyForward(); - void showHistory( int historyPosition ); void removeFromHistory( Tomahawk::ViewPage* p ); void setTreeMode(); @@ -158,7 +152,6 @@ private slots: void onWidgetDestroyed( QWidget* widget ); private: - void setHistoryPosition( int position ); void setPage( Tomahawk::ViewPage* page, bool trackHistory = true ); void updateView(); void unlinkPlaylist(); @@ -187,17 +180,16 @@ private: QList< Tomahawk::collection_ptr > m_superCollections; - QHash< Tomahawk::dynplaylist_ptr, Tomahawk::DynamicWidget* > m_dynamicWidgets; - QHash< Tomahawk::collection_ptr, CollectionView* > m_collectionViews; - QHash< Tomahawk::collection_ptr, ArtistView* > m_treeViews; - QHash< Tomahawk::collection_ptr, AlbumView* > m_collectionAlbumViews; - QHash< Tomahawk::artist_ptr, ArtistInfoWidget* > m_artistViews; - QHash< Tomahawk::album_ptr, AlbumInfoWidget* > m_albumViews; - QHash< Tomahawk::playlist_ptr, PlaylistView* > m_playlistViews; - QHash< Tomahawk::source_ptr, SourceInfoWidget* > m_sourceViews; + QHash< Tomahawk::dynplaylist_ptr, QWeakPointer > m_dynamicWidgets; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_collectionViews; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_treeViews; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_collectionAlbumViews; + QHash< Tomahawk::artist_ptr, QWeakPointer > m_artistViews; + QHash< Tomahawk::album_ptr, QWeakPointer > m_albumViews; + QHash< Tomahawk::playlist_ptr, QWeakPointer > m_playlistViews; + QHash< Tomahawk::source_ptr, QWeakPointer > m_sourceViews; QList m_pageHistory; - int m_historyPosition; Tomahawk::collection_ptr m_currentCollection; int m_currentMode; diff --git a/src/libtomahawk/widgets/newplaylistwidget.cpp b/src/libtomahawk/widgets/newplaylistwidget.cpp index 201a7b015..01b7fdffa 100644 --- a/src/libtomahawk/widgets/newplaylistwidget.cpp +++ b/src/libtomahawk/widgets/newplaylistwidget.cpp @@ -149,6 +149,6 @@ NewPlaylistWidget::savePlaylist() void NewPlaylistWidget::cancel() { + // will be deleted by viewmanager emit destroyed( this ); - deleteLater(); } diff --git a/src/searchbox.ui b/src/searchbox.ui index f996396fa..10b0f8783 100644 --- a/src/searchbox.ui +++ b/src/searchbox.ui @@ -7,26 +7,13 @@ 0 0 345 - 31 + 51 Form - - - - Qt::Horizontal - - - - 141 - 20 - - - - diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index aac45bdc1..f5e7c4c0b 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -65,11 +65,9 @@ #ifdef Q_OS_WIN32 #include #endif -#ifdef Q_OS_MAC -#include "widgets/maclineedit.h" -#endif #include "utils/logger.h" +#include "Qocoa/qsearchfield.h" using namespace Tomahawk; @@ -77,7 +75,7 @@ using namespace Tomahawk; TomahawkWindow::TomahawkWindow( QWidget* parent ) : QMainWindow( parent ) , ui( new Ui::TomahawkWindow ) - , m_searchWidget( new Ui::GlobalSearchWidget ) + , m_searchWidget( 0 ) , m_audioControls( new AudioControls( this ) ) , m_trayIcon( new TomahawkTrayIcon( this ) ) { @@ -96,7 +94,6 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) ui->centralWidget->layout()->setSpacing( 0 ); setupSideBar(); - setupToolBar(); statusBar()->addPermanentWidget( m_audioControls, 1 ); setupUpdateCheck(); @@ -195,15 +192,21 @@ TomahawkWindow::setupSideBar() AnimatedSplitter* sidebar = new AnimatedSplitter(); sidebar->setOrientation( Qt::Vertical ); sidebar->setChildrenCollapsible( false ); - sidebar->setGreedyWidget( 0 ); + + m_searchWidget = new QSearchField( sidebar ); + m_searchWidget->setPlaceholderText( "Global Search..." ); + connect( m_searchWidget, SIGNAL( returnPressed() ), this, SLOT( onFilterEdited() ) ); m_sourcetree = new SourceTreeView(); TransferView* transferView = new TransferView( sidebar ); PipelineStatusView* pipelineView = new PipelineStatusView( sidebar ); + sidebar->addWidget( m_searchWidget ); sidebar->addWidget( m_sourcetree ); sidebar->addWidget( transferView ); sidebar->addWidget( pipelineView ); + + sidebar->setGreedyWidget( 1 ); sidebar->hide( 1, false ); sidebar->hide( 2, false ); @@ -227,52 +230,6 @@ TomahawkWindow::setupSideBar() ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() ); } - -void -TomahawkWindow::setupToolBar() -{ - QToolBar* toolbar = addToolBar( "TomahawkToolbar" ); - toolbar->setObjectName( "TomahawkToolbar" ); - toolbar->setMovable( false ); - toolbar->setFloatable( false ); - toolbar->setIconSize( QSize( 28, 28 ) ); - toolbar->setToolButtonStyle( Qt::ToolButtonFollowStyle ); - 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->setToolTip( tr( "Go back one page" ) ); - m_forwardAvailable = toolbar->addAction( QIcon( RESPATH "images/forward.png" ), tr( "Forward" ), ViewManager::instance(), SLOT( historyForward() ) ); - 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" ) ); - lineEdit->setVisible( true ); - 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; }" ); - - connect( m_searchWidget->searchEdit, SIGNAL( returnPressed() ), SLOT( onFilterEdited() ) ); -#endif - - toolbar->addWidget( m_searchBox ); -} - - void TomahawkWindow::setupUpdateCheck() { @@ -360,10 +317,6 @@ TomahawkWindow::setupSignals() connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) ); connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) ); } - - // - connect( ViewManager::instance(), SIGNAL( historyBackAvailable( bool ) ), SLOT( onHistoryBackAvailable( bool ) ) ); - connect( ViewManager::instance(), SIGNAL( historyForwardAvailable( bool ) ), SLOT( onHistoryForwardAvailable( bool ) ) ); } @@ -615,21 +568,6 @@ TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result ) setWindowTitle( m_windowTitle ); } - -void -TomahawkWindow::onHistoryBackAvailable( bool avail ) -{ - m_backAvailable->setEnabled( avail ); -} - - -void -TomahawkWindow::onHistoryForwardAvailable( bool avail ) -{ - m_forwardAvailable->setEnabled( avail ); -} - - void TomahawkWindow::onSipConnected() { @@ -717,8 +655,8 @@ TomahawkWindow::onSearch( const QString& search ) void TomahawkWindow::onFilterEdited() { - onSearch( m_searchWidget->searchEdit->text() ); - m_searchWidget->searchEdit->clear(); + onSearch( m_searchWidget->text() ); + m_searchWidget->clear(); } diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index 988d66899..32e41bc2a 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -27,6 +27,7 @@ #include "result.h" +class QSearchField; class SipPlugin; class SourceTreeView; class QAction; @@ -81,8 +82,6 @@ private slots: void addPeerManually(); void onPlaybackLoading( const Tomahawk::result_ptr& result ); - void onHistoryBackAvailable( bool avail ); - void onHistoryForwardAvailable( bool avail ); void audioStarted(); void audioStopped(); @@ -105,21 +104,16 @@ private: void applyPlatformTweaks(); void setupSignals(); - void setupToolBar(); void setupSideBar(); void setupUpdateCheck(); Ui::TomahawkWindow* ui; - Ui::GlobalSearchWidget* m_searchWidget; - QWidget* m_searchBox; + QSearchField* m_searchWidget; AudioControls* m_audioControls; TomahawkTrayIcon* m_trayIcon; SourceTreeView* m_sourcetree; QPushButton* m_statusButton; - QAction* m_backAvailable; - QAction* m_forwardAvailable; - Tomahawk::result_ptr m_currentTrack; QString m_windowTitle; };