diff --git a/coverdialog.cpp b/coverdialog.cpp index 7389d97c..c215090b 100644 --- a/coverdialog.cpp +++ b/coverdialog.cpp @@ -1,211 +1,211 @@ /** * Copyright (C) 2005 Michael Pyne * Copyright (C) 2014 Arnold Dumas * * This program 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 2 of the License, or (at your option) any later * version. * * This program 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 * this program. If not, see . */ #include "coverdialog.h" #include #include #include #include #include "covericonview.h" #include "covermanager.h" #include "collectionlist.h" #include "juk_debug.h" using CoverUtility::CoverIconViewItem; class AllArtistsListViewItem : public QListWidgetItem { public: - AllArtistsListViewItem(KListWidget *parent) : + AllArtistsListViewItem(QListWidget *parent) : QListWidgetItem(i18n("<All Artists>"), parent) { } bool operator< (const QListWidgetItem& other) const { Q_UNUSED(other); return true; // Always be at the top. } }; class CaseInsensitiveItem : public QListWidgetItem { public: - CaseInsensitiveItem(KListWidget *parent, const QString &text) : + CaseInsensitiveItem(QListWidget *parent, const QString &text) : QListWidgetItem(text, parent) { } bool operator< (const QListWidgetItem& other) const { return text().toLower().localeAwareCompare(other.text().toLower()); } }; CoverDialog::CoverDialog(QWidget *parent) : QWidget(parent, Qt::Dialog) { setupUi(this); - setObjectName( QLatin1String("juk_cover_dialog" )); + setObjectName(QLatin1String("juk_cover_dialog")); - m_searchLine->setClearButtonShown(true); + m_searchLine->setClearButtonEnabled(true); connect(m_artists, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotArtistClicked(QListWidgetItem*))); connect(m_covers, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextRequested(QPoint))); connect(m_searchLine, SIGNAL(textChanged(QString)), this, SLOT(slotSearchPatternChanged(QString))); } CoverDialog::~CoverDialog() { } void CoverDialog::show() { m_artists->clear(); m_covers->clear(); QStringList artists = CollectionList::instance()->uniqueSet(CollectionList::Artists); new AllArtistsListViewItem(m_artists); for(QStringList::ConstIterator it = artists.constBegin(); it != artists.constEnd(); ++it) new CaseInsensitiveItem(m_artists, *it); QTimer::singleShot(0, this, SLOT(loadCovers())); QWidget::show(); } // TODO: Make this concurrent on a non-GUI thread void CoverDialog::loadCovers() { auto it = CoverManager::begin(); const auto &end = CoverManager::end(); for(; it != end; ++it) { (void) new CoverIconViewItem(it->first, m_covers); } } // TODO: Add a way to show cover art for tracks with no artist. void CoverDialog::slotArtistClicked(QListWidgetItem *item) { m_covers->clear(); if (!item) { return; } if(dynamic_cast(item)) { // All artists. loadCovers(); } else { QString artist = item->text().toLower(); CoverDataMapIterator it, end; it = CoverManager::begin(); end = CoverManager::end(); for(; it != end; ++it) { if(it->second.artist == artist) (void) new CoverIconViewItem(it->first, m_covers); } } } void CoverDialog::slotContextRequested(const QPoint &pt) { static KMenu *menu = 0; QListWidgetItem* item = m_covers->currentItem(); if(!item) return; if(!menu) { menu = new KMenu(this); menu->addAction(i18n("Remove Cover"), this, SLOT(removeSelectedCover())); } QPoint globalPt = m_covers->mapToGlobal(pt); menu->popup(globalPt); } void CoverDialog::slotSearchPatternChanged(const QString& pattern) { m_covers->clear(); QListWidgetItem* item = m_artists->currentItem(); // If the expression is cleared, then use slotArtistClicked. if (pattern.isEmpty()) { slotArtistClicked(item); } else { QRegExp filter(pattern, Qt::CaseInsensitive, QRegExp::Wildcard); QString artist = item->text().toLower(); CoverDataMapIterator it = CoverManager::begin(); const CoverDataMapIterator end = CoverManager::end(); // Here, only show cover that match the search pattern. if (dynamic_cast(item)) { for(; it != end; ++it) { if (filter.indexIn(it->second.artist) != -1) { (void) new CoverIconViewItem(it->first, m_covers); } } } // Here, only show the covers that match the search pattern and // that have the same artist as the currently selected one. else { for(; it != end; ++it) { if (it->second.artist == artist && ((filter.indexIn(it->second.artist) != -1) || (filter.indexIn(it->second.album) != -1))) { (void) new CoverIconViewItem(it->first, m_covers); } } } } } void CoverDialog::removeSelectedCover() { CoverIconViewItem *coverItem = m_covers->currentItem(); if(!coverItem || !coverItem->isSelected()) { qCWarning(JUK_LOG) << "No item selected for removeSelectedCover.\n"; return; } if(!CoverManager::removeCover(coverItem->id())) qCCritical(JUK_LOG) << "Unable to remove selected cover: " << coverItem->id(); else delete coverItem; } // vim: set et sw=4 tw=0 sta: diff --git a/coverdialog.h b/coverdialog.h index 84bba17c..1d493665 100644 --- a/coverdialog.h +++ b/coverdialog.h @@ -1,48 +1,48 @@ /** * Copyright (C) 2005 Michael Pyne * Copyright (C) 2014 Arnold Dumas * * This program 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 2 of the License, or (at your option) any later * version. * * This program 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 * this program. If not, see . */ -#ifndef COVERDIALOG_H -#define COVERDIALOG_H +#ifndef JUK_COVERDIALOG_H +#define JUK_COVERDIALOG_H #include "ui_coverdialogbase.h" #include class QListWidgetItem; class CoverDialog : public QWidget, public Ui::CoverDialogBase { Q_OBJECT public: CoverDialog(QWidget *parent); ~CoverDialog(); virtual void show(); public slots: void slotArtistClicked(QListWidgetItem *item); void slotContextRequested(const QPoint &pt); void slotSearchPatternChanged(const QString& pattern); private slots: void loadCovers(); void removeSelectedCover(); }; -#endif /* COVERDIALOG_H */ +#endif /* JUK_COVERDIALOG_H */ // vim: set et sw=4 tw=0 sta: diff --git a/coverdialogbase.ui b/coverdialogbase.ui index 98626056..800e0712 100644 --- a/coverdialogbase.ui +++ b/coverdialogbase.ui @@ -1,116 +1,121 @@ - + + CoverDialogBase - - + + 0 0 685 554 - + Cover Manager - - + + + 6 + + 11 - - 6 + + 11 + + + 11 + + + 11 - - - - 5 - 7 + + + 0 0 - + 164 0 - - - Artist - - - - + + + 6 + + 0 - - 6 + + 0 + + + 0 + + + 0 - - + + + 6 + + 0 - - 6 + + 0 + + + 0 + + + 0 - - - - 5 - 0 + + + 1 0 - - - - 7 - 7 + + + 1 0 - - KListWidget - QListWidget -
klistwidget.h
-
- - KLineEdit - QWidget -
klineedit.h
-
CoverIconView QWidget
covericonview.h
1
- klineedit.h - covericonview.h + covericonview.h - - +
diff --git a/covericonview.cpp b/covericonview.cpp index beb762f8..c19033d7 100644 --- a/covericonview.cpp +++ b/covericonview.cpp @@ -1,47 +1,47 @@ /** * Copyright (C) 2005 Michael Pyne * Copyright (C) 2014 Arnold Dumas * * This program 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 2 of the License, or (at your option) any later * version. * * This program 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 * this program. If not, see . */ #include "covericonview.h" #include "covermanager.h" using CoverUtility::CoverIconViewItem; -CoverIconViewItem::CoverIconViewItem(coverKey id, KListWidget *parent) : +CoverIconViewItem::CoverIconViewItem(coverKey id, QListWidget *parent) : QListWidgetItem(parent), m_id(id) { const auto &data = CoverManager::coverInfo(id); setText(QString("%1 - %2").arg(data.artist, data.album)); setIcon(data.thumbnail()); setSizeHint(QSize(140, 150)); } -CoverIconView::CoverIconView(QWidget *parent, const char *name) : KListWidget(parent) +CoverIconView::CoverIconView(QWidget *parent, const char *name) : QListWidget(parent) { setObjectName(QLatin1String(name)); - setResizeMode(KListWidget::Adjust); - setViewMode(KListWidget::IconMode); - setIconSize(QSize(130, 140)); - setMovement(KListWidget::Static); + setResizeMode(QListWidget::Adjust); + setViewMode(QListWidget::IconMode); + setIconSize(QSize(130, 140)); // FIXME: HiDPI + setMovement(QListWidget::Static); setContextMenuPolicy(Qt::CustomContextMenu); } CoverIconViewItem *CoverIconView::currentItem() const { - return static_cast(KListWidget::currentItem()); + return static_cast(QListWidget::currentItem()); } // vim: set et sw=4 tw=0 sta: diff --git a/covericonview.h b/covericonview.h index 426dac87..802be859 100644 --- a/covericonview.h +++ b/covericonview.h @@ -1,65 +1,65 @@ /** * Copyright (C) 2005 Michael Pyne * Copyright (C) 2014 Arnold Dumas * * This program 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 2 of the License, or (at your option) any later * version. * * This program 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 * this program. If not, see . */ -#ifndef COVERICONVIEW_H -#define COVERICONVIEW_H +#ifndef JUK_COVERICONVIEW_H +#define JUK_COVERICONVIEW_H -#include +#include #include "covermanager.h" // The WebImageFetcher dialog also has a class named CoverIconViewItem and I // don't like the idea of naming it "CoverIVI" or something, so just namespace // it out. I would merge them except for webimagefetcher's dependence on KIO // and such. namespace CoverUtility { class CoverIconViewItem : public QListWidgetItem { public: - CoverIconViewItem(coverKey id, KListWidget *parent); + CoverIconViewItem(coverKey id, QListWidget *parent); coverKey id() const { return m_id; } private: coverKey m_id; }; } using CoverUtility::CoverIconViewItem; /** * This class subclasses QListWidget in order to provide cover drag-and-drop * support. * * @author Michael Pyne */ -class CoverIconView : public KListWidget +class CoverIconView : public QListWidget { public: explicit CoverIconView(QWidget *parent, const char *name = 0); CoverIconViewItem *currentItem() const; protected: // virtual Q3DragObject *dragObject(); }; -#endif /* COVERICONVIEW_H */ +#endif /* JUK_COVERICONVIEW_H */ // vim: set et sw=4 tw=0 sta: