| 201 | } |
| 202 | |
| 203 | void TreeItemDelegate::drawElement(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, |
| 204 | const QPixmap &leftIcon, bool expandable, bool withIndent) const |
| 205 | { |
| 206 | bool isMute = index.data(Qt::UserRole + 3).toBool(); |
| 207 | bool isAlwaysPlayed = index.data(Qt::UserRole + 4).toBool(); |
| 208 | |
| 209 | // Background |
| 210 | bool highlighted = option.state & QStyle::State_Selected; |
| 211 | if (highlighted) |
| 212 | painter->fillRect(option.rect, s_colors->_highlightColorBackground); |
| 213 | |
| 214 | // Indent? |
| 215 | QRect rect = option.rect; |
| 216 | if (withIndent) |
| 217 | rect.adjust(16, 0, 0, 0); |
| 218 | |
| 219 | // Left icon |
| 220 | painter->drawPixmap(rect.left() + MARGIN, rect.top() + (rect.height() - leftIcon.height()) / 2, leftIcon); |
| 221 | |
| 222 | // Right arrow |
| 223 | int rightAreaWidth = 0; |
| 224 | if (expandable) |
| 225 | { |
| 226 | const TreeView* view = qobject_cast<const TreeView*>(option.widget); |
| 227 | QPixmap pix = s_icons->getPixmap(view->isExpanded(index) ? "arrow_down" : "arrow_up", |
| 228 | highlighted ? ThemeManager::HIGHLIGHTED_TEXT : ThemeManager::LIST_TEXT, false); |
| 229 | int x = rect.right() - pix.width() - MARGIN; |
| 230 | int y = rect.top() + (rect.height() - pix.height()) / 2; |
| 231 | painter->drawPixmap(x - MARGIN, y, pix); |
| 232 | |
| 233 | rightAreaWidth = pix.width() + 2 * MARGIN; |
| 234 | } |
| 235 | |
| 236 | // Text |
| 237 | QRect rectText = rect; |
| 238 | rectText.adjust(MARGIN + 20, 0, -MARGIN - rightAreaWidth, 0); |
| 239 | QString text = index.data().toString() + |
| 240 | (isMute ? " (" + tr("mute") + ")" : "") + |
| 241 | (isAlwaysPlayed ? " (" + tr("playing") + ")" : "") ; |
| 242 | QFontMetrics metrics(option.font); |
| 243 | text = metrics.elidedText(text, Qt::ElideMiddle, rectText.width() - 1); |
| 244 | |
| 245 | // Draw |
| 246 | rectText.adjust(0, (rectText.height() - metrics.height()) / 2, 0, 0); |
| 247 | painter->setPen(highlighted ? s_colors->_highlightColorText : s_colors->_textColor); |
| 248 | QFont font = option.font; |
| 249 | font.setItalic(isMute); |
| 250 | font.setBold(isAlwaysPlayed); |
| 251 | painter->setFont(font); |
| 252 | painter->drawText(rectText, text); |
| 253 | } |
| 254 | |
| 255 | bool TreeItemDelegate::helpEvent(QHelpEvent* e, QAbstractItemView* view, const QStyleOptionViewItem& option, const QModelIndex& index) |
| 256 | { |