Browse Source

- Improved a lot the download list delegate

- Replaced Qt::TextColorRole by Qt::ForegroundRole because it is deprecated
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
b0f3cdad5d
  1. 53
      src/DLListDelegate.h
  2. 2
      src/FinishedListDelegate.h
  3. 6
      src/FinishedTorrents.cpp
  4. 6
      src/GUI.cpp
  5. 2
      src/PreviewListDelegate.h
  6. 4
      src/PropListDelegate.h
  7. 2
      src/SearchListDelegate.h
  8. 2
      src/properties_imp.cpp
  9. 6
      src/searchEngine.cpp
  10. 2
      src/torrentAddition.h

53
src/DLListDelegate.h

@ -50,61 +50,35 @@ class DLListDelegate: public QItemDelegate { @@ -50,61 +50,35 @@ class DLListDelegate: public QItemDelegate {
~DLListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
QStyleOptionViewItem opt = option;
char tmp[MAX_CHAR_TMP];
// set text color
QVariant value = index.data(Qt::TextColorRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
}
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
? QPalette::Normal : QPalette::Disabled;
if (option.state & QStyle::State_Selected){
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
}else{
painter->setPen(opt.palette.color(cg, QPalette::Text));
}
// draw the background color
if(index.column() != PROGRESS){
if (option.showDecorationSelected && (option.state & QStyle::State_Selected)){
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)){
cg = QPalette::Inactive;
}
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
}else{
// painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Base));
// The following should work but is broken (retry with future versions of Qt)
QVariant value = index.data(Qt::BackgroundRole);
if (qVariantCanConvert<QBrush>(value)) {
QPointF oldBO = painter->brushOrigin();
painter->setBrushOrigin(option.rect.topLeft());
painter->fillRect(option.rect, qvariant_cast<QBrush>(value));
painter->setBrushOrigin(oldBO);
}
}
}
QStyleOptionViewItemV3 opt = QItemDelegate::setOptions(index, option);
switch(index.column()){
case SIZE:
painter->drawText(option.rect, Qt::AlignCenter, misc::friendlyUnit(index.data().toLongLong()));
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break;
case ETA:
painter->drawText(option.rect, Qt::AlignCenter, misc::userFriendlyDuration(index.data().toLongLong()));
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::userFriendlyDuration(index.data().toLongLong()));
break;
case UPSPEED:
case DLSPEED:{
QItemDelegate::drawBackground(painter, opt, index);
float speed = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.);
painter->drawText(option.rect, Qt::AlignCenter, QString(tmp)+" "+tr("KiB/s"));
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(tmp)+" "+tr("KiB/s"));
break;
}
case RATIO:{
QItemDelegate::drawBackground(painter, opt, index);
float ratio = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
painter->drawText(option.rect, Qt::AlignCenter, QString(tmp));
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(tmp));
break;
}
case PROGRESS:{
QStyleOptionProgressBarV2 newopt;
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
float progress;
progress = index.data().toDouble()*100.;
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
@ -122,7 +96,7 @@ class DLListDelegate: public QItemDelegate { @@ -122,7 +96,7 @@ class DLListDelegate: public QItemDelegate {
opt.palette.setColor(QPalette::Text, QColor("grey"));
painter->setPen(opt.palette.color(cg, QPalette::Text));
}
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
painter->drawText(opt.rect, Qt::AlignCenter, newopt.text);
break;
}
default:
@ -139,6 +113,11 @@ class DLListDelegate: public QItemDelegate { @@ -139,6 +113,11 @@ class DLListDelegate: public QItemDelegate {
return textRect.size();
}
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const {
// No editor here
return 0;
}
};
#endif

2
src/FinishedListDelegate.h

@ -51,7 +51,7 @@ class FinishedListDelegate: public QItemDelegate { @@ -51,7 +51,7 @@ class FinishedListDelegate: public QItemDelegate {
QStyleOptionViewItem opt = option;
char tmp[MAX_CHAR_TMP];
// set text color
QVariant value = index.data(Qt::TextColorRole);
QVariant value = index.data(Qt::ForegroundRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
}

6
src/FinishedTorrents.cpp

@ -113,7 +113,7 @@ void FinishedTorrents::addFinishedSHA(QString hash){ @@ -113,7 +113,7 @@ void FinishedTorrents::addFinishedSHA(QString hash){
// Set the color of a row in data model
void FinishedTorrents::setRowColor(int row, QString color){
for(int i=0; i<finishedListModel->columnCount(); ++i){
finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::TextColorRole);
finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}
@ -326,7 +326,7 @@ void FinishedTorrents::sortFinishedListFloat(int index, Qt::SortOrder sortOrder) @@ -326,7 +326,7 @@ void FinishedTorrents::sortFinishedListFloat(int index, Qt::SortOrder sortOrder)
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col)));
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows
@ -349,7 +349,7 @@ void FinishedTorrents::sortFinishedListString(int index, Qt::SortOrder sortOrder @@ -349,7 +349,7 @@ void FinishedTorrents::sortFinishedListString(int index, Qt::SortOrder sortOrder
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col)));
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows

6
src/GUI.cpp

@ -708,7 +708,7 @@ void GUI::sortDownloadListFloat(int index, Qt::SortOrder sortOrder){ @@ -708,7 +708,7 @@ void GUI::sortDownloadListFloat(int index, Qt::SortOrder sortOrder){
for(unsigned int col=0; col<nbColumns; ++col){
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col)));
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows
@ -731,7 +731,7 @@ void GUI::sortDownloadListString(int index, Qt::SortOrder sortOrder){ @@ -731,7 +731,7 @@ void GUI::sortDownloadListString(int index, Qt::SortOrder sortOrder){
for(unsigned int col=0; col<nbColumns; ++col){
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col)));
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
DLListModel->setData(DLListModel->index(nbRows_old+row, col), DLListModel->data(DLListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows
@ -1604,7 +1604,7 @@ void GUI::checkConnectionStatus(){ @@ -1604,7 +1604,7 @@ void GUI::checkConnectionStatus(){
void GUI::setRowColor(int row, QString color){
unsigned int nbColumns = DLListModel->columnCount();
for(unsigned int i=0; i<nbColumns; ++i){
DLListModel->setData(DLListModel->index(row, i), QVariant(QColor(color)), Qt::TextColorRole);
DLListModel->setData(DLListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}

2
src/PreviewListDelegate.h

@ -50,7 +50,7 @@ class PreviewListDelegate: public QAbstractItemDelegate { @@ -50,7 +50,7 @@ class PreviewListDelegate: public QAbstractItemDelegate {
char tmp[MAX_CHAR_TMP];
float progress;
// set text color
QVariant value = index.data(Qt::TextColorRole);
QVariant value = index.data(Qt::ForegroundRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
}

4
src/PropListDelegate.h

@ -60,7 +60,7 @@ class PropListDelegate: public QItemDelegate { @@ -60,7 +60,7 @@ class PropListDelegate: public QItemDelegate {
QStyleOptionViewItem opt = option;
char tmp[MAX_CHAR_TMP];
// set text color
QVariant value = index.data(Qt::TextColorRole);
QVariant value = index.data(Qt::ForegroundRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
}
@ -249,7 +249,7 @@ class PropListDelegate: public QItemDelegate { @@ -249,7 +249,7 @@ class PropListDelegate: public QItemDelegate {
}
}
for(int i=0; i<model->columnCount(); ++i){
model->setData(model->index(index.row(), i), QVariant(QColor(color)), Qt::TextColorRole);
model->setData(model->index(index.row(), i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}

2
src/SearchListDelegate.h

@ -47,7 +47,7 @@ class SearchListDelegate: public QAbstractItemDelegate { @@ -47,7 +47,7 @@ class SearchListDelegate: public QAbstractItemDelegate {
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
QStyleOptionViewItem opt = option;
// set text color
QVariant value = index.data(Qt::TextColorRole);
QVariant value = index.data(Qt::ForegroundRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid()){
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
}

2
src/properties_imp.cpp

@ -479,7 +479,7 @@ void properties::updateInfos(){ @@ -479,7 +479,7 @@ void properties::updateInfos(){
// Set the color of a row in data model
void properties::setRowColor(int row, QString color){
for(int i=0; i<PropListModel->columnCount(); ++i){
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::TextColorRole);
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}

6
src/searchEngine.cpp

@ -119,7 +119,7 @@ SearchEngine::~SearchEngine(){ @@ -119,7 +119,7 @@ SearchEngine::~SearchEngine(){
// Set the color of a row in data model
void SearchEngine::setRowColor(int row, QString color){
for(int i=0; i<SearchListModel->columnCount(); ++i){
SearchListModel->setData(SearchListModel->index(row, i), QVariant(QColor(color)), Qt::TextColorRole);
SearchListModel->setData(SearchListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}
@ -158,7 +158,7 @@ void SearchEngine::sortSearchListInt(int index, Qt::SortOrder sortOrder){ @@ -158,7 +158,7 @@ void SearchEngine::sortSearchListInt(int index, Qt::SortOrder sortOrder){
int sourceRow = lines[row].first;
for(int col=0; col<5; ++col){
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col)));
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows
@ -178,7 +178,7 @@ void SearchEngine::sortSearchListString(int index, Qt::SortOrder sortOrder){ @@ -178,7 +178,7 @@ void SearchEngine::sortSearchListString(int index, Qt::SortOrder sortOrder){
int sourceRow = lines[row].first;
for(int col=0; col<5; ++col){
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col)));
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole);
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
}
}
// Remove old rows

2
src/torrentAddition.h

@ -174,7 +174,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -174,7 +174,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
// Set the color of a row in data model
void setRowColor(int row, QString color){
for(int i=0; i<PropListModel->columnCount(); ++i){
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::TextColorRole);
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
}
}

Loading…
Cancel
Save