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
|
|
|
//---------------------------------------------------------
|
|
|
|
// sizeHint
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QSize ScoreListWidget::sizeHint() const
|
|
|
|
{
|
|
|
|
int cols = (width()-SPACE) / (CELLW + SPACE);
|
|
|
|
int n = count();
|
2014-12-16 18:02:41 +01:00
|
|
|
int rows = 1;
|
|
|
|
if (cols > 0)
|
|
|
|
rows = (n+cols-1) / cols;
|
2014-11-19 14:26:20 +01:00
|
|
|
if (rows <= 0)
|
|
|
|
rows = 1;
|
|
|
|
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-12-11 15:11:54 +01:00
|
|
|
ScoreItem(const ScoreInfo& i) : QListWidgetItem(), _info(i) {}
|
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);
|
2014-12-16 18:02:41 +01:00
|
|
|
scoreList->layout()->setMargin(0);
|
2014-11-21 12:52:07 +01:00
|
|
|
connect(preview, SIGNAL(doubleClicked(QString)), SIGNAL(scoreActivated(QString)));
|
2014-12-11 15:11:54 +01:00
|
|
|
if (!_showPreview)
|
|
|
|
preview->setVisible(false);
|
2014-11-19 14:26:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// createScoreList
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-12-11 15:11:54 +01:00
|
|
|
ScoreListWidget* ScoreBrowser::createScoreList()
|
2014-11-19 14:26:20 +01:00
|
|
|
{
|
|
|
|
ScoreListWidget* sl = new ScoreListWidget;
|
|
|
|
sl->setWrapping(true);
|
|
|
|
sl->setViewMode(QListView::IconMode);
|
2015-02-20 18:48:58 +01:00
|
|
|
sl->setIconSize(QSize(sl->cellWidth(), sl->cellHeight() - 30));
|
2015-03-05 19:00:18 +01:00
|
|
|
sl->setSpacing(sl->space());
|
2014-11-19 14:26:20 +01:00
|
|
|
sl->setResizeMode(QListView::Adjust);
|
|
|
|
sl->setFlow(QListView::LeftToRight);
|
|
|
|
sl->setMovement(QListView::Static);
|
|
|
|
sl->setTextElideMode(Qt::ElideRight);
|
2014-11-22 18:02:49 +01:00
|
|
|
sl->setWordWrap(true);
|
2014-11-19 14:26:20 +01:00
|
|
|
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);
|
2014-12-11 15:11:54 +01:00
|
|
|
if (!_showPreview)
|
|
|
|
sl->setSelectionMode(QAbstractItemView::NoSelection);
|
2014-11-19 14:26:20 +01:00
|
|
|
|
2014-12-11 15:11:54 +01:00
|
|
|
connect(sl, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(scoreChanged(QListWidgetItem*)), Qt::QueuedConnection);
|
2014-11-19 14:26:20 +01:00
|
|
|
connect(sl, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(setScoreActivated(QListWidgetItem*)));
|
|
|
|
scoreLists.append(sl);
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// genScoreItem
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-12-11 15:11:54 +01:00
|
|
|
ScoreItem* ScoreBrowser::genScoreItem(const QFileInfo& fi, ScoreListWidget* l)
|
2014-11-19 14:26:20 +01:00
|
|
|
{
|
|
|
|
ScoreInfo si(fi);
|
2015-02-06 18:39:13 +01:00
|
|
|
|
2015-02-20 18:48:58 +01:00
|
|
|
QPixmap pm(l->iconSize() * qApp->devicePixelRatio());
|
2015-02-06 18:39:13 +01:00
|
|
|
if (!QPixmapCache::find(fi.filePath(), &pm)) {
|
2015-02-20 18:48:58 +01:00
|
|
|
//load and scale pixmap
|
|
|
|
QPixmap pixmap = mscore->extractThumbnail(fi.filePath());
|
|
|
|
if (pixmap.isNull())
|
|
|
|
pixmap = icons[int(Icons::file_ICON)]->pixmap(QSize(50,60));
|
|
|
|
pixmap = pixmap.scaled(pm.width() - 2, pm.height() - 2, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
// draw pixmap and add border
|
|
|
|
pm.fill(Qt::transparent);
|
|
|
|
QPainter painter( &pm );
|
2015-02-25 20:38:48 +01:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter::TextAntialiasing);
|
2015-02-20 18:48:58 +01:00
|
|
|
painter.drawPixmap(0, 0, pixmap);
|
2015-03-03 16:56:52 +01:00
|
|
|
painter.setPen(QPen(QColor(0, 0, 0, 128), 1));
|
2015-02-20 18:48:58 +01:00
|
|
|
painter.setBrush(Qt::white);
|
2015-02-25 20:38:48 +01:00
|
|
|
if (fi.baseName() == "00-Blank" || fi.baseName() == "Create_New_Score") {
|
|
|
|
qreal round = 8.0 * qApp->devicePixelRatio();
|
|
|
|
painter.drawRoundedRect(QRectF(0, 0, pm.width() - 1 , pm.height() - 1), round, round);
|
|
|
|
}
|
2015-02-20 18:48:58 +01:00
|
|
|
else
|
|
|
|
painter.drawRect(0, 0, pm.width() - 1, pm.height() - 1);
|
|
|
|
if (fi.baseName() != "00-Blank")
|
|
|
|
painter.drawPixmap(1, 1, pixmap);
|
|
|
|
painter.end();
|
2015-02-06 18:39:13 +01:00
|
|
|
QPixmapCache::insert(fi.filePath(), pm);
|
|
|
|
}
|
2015-02-20 18:48:58 +01:00
|
|
|
|
2014-11-19 14:26:20 +01:00
|
|
|
si.setPixmap(pm);
|
|
|
|
ScoreItem* item = new ScoreItem(si);
|
|
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
2014-11-19 15:25:03 +01:00
|
|
|
|
2015-03-03 16:56:52 +01:00
|
|
|
QFont f = item->font();
|
|
|
|
f.setPointSize(f.pointSize() - 2.0);
|
|
|
|
f.setBold(_boldTitle);
|
|
|
|
if (fi.baseName() == "00-Blank") {
|
2015-02-20 18:48:58 +01:00
|
|
|
item->setText(tr("Choose Instruments"));
|
2015-03-03 16:56:52 +01:00
|
|
|
f.setBold(true);
|
|
|
|
}
|
|
|
|
else if (fi.baseName() == "Create_New_Score") {
|
2015-02-20 18:48:58 +01:00
|
|
|
item->setText(tr("Create New Score"));
|
2015-03-03 16:56:52 +01:00
|
|
|
f.setBold(true);
|
|
|
|
}
|
2015-03-05 11:10:45 +01:00
|
|
|
else if (fi.baseName() == "Getting_Started") {
|
|
|
|
item->setText(tr("Getting Started"));
|
|
|
|
f.setBold(true);
|
|
|
|
}
|
2015-02-20 18:48:58 +01:00
|
|
|
else {
|
|
|
|
QString s(si.completeBaseName());
|
|
|
|
if (!s.isEmpty() && s[0].isNumber() && _stripNumbers)
|
|
|
|
s = s.mid(3);
|
|
|
|
s = s.replace('_', ' ');
|
|
|
|
item->setText(s);
|
|
|
|
}
|
2014-11-22 18:02:49 +01:00
|
|
|
item->setFont(f);
|
|
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
2015-02-20 18:48:58 +01:00
|
|
|
item->setIcon(QIcon(pm));
|
2014-12-11 15:11:54 +01:00
|
|
|
item->setSizeHint(l->cellSize());
|
2014-11-19 14:26:20 +01:00
|
|
|
return item;
|
2014-11-12 15:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setScores
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-04-29 11:34:10 +02: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();
|
|
|
|
|
2015-04-29 11:34:10 +02:00
|
|
|
QVBoxLayout* l = static_cast<QVBoxLayout*>(scoreList->layout());
|
2014-11-19 14:26:20 +01:00
|
|
|
while (l->count())
|
|
|
|
l->removeItem(l->itemAt(0));
|
|
|
|
|
2014-12-11 15:11:54 +01:00
|
|
|
ScoreListWidget* sl = 0;
|
2014-11-19 14:26:20 +01:00
|
|
|
|
|
|
|
QStringList filter = { "*.mscz" };
|
2015-01-12 02:11:47 +01:00
|
|
|
|
2015-04-29 11:34:10 +02:00
|
|
|
if (_showCustomCategory)
|
|
|
|
std::sort(s.begin(), s.end(), [](QFileInfo a, QFileInfo b)->bool { return a.fileName() < b.fileName(); });
|
|
|
|
|
2015-01-12 02:11:47 +01:00
|
|
|
QSet<QString> entries; //to avoid duplicates
|
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('_', ' ');
|
2014-11-22 18:02:49 +01:00
|
|
|
QLabel* label = new QLabel(s);
|
|
|
|
QFont f = label->font();
|
|
|
|
f.setBold(true);
|
|
|
|
label->setFont(f);
|
|
|
|
static_cast<QVBoxLayout*>(l)->addWidget(label);
|
2014-11-19 14:26:20 +01:00
|
|
|
QDir dir(fi.filePath());
|
|
|
|
sl = createScoreList();
|
2015-04-29 11:34:10 +02:00
|
|
|
l->addWidget(sl);
|
2015-01-12 02:13:06 +01:00
|
|
|
unsigned count = 0; //nbr of entries added
|
2015-01-12 02:11:47 +01:00
|
|
|
for (const QFileInfo& fi : dir.entryInfoList(filter, QDir::Files, QDir::Name)){
|
2015-02-06 18:39:13 +01:00
|
|
|
if (entries.contains(fi.filePath()))
|
2015-01-12 02:13:06 +01:00
|
|
|
continue;
|
2014-12-11 15:11:54 +01:00
|
|
|
sl->addItem(genScoreItem(fi, sl));
|
2015-01-12 02:13:06 +01:00
|
|
|
count++;
|
2015-01-12 02:11:47 +01:00
|
|
|
entries.insert(fi.filePath());
|
|
|
|
}
|
2015-02-06 18:39:13 +01:00
|
|
|
if (count == 0) {
|
2015-01-12 02:13:06 +01:00
|
|
|
delete label;
|
|
|
|
delete sl;
|
|
|
|
}
|
2014-11-19 14:26:20 +01:00
|
|
|
sl = 0;
|
|
|
|
}
|
2015-02-20 22:28:34 +01:00
|
|
|
}
|
|
|
|
for (const QFileInfo& fi : s) {
|
|
|
|
if (fi.isFile()) {
|
|
|
|
QString s = fi.filePath();
|
|
|
|
if (entries.contains(s))
|
|
|
|
continue;
|
|
|
|
if (s.endsWith(".mscz") || s.endsWith(".mscx")) {
|
|
|
|
if (!sl) {
|
|
|
|
if (_showCustomCategory) {
|
|
|
|
QLabel* label = new QLabel(tr("Custom Templates"));
|
|
|
|
QFont f = label->font();
|
|
|
|
f.setBold(true);
|
|
|
|
label->setFont(f);
|
2015-04-29 11:34:10 +02:00
|
|
|
l->insertWidget(2,label);
|
2015-02-20 22:28:34 +01:00
|
|
|
}
|
|
|
|
sl = createScoreList();
|
2015-04-29 11:34:10 +02:00
|
|
|
l->insertWidget(3,sl);
|
2015-02-20 22:28:34 +01:00
|
|
|
}
|
|
|
|
sl->addItem(genScoreItem(fi, sl));
|
|
|
|
entries.insert(s);
|
|
|
|
}
|
|
|
|
}
|
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;
|
2014-12-11 10:54:16 +01:00
|
|
|
ScoreItem* item = static_cast<ScoreItem*>(w->item(0));
|
|
|
|
w->setCurrentItem(item);
|
|
|
|
preview->setScore(item->info());
|
2014-11-21 10:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2014-12-11 10:54:16 +01:00
|
|
|
// selectLast
|
2014-11-21 10:03:51 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreBrowser::selectLast()
|
|
|
|
{
|
|
|
|
if (scoreLists.isEmpty())
|
|
|
|
return;
|
|
|
|
ScoreListWidget* w = scoreLists.front();
|
|
|
|
if (w->count() == 0)
|
|
|
|
return;
|
2014-12-11 10:54:16 +01:00
|
|
|
ScoreItem* item = static_cast<ScoreItem*>(w->item(w->count()-1));
|
|
|
|
w->setCurrentItem(item);
|
|
|
|
preview->setScore(item->info());
|
2014-11-21 10:03:51 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 15:01:08 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// scoreChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-12-11 10:54:16 +01:00
|
|
|
void ScoreBrowser::scoreChanged(QListWidgetItem* current)
|
2014-11-12 15:01:08 +01:00
|
|
|
{
|
|
|
|
if (!current)
|
|
|
|
return;
|
|
|
|
ScoreItem* item = static_cast<ScoreItem*>(current);
|
2014-12-11 15:11:54 +01:00
|
|
|
if (!_showPreview)
|
|
|
|
emit scoreActivated(item->info().filePath());
|
|
|
|
else {
|
|
|
|
preview->setScore(item->info());
|
|
|
|
emit scoreSelected(item->info().filePath());
|
|
|
|
|
|
|
|
for (ScoreListWidget* sl : scoreLists) {
|
|
|
|
if (static_cast<QListWidget*>(sl) != item->listWidget()) {
|
|
|
|
sl->clearSelection();
|
|
|
|
}
|
2014-12-11 10:54:16 +01:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|