diff --git a/src/playlist/playlistdelegates.cpp b/src/playlist/playlistdelegates.cpp index 4ef1e7278..7dd7b9b55 100644 --- a/src/playlist/playlistdelegates.cpp +++ b/src/playlist/playlistdelegates.cpp @@ -30,6 +30,14 @@ #include #include +const int QueuedItemDelegate::kQueueBoxBorder = 1; +const int QueuedItemDelegate::kQueueBoxCornerRadius = 3; +const int QueuedItemDelegate::kQueueBoxLength = 30; +const QRgb QueuedItemDelegate::kQueueBoxGradientColor1 = qRgb(102, 150, 227); +const QRgb QueuedItemDelegate::kQueueBoxGradientColor2 = qRgb(77, 121, 200); +const int QueuedItemDelegate::kQueueOpacitySteps = 10; +const float QueuedItemDelegate::kQueueOpacityLowerBound = 0.4; + const int PlaylistDelegateBase::kMinHeight = 19; QueuedItemDelegate::QueuedItemDelegate(QObject *parent) @@ -44,54 +52,68 @@ void QueuedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op index.column() == Queue::Column_CombinedArtistTitle) { const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt(); if (queue_pos != -1) { - QFont smaller = option.font; - smaller.setPointSize(smaller.pointSize() - 2); - smaller.setBold(true); - - const int kQueueBoxBorder = 1; - const int kQueueBoxCornerRadius = 3; - const int kQueueBoxLength = QFontMetrics(smaller).width('7') * 4; - const QRgb kQueueBoxGradientColor1 = qRgb(102, 150, 227); - const QRgb kQueueBoxGradientColor2 = qRgb(77, 121, 200); - const int kQueueOpacitySteps = 10; - const float kQueueOpacityLowerBound = 0.4; - - QRect rect(option.rect); - rect.setLeft(rect.right() - kQueueBoxLength - kQueueBoxBorder); - rect.setWidth(kQueueBoxLength); - rect.setTop(rect.top() + kQueueBoxBorder); - rect.setBottom(rect.bottom() - kQueueBoxBorder - 1); - - QRect text_rect(rect); - text_rect.setBottom(text_rect.bottom() + 1); - - QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); - gradient.setColorAt(0.0, kQueueBoxGradientColor1); - gradient.setColorAt(1.0, kQueueBoxGradientColor2); - - // Turn on antialisaing - painter->setRenderHint(QPainter::Antialiasing); - float opacity = kQueueOpacitySteps - qMin(kQueueOpacitySteps, queue_pos); opacity /= kQueueOpacitySteps; opacity *= 1.0 - kQueueOpacityLowerBound; opacity += kQueueOpacityLowerBound; painter->setOpacity(opacity); - // Draw the box - painter->setPen(QPen(Qt::white, 1)); - painter->setBrush(gradient); - painter->drawRoundedRect(rect, kQueueBoxCornerRadius, kQueueBoxCornerRadius); - - // Draw the text - painter->setFont(smaller); - painter->drawText(rect, Qt::AlignCenter, QString::number(queue_pos+1)); + DrawBox(painter, option.rect, option.font, QString::number(queue_pos+1), + kQueueBoxLength); painter->setOpacity(1.0); } } } +void QueuedItemDelegate::DrawBox( + QPainter* painter, const QRect& line_rect, const QFont& font, + const QString& text, int width) const { + QFont smaller = font; + smaller.setPointSize(smaller.pointSize() - 2); + smaller.setBold(true); + + if (width == -1) + width = QFontMetrics(font).width(text + " "); + + QRect rect(line_rect); + rect.setLeft(rect.right() - width - kQueueBoxBorder); + rect.setWidth(width); + rect.setTop(rect.top() + kQueueBoxBorder); + rect.setBottom(rect.bottom() - kQueueBoxBorder - 1); + + QRect text_rect(rect); + text_rect.setBottom(text_rect.bottom() + 1); + + QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); + gradient.setColorAt(0.0, kQueueBoxGradientColor1); + gradient.setColorAt(1.0, kQueueBoxGradientColor2); + + // Turn on antialiasing + painter->setRenderHint(QPainter::Antialiasing); + + // Draw the box + painter->setPen(QPen(Qt::white, 1)); + painter->setBrush(gradient); + painter->drawRoundedRect(rect, kQueueBoxCornerRadius, kQueueBoxCornerRadius); + + // Draw the text + painter->setFont(smaller); + painter->drawText(rect, Qt::AlignCenter, text); +} + +int QueuedItemDelegate::queue_indicator_size(const QModelIndex& index) const { + if (index.column() == Playlist::Column_Title || + index.column() == Queue::Column_CombinedArtistTitle) { + const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt(); + if (queue_pos != -1) { + return kQueueBoxLength + kQueueBoxBorder*2; + } + } + return 0; +} + + PlaylistDelegateBase::PlaylistDelegateBase(QTreeView* view, const QString& suffix) : QueuedItemDelegate(view), view_(view), @@ -138,30 +160,13 @@ QSize PlaylistDelegateBase::sizeHint(const QStyleOptionViewItem &option, const Q void PlaylistDelegateBase::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QueuedItemDelegate::paint(painter, Adjusted(option, index), index); - QPoint top_left(-view_->horizontalScrollBar()->value(), - -view_->verticalScrollBar()->value()); - // Stop after indicator - if (view_->header()->logicalIndexAt(top_left) == index.column()) { + if (index.column() == Playlist::Column_Title) { if (index.data(Playlist::Role_StopAfter).toBool()) { - QColor color(Qt::white); - if (!index.data(Playlist::Role_IsCurrent).toBool() && - !(option.state & QStyle::State_Selected)) { - color = option.palette.color(QPalette::Highlight); - } + QRect rect(option.rect); + rect.setRight(rect.right() - queue_indicator_size(index)); - const int kStopSize = 10; - const int kStopBorder = 2; - - QRect stop_rect(option.rect); - stop_rect.setLeft(stop_rect.right() - kStopSize - kStopBorder); - stop_rect.setWidth(kStopSize); - stop_rect.moveTop(stop_rect.top() + (stop_rect.height() - kStopSize) / 2); - stop_rect.setHeight(kStopSize); - - painter->setOpacity(0.65); - painter->fillRect(stop_rect, color); - painter->setOpacity(1.0); + DrawBox(painter, rect, option.font, tr("stop")); } } } diff --git a/src/playlist/playlistdelegates.h b/src/playlist/playlistdelegates.h index be467a864..6c0b9148b 100644 --- a/src/playlist/playlistdelegates.h +++ b/src/playlist/playlistdelegates.h @@ -29,6 +29,19 @@ class QueuedItemDelegate : public QStyledItemDelegate { public: QueuedItemDelegate(QObject* parent); void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + void DrawBox(QPainter* painter, const QRect& line_rect, + const QFont& font, const QString& text, int width = -1) const; + + int queue_indicator_size(const QModelIndex& index) const; + +private: + static const int kQueueBoxBorder; + static const int kQueueBoxCornerRadius; + static const int kQueueBoxLength; + static const QRgb kQueueBoxGradientColor1; + static const QRgb kQueueBoxGradientColor2; + static const int kQueueOpacitySteps; + static const float kQueueOpacityLowerBound; }; class PlaylistDelegateBase : public QueuedItemDelegate { diff --git a/src/playlist/queuemanager.ui b/src/playlist/queuemanager.ui index a017bb4bc..7be3c674c 100644 --- a/src/playlist/queuemanager.ui +++ b/src/playlist/queuemanager.ui @@ -25,6 +25,9 @@ true + + true + true diff --git a/src/translations/ar.po b/src/translations/ar.po index b9744a050..6f48327f8 100644 --- a/src/translations/ar.po +++ b/src/translations/ar.po @@ -1693,6 +1693,9 @@ msgstr "الخيارات" msgid "remove %n songs" msgstr "أزِل %n أغاني\\أغنية" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/cs.po b/src/translations/cs.po index a8ec84cfe..d4febdfe9 100644 --- a/src/translations/cs.po +++ b/src/translations/cs.po @@ -1697,6 +1697,9 @@ msgstr "Možnosti" msgid "remove %n songs" msgstr "Odeber %n skladeb" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "stopa %1" diff --git a/src/translations/da.po b/src/translations/da.po index 9582bf160..e9b45ee6d 100644 --- a/src/translations/da.po +++ b/src/translations/da.po @@ -1700,6 +1700,9 @@ msgstr "indstillinger" msgid "remove %n songs" msgstr "fjern %n sange" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "spor %1" diff --git a/src/translations/de.po b/src/translations/de.po index 601cfb1c5..949b800b4 100644 --- a/src/translations/de.po +++ b/src/translations/de.po @@ -1704,6 +1704,9 @@ msgstr "Einstellungen" msgid "remove %n songs" msgstr "%n Stücke entfernen" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "Stück %1" diff --git a/src/translations/el.po b/src/translations/el.po index 9cc98914f..48f3b57b8 100644 --- a/src/translations/el.po +++ b/src/translations/el.po @@ -1719,6 +1719,9 @@ msgstr "επιλογές" msgid "remove %n songs" msgstr "αφαίρεση %n τραγουδιών" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "κομμάτι %1" diff --git a/src/translations/en_CA.po b/src/translations/en_CA.po index 99be607c1..b9ed55a1c 100644 --- a/src/translations/en_CA.po +++ b/src/translations/en_CA.po @@ -1698,6 +1698,9 @@ msgstr "options" msgid "remove %n songs" msgstr "remove %n songs" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "track %1" diff --git a/src/translations/en_GB.po b/src/translations/en_GB.po index 926591783..c67e5d64b 100644 --- a/src/translations/en_GB.po +++ b/src/translations/en_GB.po @@ -1695,6 +1695,9 @@ msgstr "options" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "track %1" diff --git a/src/translations/es.po b/src/translations/es.po index ab05b384d..95d7d45f4 100644 --- a/src/translations/es.po +++ b/src/translations/es.po @@ -1709,6 +1709,9 @@ msgstr "opciones" msgid "remove %n songs" msgstr "remover %n pistas" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "Pista %1" diff --git a/src/translations/fi.po b/src/translations/fi.po index e61d327c3..4ce695d05 100644 --- a/src/translations/fi.po +++ b/src/translations/fi.po @@ -1695,6 +1695,9 @@ msgstr "" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/fr.po b/src/translations/fr.po index c3c318de2..2e4c48018 100644 --- a/src/translations/fr.po +++ b/src/translations/fr.po @@ -1705,6 +1705,9 @@ msgstr "options" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "piste %1" diff --git a/src/translations/gl.po b/src/translations/gl.po index eccb9ce2a..299367084 100644 --- a/src/translations/gl.po +++ b/src/translations/gl.po @@ -1695,6 +1695,9 @@ msgstr "Opzóns" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "faixa %1" diff --git a/src/translations/it.po b/src/translations/it.po index ceaa5f080..356da9ddc 100644 --- a/src/translations/it.po +++ b/src/translations/it.po @@ -1711,6 +1711,9 @@ msgstr "opzioni" msgid "remove %n songs" msgstr "rimuovi %n brani" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "traccia %1" diff --git a/src/translations/kk.po b/src/translations/kk.po index 00c931a40..9f14192f2 100644 --- a/src/translations/kk.po +++ b/src/translations/kk.po @@ -1695,6 +1695,9 @@ msgstr "опциялар" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/nb.po b/src/translations/nb.po index 9f82eee37..ca5657d01 100644 --- a/src/translations/nb.po +++ b/src/translations/nb.po @@ -1697,6 +1697,9 @@ msgstr "" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "spor %1" diff --git a/src/translations/oc.po b/src/translations/oc.po index bba7df0d3..3ef83f680 100644 --- a/src/translations/oc.po +++ b/src/translations/oc.po @@ -1693,6 +1693,9 @@ msgstr "opcions" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "pista %1" diff --git a/src/translations/pl.po b/src/translations/pl.po index 6ffb2a39d..937f5aade 100644 --- a/src/translations/pl.po +++ b/src/translations/pl.po @@ -1695,6 +1695,9 @@ msgstr "opcje" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "utwór %1" diff --git a/src/translations/pt.po b/src/translations/pt.po index 257aeac1b..0014e3ab4 100644 --- a/src/translations/pt.po +++ b/src/translations/pt.po @@ -1713,6 +1713,9 @@ msgstr "opções" msgid "remove %n songs" msgstr "remover %n canções" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "faixa %1" diff --git a/src/translations/pt_BR.po b/src/translations/pt_BR.po index a98f86d2b..b460489de 100644 --- a/src/translations/pt_BR.po +++ b/src/translations/pt_BR.po @@ -1713,6 +1713,9 @@ msgstr "opções" msgid "remove %n songs" msgstr "Remover %n músicas" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "faixa %1" diff --git a/src/translations/ro.po b/src/translations/ro.po index 5551573d5..b95021ada 100644 --- a/src/translations/ro.po +++ b/src/translations/ro.po @@ -1694,6 +1694,9 @@ msgstr "opțiuni" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "pistă %1" diff --git a/src/translations/ru.po b/src/translations/ru.po index a9a1e24e9..3fd747aa7 100644 --- a/src/translations/ru.po +++ b/src/translations/ru.po @@ -1703,6 +1703,9 @@ msgstr "настройки" msgid "remove %n songs" msgstr "удалить %n композиций" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "композиция %1" diff --git a/src/translations/sk.po b/src/translations/sk.po index c033962bd..3631e027d 100644 --- a/src/translations/sk.po +++ b/src/translations/sk.po @@ -1711,6 +1711,9 @@ msgstr "možnosti" msgid "remove %n songs" msgstr "odstrániť %n piesní" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "skladba %1" diff --git a/src/translations/sv.po b/src/translations/sv.po index 5fc3ee408..9483585b0 100644 --- a/src/translations/sv.po +++ b/src/translations/sv.po @@ -1701,6 +1701,9 @@ msgstr "alternativ" msgid "remove %n songs" msgstr "Ta bort %n songer" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "spår %1" diff --git a/src/translations/tr.po b/src/translations/tr.po index 8cdcf06ae..5b425bc66 100644 --- a/src/translations/tr.po +++ b/src/translations/tr.po @@ -1695,6 +1695,9 @@ msgstr "seçenekler" msgid "remove %n songs" msgstr "%n şakıyı çıkart" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/translations.pot b/src/translations/translations.pot index 277edb97f..28fe8caf8 100644 --- a/src/translations/translations.pot +++ b/src/translations/translations.pot @@ -1684,6 +1684,9 @@ msgstr "" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/uk.po b/src/translations/uk.po index c14b988f1..3eb201ee3 100644 --- a/src/translations/uk.po +++ b/src/translations/uk.po @@ -1712,6 +1712,9 @@ msgstr "параметри" msgid "remove %n songs" msgstr "вилучити %n композицій" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "доріжка %1" diff --git a/src/translations/zh_CN.po b/src/translations/zh_CN.po index 117ffd85e..42e106178 100644 --- a/src/translations/zh_CN.po +++ b/src/translations/zh_CN.po @@ -1693,6 +1693,9 @@ msgstr "选项" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr "" diff --git a/src/translations/zh_TW.po b/src/translations/zh_TW.po index 3e183f592..9f9d2de1a 100644 --- a/src/translations/zh_TW.po +++ b/src/translations/zh_TW.po @@ -1693,6 +1693,9 @@ msgstr "" msgid "remove %n songs" msgstr "" +msgid "stop" +msgstr "" + #, qt-format msgid "track %1" msgstr ""