--- a/GUI/playlist/delegate/PlaylistItemDelegate.cpp
+++ b/GUI/playlist/delegate/PlaylistItemDelegate.cpp
@@ -1,5 +1,3 @@
-/* PlaylistItemDelegate.cpp */
-
/* Copyright (C) 2012 Lucio Carreras
*
* This file is part of sayonara player
@@ -18,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
-
#include <QObject>
#include <QLabel>
#include <QListView>
@@ -28,139 +24,126 @@
#include "GUI/playlist/entry/GUI_PlaylistEntryBig.h"
#include "GUI/playlist/entry/GUI_PlaylistEntrySmall.h"
-static QString get_fg_color(int val_bg){
-
- if(val_bg > 160)
- return QString(" color: #202020; ");
-
- else
- return QString(" color: #D8D8D8 ");
+static QString get_fg_color(int val_bg)
+{
+ if (val_bg > 160) {
+ return QString(" color: #202020; ");
+ } else {
+ return QString(" color: #D8D8D8; ");
+ }
}
-PlaylistItemDelegate::PlaylistItemDelegate(QListView* parent, bool compact){
+PlaylistItemDelegate::PlaylistItemDelegate(QListView* parent, bool compact)
+{
+ // There is no way to apply the style sheet and compute the row
+ // height here, the actual font metrics are only known during the
+ // paint event (apparently...)
+ if (compact) {
+ _row_height = 20;
+ _pl_entry = new GUI_PlaylistEntrySmall();
+ } else {
+ _row_height = 31;
+ _pl_entry = new GUI_PlaylistEntryBig();
+ }
- if(compact){
- _row_height = 20;
- _pl_entry = new GUI_PlaylistEntrySmall();
- }
- else{
- _row_height = 31;
- _pl_entry = new GUI_PlaylistEntryBig();
- }
-
- _parent = parent;
- _rendered_items = 0;
+ _parent = parent;
+ _rendered_items = 0;
}
-PlaylistItemDelegate::~PlaylistItemDelegate(){
- delete _pl_entry;
- _row_height = 0;
+PlaylistItemDelegate::~PlaylistItemDelegate()
+{
+ delete _pl_entry;
+ _row_height = 0;
}
-void PlaylistItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const {
+void PlaylistItemDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
+{
+ if (!index.isValid()) {
+ return;
+ }
- if(!index.isValid()) return;
+ QRect rect(option.rect);
+ _pl_entry->setMaximumSize(_max_width, _row_height);
+ _pl_entry->setMinimumSize(_max_width, _row_height);
+ _pl_entry->resize(_max_width, _row_height);
- QRect rect(option.rect);
- _pl_entry->setMaximumSize(_max_width, _row_height);
- _pl_entry->setMinimumSize(_max_width, _row_height);
- _pl_entry->resize(_max_width, _row_height);
+ QVariant mdVariant = index.model()->data(index, Qt::WhatsThisRole);
+ MetaData md;
+ if (!MetaData::fromVariant(mdVariant, md)) {
+ return;
+ }
- QVariant mdVariant = index.model()->data(index, Qt::WhatsThisRole);
- MetaData md;
- if( !MetaData::fromVariant(mdVariant, md) ) return;
+ _pl_entry->setContent(md, index.row() + 1);
- _pl_entry->setContent(md, index.row() +1 );
+ QString style;
+ QPalette palette = _parent->palette();
- QString style;
- QPalette palette = _parent->palette();
+ QColor col_background = palette.color(QPalette::Active,
+ QPalette::Background);
+ QColor col_highlight = palette.color(QPalette::Active, QPalette::Highlight);
+ QColor col_highlight_lighter = col_highlight.darker(140);
- QColor col_background = palette.color(QPalette::Active, QPalette::Background);
- QColor col_highlight = palette.color(QPalette::Active, QPalette::Highlight);
- QColor col_highlight_lighter = col_highlight.darker(140);
+ int highlight_val = col_highlight.lightness();
+ int playing_val = col_highlight_lighter.lightness();
+ int background_val = col_background.lightness();
- int highlight_val = col_highlight.lightness();
- int playing_val = col_highlight_lighter.lightness();
- int background_val = col_background.lightness();
+ style = "* {";
+ if (md.pl_playing) {
+ style += QString("background-color: ") +
+ col_highlight_lighter.name() + "; " +
+ get_fg_color(playing_val);
+ _pl_entry->setProperty("play_state", "playing");
+ } else if (md.is_disabled) {
+ style += QString("color: #A0A0A0; background-color: transparent;");
+ _pl_entry->setProperty("play_state", "disabled");
+ } else if (!md.pl_selected) {
+ style += QString("background-color: transparent; ") +
+ get_fg_color(background_val);
+ _pl_entry->setProperty("play_state", "selected");
+ } else {
+ // standard selected
+ style += QString("background-color: ") +
+ col_highlight.name() + ";" +
+ get_fg_color(highlight_val);
+ _pl_entry->setProperty("play_state", "default");
+ }
+ style += "}";
+ int y = rect.topLeft().y() + _pl_entry->height() - 1;
+ _pl_entry->setStyleSheet(_parent->styleSheet().append(style));
+// _pl_entry->setStyleSheet(style);
+ if (md.is_disabled) {
+ _pl_entry->setDisabled(true);
+ }
- if(md.pl_playing){
- style = QString("background-color: ") +
- col_highlight_lighter.name() + "; " +
- get_fg_color(playing_val);
- }
+ painter->save();
+ painter->translate(0, 0);
- else if(md.is_disabled){
- style = QString("color: #A0A0A0; background-color: transparent;");
- }
+ _pl_entry->render(painter, rect.topLeft());
- else if(!md.pl_selected){
- style = QString("background-color: transparent; ") +
- get_fg_color(background_val);
- }
+ if (md.pl_dragged) {
+ painter->drawLine(QLine(0, y, _max_width, y));
+ }
- // standard selected
- else{
- style = QString("background-color: ") +
- col_highlight.name() + ";" +
- get_fg_color(highlight_val);
- }
-
- int y = rect.topLeft().y() + _pl_entry->height() -1;
- _pl_entry->setStyleSheet(style);
- if(md.is_disabled) _pl_entry->setDisabled(true);
-
- painter->save();
- painter->translate(0, 0);
-
- _pl_entry->render(painter, rect.topLeft() );
-
- if(md.pl_dragged) {
- painter->drawLine(QLine(0, y, _max_width, y));
- }
-
- painter->restore();
+ painter->restore();
}
-
-QSize PlaylistItemDelegate::sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const
+QSize PlaylistItemDelegate::sizeHint(const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
{
- Q_UNUSED(option);
- Q_UNUSED(index);
+ Q_UNUSED(option);
+ Q_UNUSED(index);
return QSize(_max_width, _row_height);
}
-
-
-void PlaylistItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{
- Q_UNUSED(editor);
- Q_UNUSED(index);
+void PlaylistItemDelegate::setMaxWidth(int w)
+{
+ _max_width = w;
}
-void PlaylistItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
- Q_UNUSED(editor);
- Q_UNUSED(index);
- Q_UNUSED(model);
+int PlaylistItemDelegate::rowHeight()
+{
+ return _row_height;
}
-
-QWidget* PlaylistItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- Q_UNUSED(parent);
- Q_UNUSED(option);
- Q_UNUSED(index);
-
- return 0;
-}
-
-void PlaylistItemDelegate::setMaxWidth(int w){
- _max_width = w;
-}
-
-int PlaylistItemDelegate::rowHeight(){
- return _row_height;
-}
-
-
-