hi
auf der seite war ich schon ...
ich will es nicht stylen mit stylesheet.
das dialog holt vom interface die daten und somit ich auch das den progress ändert
mit verschiedenen farben..
so etwa solls aussehen...
momentan siehts so aus mit plastique style:
hier ist mein DLDelegate.cpp
Code: Alles auswählen
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBarV2>
#include <QProgressBar>
#include <QApplication>
#include "DLListDelegate.h"
DLListDelegate::DLListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
{
;
}
DLListDelegate::~DLListDelegate(void)
{
;
}
void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
QStyleOptionViewItem opt = option;
QStyleOptionProgressBarV2 newopt;
QRect pixmapRect;
QPixmap pixmap;
qlonglong fileSize;
double progress, dlspeed, multi;
int minutes, hours, days;
qlonglong remaining;
QString temp , status;
qlonglong completed;
//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 {
value = index.data(Qt::BackgroundColorRole);
if(value.isValid() && qvariant_cast<QColor>(value).isValid()) {
painter->fillRect(option.rect, qvariant_cast<QColor>(value));
}
}
}
switch(index.column()) {
case PROGRESS:
progress = index.data().toDouble();
temp.clear();
temp.sprintf("%.2f", progress);
temp += "%";
newopt.rect = opt.rect;
//newopt.text = temp;
newopt.maximum = 100;
newopt.minimum = 0;
newopt.progress = (int)progress;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = false;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt,
painter);
//We prefer to display text manually to control color/font/boldness
if (option.state & QStyle::State_Selected){
opt.palette.setColor(QPalette::Text, QColor("grey"));
painter->setPen(opt.palette.color(cg, QPalette::Text));
}
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break;
}
}
QSize DLListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
QFontMetrics fontMetrics(fnt);
const QString text = index.data(Qt::DisplayRole).toString();
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
return textRect.size();
}
function die auf progress zugreift vom interface im TransfersDialog.cpp:
Code: Alles auswählen
void TransfersDialog::insertTransfers()
{
QString symbol, name, sources, status;
qlonglong fileSize, completed, remaining;
double progress, dlspeed;
//remove all Items
for(int i = DLListModel->rowCount(); i >= 0; i--)
{
delItem(i);
}
//nun aktuelle DownloadListe hinzufügen
rsiface->lockData(); /* Lock Interface */
std::list<FileTransferInfo>::const_iterator it;
const std::list<FileTransferInfo> &transfers = rsiface->getTransferList();
for(it = transfers.begin(); it != transfers.end(); it++)
{
symbol = "";
name = QString::fromStdString(it->fname);
sources = QString::fromStdString(it->source);
dlspeed = it->tfRate * 1024.0;
fileSize = it->size;
completed = it->transfered;
progress = it->transfered * 100.0 / it->size;
remaining = (it->size - it->transfered) / (it->tfRate * 1024.0);
switch(it->downloadStatus)
{
/* XXX HAND CODED! */
case 0: /* FAILED */
status = "Failed";
break;
case 1: /* Downloading */
status = "Downloading";
break;
case 2: /* COMPLETE */
default:
status = "Complete";
break;
}
addItem(symbol, name, fileSize, progress, dlspeed, sources, status, completed, remaining);
}
rsiface->unlockData(); /* UnLock Interface */
}