#include "cseasondelegate.h" #include "cserie.h" #include "cseason.h" #include "cepisode.h" #include #include #include #include #include #include #define FIELD_WIDTH 3 #define FIELD_STEP 4 #define FIELD_HEIGHT 15 #define HEIGHT 18 #define STATE_INIT Qt::lightGray #define STATE_PROGRESS Qt::blue #define STATE_DONE Qt::green #define STATE_UNKNOWN Qt::black void cSeasonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if(index.column() > 3) { cSeason* lpSeason = nullptr; if(index.data(Qt::UserRole).canConvert()) lpSeason = qvariant_cast(index.data(Qt::UserRole)); if(option.state & QStyle::State_Selected) painter->fillRect(option.rect, QBrush(QColor(51, 153, 255))); if(lpSeason) { QList episodeList = lpSeason->episodeList(); painter->save(); painter->setRenderHint(QPainter::Antialiasing, false); painter->setBrush(option.palette.foreground()); painter->translate(option.rect.x(), option.rect.y()); for(int z = 0;z < episodeList.count();z++) { painter->setPen(Qt::NoPen); cEpisode* lpEpisode = episodeList.at(z); if(lpEpisode) { switch(lpEpisode->state()) { case cEpisode::StateInit: painter->setBrush(STATE_INIT); break; case cEpisode::StateProgress: painter->setBrush(STATE_PROGRESS); break; case cEpisode::StateDone: painter->setBrush(STATE_DONE); break; default: break; } painter->drawRect(z*FIELD_STEP, 0, FIELD_STEP, FIELD_HEIGHT); painter->setPen(Qt::black); painter->drawLine(z*FIELD_STEP+FIELD_WIDTH, 0, z*FIELD_STEP+FIELD_WIDTH, FIELD_HEIGHT); } } painter->setBrush(Qt::black); painter->translate(1.0, 0.0); painter->restore(); } } else { QStyledItemDelegate::paint(painter, option, index); } } QSize cSeasonDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { if(index.column() > 3) { qint32 iTotal = -1; qint32 z; cSeason* lpSeason = nullptr; if(index.data(Qt::UserRole).canConvert()) lpSeason = qvariant_cast(index.data(Qt::UserRole)); if(lpSeason) { QList episodeList = lpSeason->episodeList(); for(z = 0;z < episodeList.count();z++) { cEpisode* lpEpisode = episodeList.at(z); if(lpEpisode) { if(lpEpisode->episodeNumber() > iTotal) iTotal = lpEpisode->episodeNumber(); } } if(iTotal > 0 && lpSeason->seasonNumber() != 0) return(QSize((iTotal+1)*FIELD_STEP, HEIGHT)); else return(QSize(FIELD_STEP*40, HEIGHT)); } return(QSize(FIELD_STEP, HEIGHT)); } return QSize(QStyledItemDelegate::sizeHint(option, index).width(), HEIGHT); }