Commit f77b6cb1 authored by Arnold Dumas's avatar Arnold Dumas

Port the Cover dialog from K3ListView and Q3IconView to KListWidget.

parent 3d4eafcc
/***************************************************************************
begin : Sun May 15 2005
copyright : (C) 2005 by Michael Pyne
: (C) 2014 by Arnold Dumas <contact@arnolddumas.fr>
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -15,9 +16,6 @@
#include "coverdialog.h"
#include <k3listview.h>
#include <k3iconview.h>
#include <k3iconviewsearchline.h>
#include <kiconloader.h>
#include <kapplication.h>
#include <kmenu.h>
......@@ -31,32 +29,32 @@
using CoverUtility::CoverIconViewItem;
class AllArtistsListViewItem : public K3ListViewItem
class AllArtistsListViewItem : public QListWidgetItem
{
public:
AllArtistsListViewItem(Q3ListView *parent) :
K3ListViewItem(parent, i18n("&lt;All Artists&gt;"))
AllArtistsListViewItem(KListWidget *parent) :
QListWidgetItem(i18n("&lt;All Artists&gt;"), parent)
{
}
int compare(Q3ListViewItem *, int, bool) const
bool operator< (const QListWidgetItem& other) const
{
return -1; // Always be at the top.
Q_UNUSED(other);
return true; // Always be at the top.
}
};
class CaseInsensitiveItem : public K3ListViewItem
class CaseInsensitiveItem : public QListWidgetItem
{
public:
CaseInsensitiveItem(Q3ListView *parent, const QString &text) :
K3ListViewItem(parent, text)
CaseInsensitiveItem(KListWidget *parent, const QString &text) :
QListWidgetItem(text, parent)
{
}
int compare(Q3ListViewItem *item, int column, bool ascending) const
bool operator< (const QListWidgetItem& other) const
{
Q_UNUSED(ascending);
return text(column).toLower().localeAwareCompare(item->text(column).toLower());
return text().toLower().localeAwareCompare(other.text().toLower());
}
};
......@@ -67,11 +65,16 @@ CoverDialog::CoverDialog(QWidget *parent) :
setObjectName( QLatin1String("juk_cover_dialog" ));
m_covers->setResizeMode(Q3IconView::Adjust);
m_covers->setGridX(140);
m_covers->setGridY(150);
m_searchLine->setClearButtonShown(true);
m_searchLine->setIconView(m_covers);
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()
......@@ -85,13 +88,10 @@ void CoverDialog::show()
QStringList artists = CollectionList::instance()->uniqueSet(CollectionList::Artists);
m_artists->setSorting(-1);
new AllArtistsListViewItem(m_artists);
for(QStringList::ConstIterator it = artists.constBegin(); it != artists.constEnd(); ++it)
new CaseInsensitiveItem(m_artists, *it);
m_artists->setSorting(0);
QTimer::singleShot(0, this, SLOT(loadCovers()));
QWidget::show();
}
......@@ -118,7 +118,7 @@ void CoverDialog::loadCovers()
}
// TODO: Add a way to show cover art for tracks with no artist.
void CoverDialog::slotArtistClicked(Q3ListViewItem *item)
void CoverDialog::slotArtistClicked(QListWidgetItem *item)
{
m_covers->clear();
......@@ -127,7 +127,7 @@ void CoverDialog::slotArtistClicked(Q3ListViewItem *item)
loadCovers();
}
else {
QString artist = item->text(0).toLower();
QString artist = item->text().toLower();
CoverDataMapIterator it, end;
......@@ -141,10 +141,12 @@ void CoverDialog::slotArtistClicked(Q3ListViewItem *item)
}
}
void CoverDialog::slotContextRequested(Q3IconViewItem *item, const QPoint &pt)
void CoverDialog::slotContextRequested(const QPoint &pt)
{
static KMenu *menu = 0;
QListWidgetItem* item = m_covers->currentItem();
if(!item)
return;
......@@ -153,7 +155,55 @@ void CoverDialog::slotContextRequested(Q3IconViewItem *item, const QPoint &pt)
menu->addAction(i18n("Remove Cover"), this, SLOT(removeSelectedCover()));
}
menu->popup(pt);
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, end;
it = CoverManager::begin();
end = CoverManager::end();
// Here, only show cover that match the search pattern.
if (dynamic_cast<AllArtistsListViewItem *>(item)) {
for(; it != end; ++it) {
if (filter.indexIn(it.value()->artist) != -1) {
(void) new CoverIconViewItem(it.key(), 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.value()->artist == artist
&& (filter.indexIn(it.value()->artist) != -1)
|| (filter.indexIn(it.value()->album) != -1)) {
(void) new CoverIconViewItem(it.key(), m_covers);
}
}
}
}
}
void CoverDialog::removeSelectedCover()
......
/***************************************************************************
begin : Sun May 15 2005
copyright : (C) 2005 by Michael Pyne
: (C) 2014 by Arnold Dumas <contact@arnolddumas.fr>
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -20,6 +21,8 @@
#include <QWidget>
class QListWidgetItem;
class CoverDialog : public QWidget, public Ui::CoverDialogBase
{
Q_OBJECT
......@@ -30,8 +33,9 @@ public:
virtual void show();
public slots:
void slotArtistClicked(Q3ListViewItem *item);
void slotContextRequested(Q3IconViewItem *item, const QPoint &pt);
void slotArtistClicked(QListWidgetItem *item);
void slotContextRequested(const QPoint &pt);
void slotSearchPatternChanged(const QString& pattern);
private slots:
void loadCovers();
......
......@@ -20,7 +20,7 @@
<number>6</number>
</property>
<item>
<widget class="K3ListView" name="m_artists" >
<widget class="KListWidget" name="m_artists" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
......@@ -35,12 +35,6 @@
<height>0</height>
</size>
</property>
<property name="resizeMode" >
<enum>Q3ListView::LastColumn</enum>
</property>
<property name="shadeSortColumn" >
<bool>false</bool>
</property>
<column>
<property name="text" >
<string>Artist</string>
......@@ -65,7 +59,7 @@
<number>6</number>
</property>
<item>
<widget class="K3IconViewSearchLine" native="1" name="m_searchLine" >
<widget class="KLineEdit" native="1" name="m_searchLine" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
......@@ -96,14 +90,14 @@
</widget>
<customwidgets>
<customwidget>
<class>K3ListView</class>
<extends>Q3ListView</extends>
<header>k3listview.h</header>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
<customwidget>
<class>K3IconViewSearchLine</class>
<class>KLineEdit</class>
<extends>QWidget</extends>
<header>k3iconviewsearchline.h</header>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>CoverIconView</class>
......@@ -114,42 +108,10 @@
</customwidgets>
<includes>
<include location="local" >k3listview.h</include>
<include location="local" >k3iconviewsearchline.h</include>
<include location="local" >klineedit.h</include>
<include location="local" >covericonview.h</include>
</includes>
<resources/>
<connections>
<connection>
<sender>m_artists</sender>
<signal>clicked(Q3ListViewItem*)</signal>
<receiver>CoverDialogBase</receiver>
<slot>slotArtistClicked(Q3ListViewItem*)</slot>
<hints>
<hint type="sourcelabel" >
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_covers</sender>
<signal>contextMenuRequested(Q3IconViewItem*,QPoint)</signal>
<receiver>CoverDialogBase</receiver>
<slot>slotContextRequested(Q3IconViewItem*,QPoint)</slot>
<hints>
<hint type="sourcelabel" >
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/***************************************************************************
begin : Sat Jul 9 2005
copyright : (C) 2005 by Michael Pyne
: (C) 2014 by Arnold Dumas <contact@arnolddumas.fr>
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -18,34 +19,41 @@
using CoverUtility::CoverIconViewItem;
CoverIconViewItem::CoverIconViewItem(coverKey id, Q3IconView *parent) :
K3IconViewItem(parent), m_id(id)
CoverIconViewItem::CoverIconViewItem(coverKey id, KListWidget *parent) :
QListWidgetItem(parent), m_id(id)
{
CoverDataPtr data = CoverManager::coverInfo(id);
setText(QString("%1 - %2").arg(data->artist, data->album));
setPixmap(data->thumbnail());
setIcon(data->thumbnail());
setSizeHint(QSize(140, 150));
}
CoverIconView::CoverIconView(QWidget *parent, const char *name) : K3IconView(parent, name)
CoverIconView::CoverIconView(QWidget *parent, const char *name) : KListWidget(parent)
{
setResizeMode(Adjust);
setObjectName(name);
setResizeMode(KListWidget::Adjust);
setViewMode(KListWidget::IconMode);
setIconSize(QSize(130, 140));
setMovement(KListWidget::Static);
setContextMenuPolicy(Qt::CustomContextMenu);
}
CoverIconViewItem *CoverIconView::currentItem() const
{
return static_cast<CoverIconViewItem *>(K3IconView::currentItem());
return static_cast<CoverIconViewItem *>(KListWidget::currentItem());
}
// TODO: port to Qt4
#if 0
Q3DragObject *CoverIconView::dragObject()
{
#if 0
// Temporarily disabled pending conversion of the cover manager icon view
// to Qt 4 ish stuff.
CoverIconViewItem *item = currentItem();
if(item)
return new CoverDrag(item->id(), this);
#endif
return 0;
}
#endif
// vim: set et sw=4 tw=0 sta:
/***************************************************************************
begin : Sat Jul 9 2005
copyright : (C) 2005 by Michael Pyne
: (C) 2014 by Arnold Dumas <contact@arnolddumas.fr>
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -16,7 +17,7 @@
#ifndef COVERICONVIEW_H
#define COVERICONVIEW_H
#include <k3iconview.h>
#include <klistwidget.h>
#include "covermanager.h"
......@@ -27,10 +28,10 @@
namespace CoverUtility
{
class CoverIconViewItem : public K3IconViewItem
class CoverIconViewItem : public QListWidgetItem
{
public:
CoverIconViewItem(coverKey id, Q3IconView *parent);
CoverIconViewItem(coverKey id, KListWidget *parent);
coverKey id() const { return m_id; }
......@@ -42,12 +43,12 @@ namespace CoverUtility
using CoverUtility::CoverIconViewItem;
/**
* This class subclasses K3IconView in order to provide cover drag-and-drop
* This class subclasses KListWidget in order to provide cover drag-and-drop
* support.
*
* @author Michael Pyne <michael.pyne@kdemail.net>
*/
class CoverIconView : public K3IconView
class CoverIconView : public KListWidget
{
public:
explicit CoverIconView(QWidget *parent, const char *name = 0);
......@@ -55,7 +56,7 @@ public:
CoverIconViewItem *currentItem() const;
protected:
virtual Q3DragObject *dragObject();
// virtual Q3DragObject *dragObject();
};
#endif /* COVERICONVIEW_H */
......
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