Use the default text color when the row is highlighted

This commit is contained in:
Vladimir Golovnev (Glassez) 2025-05-05 16:43:38 +03:00
commit a360c6b10c
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
2 changed files with 45 additions and 27 deletions

View file

@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -33,7 +34,7 @@
#include "transferlistmodel.h"
TransferListDelegate::TransferListDelegate(QObject *parent)
: QStyledItemDelegate {parent}
: QStyledItemDelegate(parent)
{
}
@ -66,6 +67,25 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
switch (index.column())
{
case TransferListModel::TR_PROGRESS:
paintProgressBarItem(painter, option, index);
break;
default:
QStyledItemDelegate::paint(painter, option, index);
break;
}
}
void TransferListDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
{
QStyledItemDelegate::initStyleOption(option, index);
// Force QPalette::HighlightedText to be used for drawing highlighted text
if (option->state.testAnyFlags(QStyle::State_Selected | QStyle::State_MouseOver))
option->palette.setColor(QPalette::All, QPalette::Text, option->palette.color(QPalette::Active, QPalette::HighlightedText));
}
void TransferListDelegate::paintProgressBarItem(QPainter *painter, QStyleOptionViewItem option, const QModelIndex &index) const
{
using namespace BitTorrent;
@ -86,15 +106,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
const QModelIndex statusIndex = index.siblingAtColumn(TransferListModel::TR_STATUS);
const auto torrentState = statusIndex.data(TransferListModel::UnderlyingDataRole).value<TorrentState>();
option.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState));
QStyleOptionViewItem customOption {option};
customOption.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState));
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress);
}
break;
default:
QStyledItemDelegate::paint(painter, option, index);
break;
}
m_progressBarPainter.paint(painter, option, index.data().toString(), progress);
}

View file

@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -44,7 +45,12 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
protected:
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
private:
void paintProgressBarItem(QPainter *painter, QStyleOptionViewItem option, const QModelIndex &index) const;
ProgressBarPainter m_progressBarPainter;
mutable int m_nameColHeight = -1;
};