2014-11-12 15:01:08 +01:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2014 Werner Schweer
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "scoreBrowser.h"
|
2014-11-12 16:36:40 +01:00
|
|
|
#include "musescore.h"
|
2014-11-14 11:44:48 +01:00
|
|
|
#include "icons.h"
|
2014-11-12 15:01:08 +01:00
|
|
|
#include "libmscore/score.h"
|
|
|
|
|
|
|
|
namespace Ms {
|
|
|
|
|
2014-11-19 14:26:20 +01:00
|
|
|
static const int CELLW = 110;
|
|
|
|
static const int CELLH = 130;
|
|
|
|
static const int SPACE = 10;
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// sizeHint
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QSize ScoreListWidget::sizeHint() const
|
|
|
|
{
|
|
|
|
int cols = (width()-SPACE) / (CELLW + SPACE);
|
|
|
|
int n = count();
|
|
|
|
int rows = (n+cols-1) / cols;
|
|
|
|
if (rows <= 0)
|
|
|
|
rows = 1;
|
|
|
|
// printf("ScoreListWidget count %d width %d %d %d\n", count(), width(), cols, rows);
|
|
|
|
return QSize(cols * CELLW, rows * (CELLH + SPACE) + SPACE);
|
|
|
|
}
|
|
|
|
|
2014-11-12 15:01:08 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ScoreItem
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class ScoreItem : public QListWidgetItem
|
|
|
|
{
|
|
|
|
ScoreInfo _info;
|
|
|
|
|
|
|
|
public:
|
2014-11-14 11:44:48 +01:00
|
|
|
ScoreItem(const ScoreInfo& i) : QListWidgetItem(), _info(i) {
|
2014-11-19 14:26:20 +01:00
|
|
|
setSizeHint(QSize(CELLW, CELLH));
|
2014-11-14 11:44:48 +01:00
|
|
|
}
|
2014-11-12 15:01:08 +01:00
|
|
|
const ScoreInfo& info() const { return _info; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// ScoreBrowser
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ScoreBrowser::ScoreBrowser(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2014-11-19 14:26:20 +01:00
|
|
|
scoreList->setLayout(new QVBoxLayout);
|
|
|
|
scoreList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// createScoreList
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QListWidget* ScoreBrowser::createScoreList()
|
|
|
|
{
|
|
|
|
ScoreListWidget* sl = new ScoreListWidget;
|
|
|
|
static_cast<QVBoxLayout*>(scoreList->layout())->addWidget(sl);
|
|
|
|
sl->setWrapping(true);
|
|
|
|
sl->setViewMode(QListView::IconMode);
|
|
|
|
sl->setIconSize(QSize(CELLW, CELLH-20));
|
|
|
|
sl->setSpacing(10);
|
|
|
|
sl->setResizeMode(QListView::Adjust);
|
|
|
|
sl->setFlow(QListView::LeftToRight);
|
|
|
|
sl->setMovement(QListView::Static);
|
|
|
|
sl->setTextElideMode(Qt::ElideRight);
|
|
|
|
sl->setUniformItemSizes(true);
|
|
|
|
sl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
|
|
|
|
sl->setLineWidth(0);
|
|
|
|
sl->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
|
|
|
|
sl->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
sl->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
sl->setLayoutMode(QListView::SinglePass);
|
|
|
|
sl->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
|
|
|
|
|
|
connect(sl, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),SLOT(scoreChanged(QListWidgetItem*,QListWidgetItem*)));
|
|
|
|
connect(sl, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(setScoreActivated(QListWidgetItem*)));
|
|
|
|
scoreLists.append(sl);
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// genScoreItem
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ScoreItem* ScoreBrowser::genScoreItem(const QFileInfo& fi)
|
|
|
|
{
|
|
|
|
ScoreInfo si(fi);
|
|
|
|
QPixmap pm = mscore->extractThumbnail(fi.filePath());
|
|
|
|
if (pm.isNull())
|
|
|
|
pm = icons[int(Icons::file_ICON)]->pixmap(QSize(50,60));
|
|
|
|
si.setPixmap(pm);
|
|
|
|
ScoreItem* item = new ScoreItem(si);
|
|
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
2014-11-19 15:25:03 +01:00
|
|
|
|
|
|
|
QString s(si.completeBaseName());
|
|
|
|
if (!s.isEmpty() && s[0].isNumber() && _stripNumbers)
|
|
|
|
s = s.mid(3);
|
2014-11-20 12:49:51 +01:00
|
|
|
s = s.replace('_', ' ');
|
2014-11-19 15:25:03 +01:00
|
|
|
item->setText(s);
|
2014-11-19 14:26:20 +01:00
|
|
|
item->setIcon(QIcon(si.pixmap()));
|
|
|
|
return item;
|
2014-11-12 15:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setScores
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-11-13 10:22:05 +01:00
|
|
|
void ScoreBrowser::setScores(QFileInfoList s)
|
2014-11-12 15:01:08 +01:00
|
|
|
{
|
2014-11-19 14:26:20 +01:00
|
|
|
qDeleteAll(scoreLists);
|
|
|
|
scoreLists.clear();
|
|
|
|
|
|
|
|
QLayout* l = scoreList->layout();
|
|
|
|
while (l->count())
|
|
|
|
l->removeItem(l->itemAt(0));
|
|
|
|
|
|
|
|
QListWidget* sl = 0;
|
|
|
|
|
|
|
|
QStringList filter = { "*.mscz" };
|
2014-11-19 15:25:03 +01:00
|
|
|
for (const QFileInfo& fi : s) {
|
|
|
|
if (fi.isFile()) {
|
|
|
|
QString s = fi.filePath();
|
|
|
|
if (s.endsWith(".mscz") || s.endsWith(".mscx")) {
|
|
|
|
if (!sl)
|
|
|
|
sl = createScoreList();
|
|
|
|
sl->addItem(genScoreItem(fi));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 15:01:08 +01:00
|
|
|
for (const QFileInfo& fi : s) {
|
2014-11-19 14:26:20 +01:00
|
|
|
if (fi.isDir()) {
|
2014-11-20 12:49:51 +01:00
|
|
|
QString s(fi.fileName());
|
|
|
|
if (!s.isEmpty() && s[0].isNumber() && _stripNumbers)
|
|
|
|
s = s.mid(3);
|
|
|
|
s = s.replace('_', ' ');
|
|
|
|
QLabel* l = new QLabel(s);
|
2014-11-19 14:26:20 +01:00
|
|
|
static_cast<QVBoxLayout*>(scoreList->layout())->addWidget(l);
|
|
|
|
QDir dir(fi.filePath());
|
|
|
|
sl = createScoreList();
|
2014-11-19 15:25:03 +01:00
|
|
|
for (const QFileInfo& fi : dir.entryInfoList(filter, QDir::Files, QDir::Name))
|
2014-11-19 14:26:20 +01:00
|
|
|
sl->addItem(genScoreItem(fi));
|
|
|
|
sl = 0;
|
|
|
|
}
|
2014-11-12 15:01:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 10:03:51 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// selectFirst
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreBrowser::selectFirst()
|
|
|
|
{
|
|
|
|
if (scoreLists.isEmpty())
|
|
|
|
return;
|
|
|
|
ScoreListWidget* w = scoreLists.front();
|
|
|
|
if (w->count() == 0)
|
|
|
|
return;
|
|
|
|
w->setCurrentItem(w->item(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// selectFirst
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreBrowser::selectLast()
|
|
|
|
{
|
|
|
|
if (scoreLists.isEmpty())
|
|
|
|
return;
|
|
|
|
ScoreListWidget* w = scoreLists.front();
|
|
|
|
if (w->count() == 0)
|
|
|
|
return;
|
|
|
|
w->setCurrentItem(w->item(w->count()-1));
|
|
|
|
}
|
|
|
|
|
2014-11-12 15:01:08 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// scoreChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreBrowser::scoreChanged(QListWidgetItem* current, QListWidgetItem*)
|
|
|
|
{
|
|
|
|
if (!current)
|
|
|
|
return;
|
|
|
|
ScoreItem* item = static_cast<ScoreItem*>(current);
|
2014-11-19 14:26:20 +01:00
|
|
|
preview->setScore(item->info());
|
|
|
|
emit scoreSelected(item->info().filePath());
|
2014-11-12 15:01:08 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 16:36:40 +01:00
|
|
|
//---------------------------------------------------------
|
2014-11-19 14:26:20 +01:00
|
|
|
// setScoreActivated
|
2014-11-12 16:36:40 +01:00
|
|
|
//---------------------------------------------------------
|
2014-11-12 15:01:08 +01:00
|
|
|
|
2014-11-19 14:26:20 +01:00
|
|
|
void ScoreBrowser::setScoreActivated(QListWidgetItem* val)
|
2014-11-12 15:01:08 +01:00
|
|
|
{
|
2014-11-12 16:36:40 +01:00
|
|
|
ScoreItem* item = static_cast<ScoreItem*>(val);
|
2014-11-19 14:26:20 +01:00
|
|
|
emit scoreActivated(item->info().filePath());
|
2014-11-12 15:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|