Add table style for search results. Not officially part of 1.3.0, as this is being translated, will be part of 1.4.0

This commit is contained in:
craig.p.drummond
2014-02-05 19:24:52 +00:00
parent d15817dc85
commit 2104a094d3
7 changed files with 166 additions and 11 deletions

View File

@@ -930,7 +930,7 @@ MainWindow::~MainWindow()
streamsPage->save();
StreamsModel::self()->save();
#endif
searchPage->save();
searchPage->saveConfig();
positionSlider->saveConfig();
#ifdef ENABLE_ONLINE_SERVICES
OnlineServicesModel::self()->save();
@@ -1453,6 +1453,7 @@ void MainWindow::readSettings()
#ifdef ENABLE_DEVICES_SUPPORT
devicesPage->setView(Settings::self()->devicesView());
#endif
searchPage->setView(Settings::self()->searchView());
trayItem->setup();
autoScrollPlayQueue=Settings::self()->playQueueScroll();
updateWindowTitle();

View File

@@ -29,6 +29,20 @@
#include "utils.h"
#include "icon.h"
#include "qtplural.h"
#include "tableview.h"
class SearchTableView : public TableView
{
public:
SearchTableView(QWidget *p)
: TableView(QLatin1String("search"), p)
{
setUseSimpleDelegate();
setIndentation(0);
}
virtual ~SearchTableView() { }
};
SearchPage::SearchPage(QWidget *p)
: QWidget(p)
@@ -40,6 +54,7 @@ SearchPage::SearchPage(QWidget *p)
addToPlayQueue->setDefaultAction(StdActions::self()->addToPlayQueueAction);
replacePlayQueue->setDefaultAction(StdActions::self()->replacePlayQueueAction);
view->allowTableView(new SearchTableView(view));
view->addAction(StdActions::self()->addToPlayQueueAction);
view->addAction(StdActions::self()->addRandomToPlayQueueAction);
view->addAction(StdActions::self()->replacePlayQueueAction);
@@ -79,9 +94,13 @@ void SearchPage::showEvent(QShowEvent *e)
QWidget::showEvent(e);
}
void SearchPage::save()
void SearchPage::saveConfig()
{
Settings::self()->saveSearchCategory(view->searchCategory());
TableView *tv=qobject_cast<TableView *>(view->view());
if (tv) {
tv->saveHeader();
}
}
void SearchPage::refresh()
@@ -94,6 +113,12 @@ void SearchPage::clear()
model.clear();
}
void SearchPage::setView(int mode)
{
view->setMode((ItemView::Mode)mode);
model.setMultiColumn(ItemView::Mode_Table==mode);
}
QStringList SearchPage::selectedFiles(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();

View File

@@ -40,9 +40,10 @@ public:
SearchPage(QWidget *p);
virtual ~SearchPage();
void save();
void saveConfig();
void refresh();
void clear();
void setView(int mode);
QStringList selectedFiles(bool allowPlaylists=false) const;
QList<Song> selectedSongs(bool allowPlaylists=false) const;
void addSelectionToPlaylist(const QString &name=QString(), bool replace=false, quint8 priorty=0);

View File

@@ -663,6 +663,11 @@ int Settings::devicesView()
}
#endif
int Settings::searchView()
{
return ItemView::toMode(GET_STRING("searchView", ItemView::modeStr(ItemView::Mode_List)));
}
int Settings::version()
{
if (-1==ver) {
@@ -1273,6 +1278,11 @@ void Settings::saveDevicesView(int v)
}
#endif
void Settings::saveSearchView(int v)
{
SET_ITEMVIEW_MODE_VALUE_MOD(searchView)
}
void Settings::saveStopFadeDuration(int v)
{
if (v<=MinFade) {

View File

@@ -158,6 +158,7 @@ public:
bool showDeleteAction();
int devicesView();
#endif
int searchView();
int version();
int stopFadeDuration();
int httpAllocatedPort();
@@ -274,6 +275,7 @@ public:
void saveShowDeleteAction(bool v);
void saveDevicesView(int v);
#endif
void saveSearchView(int v);
void saveStopFadeDuration(int v);
void saveHttpAllocatedPort(int v);
void saveHttpInterface(const QString &v);

View File

@@ -24,6 +24,7 @@
#include "searchmodel.h"
#include "icons.h"
#include "itemview.h"
#include "tableview.h"
#include "localize.h"
#include "qtplural.h"
#include "mpdconnection.h"
@@ -40,8 +41,24 @@
#include "modeltest.h"
#endif
QString SearchModel::headerText(int col)
{
switch (col) {
case COL_TRACK: return PlayQueueModel::headerText(PlayQueueModel::COL_TRACK);
case COL_DISC: return PlayQueueModel::headerText(PlayQueueModel::COL_DISC);
case COL_TITLE: return PlayQueueModel::headerText(PlayQueueModel::COL_TITLE);
case COL_ARTIST: return PlayQueueModel::headerText(PlayQueueModel::COL_ARTIST);
case COL_ALBUM: return PlayQueueModel::headerText(PlayQueueModel::COL_ALBUM);
case COL_LENGTH: return PlayQueueModel::headerText(PlayQueueModel::COL_LENGTH);
case COL_YEAR: return PlayQueueModel::headerText(PlayQueueModel::COL_YEAR);
case COL_GENRE: return PlayQueueModel::headerText(PlayQueueModel::COL_GENRE);
default: return QString();
}
}
SearchModel::SearchModel(QObject *parent)
: ActionModel(parent)
, multiCol(false)
, currentId(0)
{
connect(this, SIGNAL(search(QString,QString,int)), MPDConnection::self(), SLOT(search(QString,QString,int)));
@@ -68,21 +85,52 @@ QModelIndex SearchModel::parent(const QModelIndex &index) const
return QModelIndex();
}
QVariant SearchModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const
QVariant SearchModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (Qt::Horizontal==orientation) {
switch (role) {
case Qt::DisplayRole:
return headerText(section);
case Qt::TextAlignmentRole:
switch (section) {
case COL_TITLE:
case COL_ARTIST:
case COL_ALBUM:
case COL_GENRE:
default:
return int(Qt::AlignVCenter|Qt::AlignLeft);
case COL_TRACK:
case COL_LENGTH:
case COL_DISC:
case COL_YEAR:
return int(Qt::AlignVCenter|Qt::AlignRight);
}
case TableView::Role_Hideable:
return COL_YEAR==section || COL_DISC==section || COL_GENRE==section ? true : false;
case TableView::Role_Width:
switch (section) {
case COL_TRACK: return 0.075;
case COL_DISC: return 0.03;
case COL_TITLE: return 0.3;
case COL_ARTIST: return 0.27;
case COL_ALBUM: return 0.27;
case COL_LENGTH: return 0.05;
case COL_YEAR: return 0.05;
case COL_GENRE: return 0.115;
}
default:
break;
}
}
return QVariant();
}
int SearchModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : songList.count();
}
int SearchModel::columnCount(const QModelIndex &) const
{
return 1;
}
QVariant SearchModel::data(const QModelIndex &index, int role) const
{
const Song *song = toSong(index);
@@ -93,12 +141,61 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DecorationRole:
if (multiCol) {
return QVariant();
}
return Song::Playlist==song->type
? Icons::self()->playlistIcon
: song->isStream()
? Icons::self()->streamIcon
: Icons::self()->audioFileIcon;
case Qt::TextAlignmentRole:
switch (index.column()) {
case COL_TITLE:
case COL_ARTIST:
case COL_ALBUM:
case COL_GENRE:
default:
return int(Qt::AlignVCenter|Qt::AlignLeft);
case COL_TRACK:
case COL_LENGTH:
case COL_DISC:
case COL_YEAR:
return int(Qt::AlignVCenter|Qt::AlignRight);
}
case Qt::DisplayRole:
if (multiCol) {
switch (index.column()) {
case COL_TITLE:
return song->title.isEmpty() ? Utils::getFile(song->file) : song->title;
case COL_ARTIST:
return song->artist.isEmpty() ? Song::unknown() : song->artist;
case COL_ALBUM:
return song->album.isEmpty() && !song->name.isEmpty() && song->isStream() ? song->name : song->album;
case COL_TRACK:
if (song->track <= 0) {
return QVariant();
}
return song->track;
case COL_LENGTH:
return Song::formattedTime(song->time);
case COL_DISC:
if (song->disc <= 0) {
return QVariant();
}
return song->disc;
case COL_YEAR:
if (song->year <= 0) {
return QVariant();
}
return song->year;
case COL_GENRE:
return song->genre;
default:
break;
}
break;
}
case Qt::ToolTipRole: {
QString text=song->entryName();

View File

@@ -33,13 +33,30 @@ class SearchModel : public ActionModel
Q_OBJECT
public:
enum Columns
{
COL_TRACK,
COL_DISC,
COL_TITLE,
COL_ARTIST,
COL_ALBUM,
COL_LENGTH,
COL_YEAR,
COL_GENRE,
COL_COUNT
};
static QString headerText(int col);
SearchModel(QObject *parent = 0);
~SearchModel();
QModelIndex index(int, int, const QModelIndex & = QModelIndex()) const;
QModelIndex parent(const QModelIndex &) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &) const;
int columnCount(const QModelIndex &) const { return COL_COUNT; }
QVariant data(const QModelIndex &, int) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
@@ -51,7 +68,8 @@ public:
void refresh();
void clear();
void search(const QString &key, const QString &value);
void setMultiColumn(bool m) { multiCol=m; }
Q_SIGNALS:
void searching();
void searched();
@@ -67,6 +85,7 @@ private:
const Song * toSong(const QModelIndex &index) const { return index.isValid() ? static_cast<const Song *>(index.internalPointer()) : 0; }
private:
bool multiCol;
QList<Song> songList;
int currentId;
QString currentKey;