Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit d5603e9a authored by Arnold Dumas's avatar Arnold Dumas

Port the Cover dialog from K3ListView and Q3IconView to KListWidget.

REVIEW: 115957
parent bd33a7b0
/**
* Copyright (C) 2005 Michael Pyne <mpyne@kde.org>
* Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.com>
*
* 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
......@@ -16,9 +17,6 @@
#include "coverdialog.h"
#include <k3listview.h>
#include <k3iconview.h>
#include <k3iconviewsearchline.h>
#include <kiconloader.h>
#include <kapplication.h>
#include <kmenu.h>
......@@ -32,32 +30,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());
}
};
......@@ -68,11 +66,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()
......@@ -86,13 +89,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();
}
......@@ -119,7 +119,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();
if (!item) {
......@@ -130,7 +130,7 @@ void CoverDialog::slotArtistClicked(Q3ListViewItem *item)
loadCovers();
}
else {
QString artist = item->text(0).toLower();
QString artist = item->text().toLower();
CoverDataMapIterator it, end;
......@@ -144,10 +144,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;
......@@ -156,7 +158,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()
......
/**
* Copyright (C) 2005 Michael Pyne <mpyne@kde.org>
* Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.com>
*
* 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
......@@ -21,6 +22,8 @@
#include <QWidget>
class QListWidgetItem;
class CoverDialog : public QWidget, public Ui::CoverDialogBase
{
Q_OBJECT
......@@ -31,8 +34,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>
/**
* Copyright (C) 2005 Michael Pyne <mpyne@kde.org>
* Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.com>
*
* 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
......@@ -19,34 +20,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:
/**
* Copyright (C) 2005 Michael Pyne <mpyne@kde.org>
* Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.com>
*
* 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
......@@ -17,7 +18,7 @@
#ifndef COVERICONVIEW_H
#define COVERICONVIEW_H
#include <k3iconview.h>
#include <klistwidget.h>
#include "covermanager.h"
......@@ -28,10 +29,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; }
......@@ -43,12 +44,12 @@ namespace CoverUtility
using CoverUtility::CoverIconViewItem;
/**
* This class subclasses K3IconView in order to provide cover drag-and-drop
* This class subclasses QListWidget in order to provide cover drag-and-drop
* support.
*
* @author Michael Pyne <mpyne@kde.org>
*/
class CoverIconView : public K3IconView
class CoverIconView : public KListWidget
{
public:
explicit CoverIconView(QWidget *parent, const char *name = 0);
......@@ -56,7 +57,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