Make the "stop after this track" box look nicer

This commit is contained in:
David Sansome 2010-07-11 18:37:42 +00:00
parent e625deed33
commit cbc6169ea8
30 changed files with 159 additions and 57 deletions

View File

@ -30,6 +30,14 @@
#include <QScrollBar>
#include <QLinearGradient>
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"));
}
}
}

View File

@ -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 {

View File

@ -25,6 +25,9 @@
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>

View File

@ -1693,6 +1693,9 @@ msgstr "الخيارات"
msgid "remove %n songs"
msgstr "أزِل %n أغاني\\أغنية"
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -1719,6 +1719,9 @@ msgstr "επιλογές"
msgid "remove %n songs"
msgstr "αφαίρεση %n τραγουδιών"
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "κομμάτι %1"

View File

@ -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"

View File

@ -1695,6 +1695,9 @@ msgstr "options"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "track %1"

View File

@ -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"

View File

@ -1695,6 +1695,9 @@ msgstr ""
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""

View File

@ -1705,6 +1705,9 @@ msgstr "options"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "piste %1"

View File

@ -1695,6 +1695,9 @@ msgstr "Opzóns"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "faixa %1"

View File

@ -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"

View File

@ -1695,6 +1695,9 @@ msgstr "опциялар"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""

View File

@ -1697,6 +1697,9 @@ msgstr ""
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "spor %1"

View File

@ -1693,6 +1693,9 @@ msgstr "opcions"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "pista %1"

View File

@ -1695,6 +1695,9 @@ msgstr "opcje"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "utwór %1"

View File

@ -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"

View File

@ -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"

View File

@ -1694,6 +1694,9 @@ msgstr "opțiuni"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "pistă %1"

View File

@ -1703,6 +1703,9 @@ msgstr "настройки"
msgid "remove %n songs"
msgstr "удалить %n композиций"
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "композиция %1"

View File

@ -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"

View File

@ -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"

View File

@ -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 ""

View File

@ -1684,6 +1684,9 @@ msgstr ""
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""

View File

@ -1712,6 +1712,9 @@ msgstr "параметри"
msgid "remove %n songs"
msgstr "вилучити %n композицій"
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr "доріжка %1"

View File

@ -1693,6 +1693,9 @@ msgstr "选项"
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""

View File

@ -1693,6 +1693,9 @@ msgstr ""
msgid "remove %n songs"
msgstr ""
msgid "stop"
msgstr ""
#, qt-format
msgid "track %1"
msgstr ""