Commit de290e15 authored by Michael Pyne's avatar Michael Pyne
Browse files

playlistsplitter: Minor cleanups again.

parent d6b28a9b
......@@ -50,18 +50,9 @@
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistSplitter::PlaylistSplitter(PlayerManager *player, QWidget *parent) :
QSplitter(Qt::Horizontal, parent),
m_newVisible(0),
m_playlistBox(0),
m_searchWidget(0),
m_playlistStack(0),
m_editor(0),
m_nowPlaying(0),
m_player(player),
m_lyricsWidget(0),
m_editorSplitter(0)
PlaylistSplitter::PlaylistSplitter(PlayerManager *player, QWidget *parent)
: QSplitter(Qt::Horizontal, parent)
, m_player(player)
{
setObjectName(QLatin1String("playlistSplitter"));
......@@ -83,20 +74,24 @@ PlaylistSplitter::~PlaylistSplitter()
// destroy it now.
delete m_editor;
m_editor = nullptr;
delete m_lyricsWidget;
m_lyricsWidget = nullptr;
// NowPlaying depends on the PlaylistCollection, so kill it now.
delete m_nowPlaying;
m_nowPlaying = 0;
m_nowPlaying = nullptr;
delete m_searchWidget; // Take no chances here either.
m_searchWidget = nullptr;
// Since we want to ensure that the shutdown process for the PlaylistCollection
// (a base class for PlaylistBox) has a chance to write the playlists to disk
// before they are deleted we're explicitly deleting the PlaylistBox here.
delete m_playlistBox;
m_playlistBox = nullptr;
}
PlaylistInterface *PlaylistSplitter::playlist() const
......@@ -121,26 +116,29 @@ void PlaylistSplitter::slotFocusCurrentPlaylist()
{
Playlist *playlist = m_playlistBox->visiblePlaylist();
if(playlist) {
playlist->setFocus();
playlist->clearSelection();
if(!playlist) {
return;
}
// Select the top visible (and matching) item.
playlist->setFocus();
playlist->clearSelection();
PlaylistItem *item = static_cast<PlaylistItem *>(playlist->itemAt(QPoint(0, 0)));
// Select the top visible (and matching) item.
if(!item)
return;
PlaylistItem *item = static_cast<PlaylistItem *>(playlist->itemAt(QPoint(0, 0)));
// A little bit of a hack to make QListView repaint things properly. Switch
// to single selection mode, set the selection and then switch back.
if(!item) {
return;
}
playlist->setSelectionMode(QTreeWidget::SingleSelection);
// A little bit of a hack to make QListView repaint things properly. Switch
// to single selection mode, set the selection and then switch back.
playlist->setCurrentItem(item);
playlist->setSelectionMode(QTreeWidget::SingleSelection);
playlist->setSelectionMode(QTreeWidget::ExtendedSelection);
}
playlist->setCurrentItem(item);
playlist->setSelectionMode(QTreeWidget::ExtendedSelection);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -156,7 +154,7 @@ void PlaylistSplitter::setupActions()
{
KActionCollection* coll = ActionCollection::actions();
KToggleAction *showSearch =
new KToggleAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Show &Search Bar"), this);
new KToggleAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Show &Search Bar"), this);
coll->addAction("showSearch", showSearch);
QAction *act = new QAction(QIcon::fromTheme(QStringLiteral("edit-clear")), i18n("Edit Track Search"), this);
......@@ -301,9 +299,7 @@ void PlaylistSplitter::saveConfig()
void PlaylistSplitter::slotShowSearchResults()
{
PlaylistList playlists;
playlists.append(visiblePlaylist());
visiblePlaylist()->setSearch(m_searchWidget->search(playlists));
visiblePlaylist()->setSearch(m_searchWidget->search(visiblePlaylist()));
}
void PlaylistSplitter::slotPlaylistSelectionChanged()
......@@ -320,7 +316,7 @@ void PlaylistSplitter::slotPlaylistChanged(int i)
m_newVisible = p;
m_searchWidget->setSearch(p->search());
m_newVisible = 0;
m_newVisible = nullptr;
}
void PlaylistSplitter::slotCurrentPlaylistChanged(QTreeWidgetItem *item)
......
......@@ -90,15 +90,41 @@ private slots:
void slotCurrentPlaylistChanged(QTreeWidgetItem *item);
private:
Playlist *m_newVisible;
PlaylistBox *m_playlistBox;
SearchWidget *m_searchWidget;
QStackedWidget *m_playlistStack;
TagEditor *m_editor;
NowPlaying *m_nowPlaying;
PlayerManager *m_player;
LyricsWidget *m_lyricsWidget;
QSplitter *m_editorSplitter;
// These classes appear in the main user interface in the following arrangement/layout:
// (note the left/right splitter is the reason this class is named as it is and why it
// is a subclass of QSplitter).
//
// +-----------+--------------------------------------------------------------+---------+
// | Playlist | NowPlaying* | Lyrics |
// | Box* +--------------------------------------------------------------+ Widget* |
// | | SearchWidget* | |
// | +--------------------------------------------------------------+ |
// | ^ Playlist* (multiple; stacked under QStackedWidget*) | |
// | | -------------- --------- -------- --------- ----------- | |
// | * PlaylistItem*s | |
// | splitter t -------------- --------- -------- --------- ----------- | |
// | handle h | |
// | ------> i -------------- --------- -------- --------- ----------- | |
// | s | |
// | | -------------- --------- -------- --------- ----------- | |
// | , ... | |
// | | ... | |
// | +-------------[ splitter handle m_editorSplitter ]-------------+ |
// | | TagEditor* | |
// | | | |
// | | | |
// +-----------+--------------------------------------------------------------+---------+
PlaylistBox *m_playlistBox = nullptr;
QSplitter *m_editorSplitter = nullptr;
NowPlaying *m_nowPlaying = nullptr;
SearchWidget *m_searchWidget = nullptr;
QStackedWidget *m_playlistStack = nullptr;
TagEditor *m_editor = nullptr;
LyricsWidget *m_lyricsWidget = nullptr;
Playlist *m_newVisible = nullptr;
PlayerManager *m_player = nullptr;
};
#endif
......
......@@ -21,6 +21,8 @@
#include "searchadaptor.h"
#include "juk_debug.h"
#include <utility>
#include <KLocalizedString>
#include <QAction>
......@@ -230,9 +232,17 @@ PlaylistSearch* SearchWidget::search(const PlaylistList &playlists) const
{
PlaylistSearch::ComponentList components;
components.append(searchComponent());
return new PlaylistSearch(playlists, components);
return new PlaylistSearch(std::move(playlists), std::move(components));
}
PlaylistSearch* SearchWidget::search(Playlist *playlist) const
{
PlaylistSearch::ComponentList components;
components.append(searchComponent());
PlaylistList playlists = (PlaylistList{} << playlist);
return new PlaylistSearch(std::move(playlists), std::move(components));
}
////////////////////////////////////////////////////////////////////////////////
// SearchWidget public slots
......
......@@ -75,6 +75,7 @@ public:
explicit SearchWidget(QWidget *parent);
PlaylistSearch* search(const PlaylistList& playlists) const;
PlaylistSearch* search(Playlist *playlist) const;
void setSearch(const PlaylistSearch* search);
virtual QString searchText() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment