corrected issue in display of download/upload progress

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2192 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-02-04 21:08:53 +00:00
parent 163ed040be
commit c2fdbe177d
5 changed files with 30 additions and 40 deletions

View File

@ -150,18 +150,15 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
{ {
// create a xProgressBar // create a xProgressBar
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ; FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
xProgressBar progressBar(pinfo.cmap,option.rect, painter); // the 3rd param is the color schema (0 is the default value) xProgressBar progressBar(pinfo,option.rect, painter); // the 3rd param is the color schema (0 is the default value)
if(pinfo.type == FileProgressInfo::DOWNLOAD_LINE) if(pinfo.type == FileProgressInfo::DOWNLOAD_LINE)
{ {
progressBar.setDisplayText(true); // should display % text? progressBar.setDisplayText(true); // should display % text?
progressBar.setValue(pinfo.progress); // set the progress value
progressBar.setColorSchema(0) ; progressBar.setColorSchema(0) ;
} }
else else
{ {
progressBar.setDisplayText(false); // should display % text? progressBar.setDisplayText(false); // should display % text?
progressBar.setValue(pinfo.progress); // set the progress value
progressBar.setColorSchema(1) ; progressBar.setColorSchema(1) ;
} }
progressBar.setVerticalSpan(1); progressBar.setVerticalSpan(1);

View File

@ -824,12 +824,7 @@ void TransfersDialog::insertTransfers()
pinfo.cmap = fcinfo.chunks ; pinfo.cmap = fcinfo.chunks ;
pinfo.type = FileProgressInfo::DOWNLOAD_LINE ; pinfo.type = FileProgressInfo::DOWNLOAD_LINE ;
pinfo.progress = completed*100.0/info.size ; pinfo.progress = completed*100.0/info.size ;
pinfo.nb_chunks = fcinfo.chunks.size() ;
// std::cerr << "Converting fcinfo to compressed chunk map. Chunks=" << fcinfo.chunks.size() << std::endl ;
// std::cerr << "map data = " ;
// for(uint k=0;k<cmap._map.size();++k)
// std::cout << (void*)cmap._map[k] ;
// std::cout << std::endl ;
int addedRow = addItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, priority, completed, remaining); int addedRow = addItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, priority, completed, remaining);
@ -899,6 +894,7 @@ void TransfersDialog::insertTransfers()
pinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ; pinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ;
pinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId] ; pinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId] ;
pinfo.progress = 0.0 ; // we don't display completion for sources. pinfo.progress = 0.0 ; // we don't display completion for sources.
pinfo.nb_chunks = fcinfo.chunks.size() ;
if (!addPeerToItem(addedRow, symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining)) if (!addPeerToItem(addedRow, symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining))
continue; continue;
@ -951,6 +947,7 @@ void TransfersDialog::insertTransfers()
FileProgressInfo pinfo ; FileProgressInfo pinfo ;
pinfo.progress = 0.0 ; pinfo.progress = 0.0 ;
pinfo.nb_chunks = 0 ;
addItem("", name, coreId, fileSize, pinfo, dlspeed, sources, status, priority, completed, remaining); addItem("", name, coreId, fileSize, pinfo, dlspeed, sources, status, priority, completed, remaining);
@ -1036,6 +1033,7 @@ void TransfersDialog::insertTransfers()
++nb_chunks ; ++nb_chunks ;
uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ; uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ;
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:nb_chunks ;
if(filled_chunks > 1) if(filled_chunks > 1)
{ {
@ -1087,6 +1085,7 @@ void TransfersDialog::insertTransfers()
pinfo.progress = progress ; pinfo.progress = progress ;
pinfo.cmap = CompressedChunkMap() ; pinfo.cmap = CompressedChunkMap() ;
pinfo.type = FileProgressInfo::DOWNLOAD_LINE ; pinfo.type = FileProgressInfo::DOWNLOAD_LINE ;
pinfo.nb_chunks = 0 ;
addUploadItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining); addUploadItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining);
ulCount++; ulCount++;

View File

@ -130,7 +130,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ; FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
// create a xProgressBar // create a xProgressBar
xProgressBar progressBar(pinfo.cmap,option.rect,painter,0);// the 3rd param is the color schema (0 is the default value) xProgressBar progressBar(pinfo,option.rect,painter,0);// the 3rd param is the color schema (0 is the default value)
QString ext = QFileInfo(QString::fromStdString(index.sibling(index.row(), UNAME).data().toString().toStdString())).suffix();; QString ext = QFileInfo(QString::fromStdString(index.sibling(index.row(), UNAME).data().toString().toStdString())).suffix();;
if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb") if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb")
@ -139,7 +139,6 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
progressBar.setColorSchema( 8); progressBar.setColorSchema( 8);
progressBar.setDisplayText(true); // should display % text? progressBar.setDisplayText(true); // should display % text?
progressBar.setValue(pinfo.progress); // set the progress value
progressBar.setVerticalSpan(1); progressBar.setVerticalSpan(1);
progressBar.paint(); // paint the progress bar progressBar.paint(); // paint the progress bar
} }

View File

@ -28,14 +28,13 @@
#include <rsiface/rstypes.h> #include <rsiface/rstypes.h>
#include "xprogressbar.h" #include "xprogressbar.h"
xProgressBar::xProgressBar(const CompressedChunkMap& cmap,QRect rect, QPainter *painter, int schemaIndex) xProgressBar::xProgressBar(const FileProgressInfo& pinfo,QRect rect, QPainter *painter, int schemaIndex)
: _cmap(cmap) : _pinfo(pinfo)
{ {
// assign internal data // assign internal data
this->schemaIndex = schemaIndex; this->schemaIndex = schemaIndex;
this->rect = rect; this->rect = rect;
this->painter = painter; this->painter = painter;
this->progressValue = 0.00;
// set the progress bar colors // set the progress bar colors
setColor(); setColor();
// configure span // configure span
@ -194,28 +193,28 @@ void xProgressBar::paint()
painter->setBrush(linearGrad); painter->setBrush(linearGrad);
uint32_t ss = _cmap._map.size()*32 ; uint32_t ss = _pinfo.nb_chunks ;
if(ss > 1) // for small files we use a more progressive display if(ss > 1) // for small files we use a more progressive display
for(int i=0;i<ss;++i) for(int i=0;i<ss;++i)
{
int j=0 ;
while(i+j<ss && _cmap[i+j])
++j ;
if(j>0)
{ {
float o = std::min(1.0f,j/(float)ss*width) ; int j=0 ;
painter->setOpacity(o) ; while(i+j<ss && _pinfo.cmap[i+j])
painter->drawRect(rect.x() + hSpan+(int)rint(i*width/(float)ss), rect.y() + vSpan, (int)ceil(j*width/(float)ss), rect.height() - 1 - vSpan * 2); ++j ;
}
i += j ; if(j>0)
} {
float o = std::min(1.0f,j/(float)ss*width) ;
painter->setOpacity(o) ;
painter->drawRect(rect.x() + hSpan+(int)rint(i*width/(float)ss), rect.y() + vSpan, (int)ceil(j*width/(float)ss), rect.height() - 1 - vSpan * 2);
}
i += j ;
}
else else
{ {
// calculate progress value // calculate progress value
int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(progressValue/100)); int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(_pinfo.progress/100));
int progressWidth = rect.width() - preWidth; int progressWidth = rect.width() - preWidth;
if (progressWidth == rect.width() - hSpan) return; if (progressWidth == rect.width() - hSpan) return;
@ -231,7 +230,7 @@ void xProgressBar::paint()
{ {
QLocale locale; QLocale locale;
painter->setPen(textColor); painter->setPen(textColor);
painter->drawText(rect, Qt::AlignCenter, locale.toString(progressValue, 'f', 2) + "%"); painter->drawText(rect, Qt::AlignCenter, locale.toString(_pinfo.progress, 'f', 2) + "%");
} }
} }
@ -242,11 +241,6 @@ void xProgressBar::setColorSchema(const int value)
setColor(); setColor();
} }
void xProgressBar::setValue(const float value)
{
progressValue = value < 0 ? 0 : value > 100 ? 100 : value;
}
void xProgressBar::setDisplayText(const bool display) void xProgressBar::setDisplayText(const bool display)
{ {
displayText = display; displayText = display;

View File

@ -44,6 +44,7 @@ class FileProgressInfo
LineType type ; LineType type ;
CompressedChunkMap cmap ; CompressedChunkMap cmap ;
float progress ; float progress ;
uint32_t nb_chunks ;
}; };
// //
class xProgressBar : public QObject class xProgressBar : public QObject
@ -51,7 +52,7 @@ class xProgressBar : public QObject
Q_OBJECT Q_OBJECT
private: private:
// progress vlues // progress vlues
float progressValue; uint32_t _nb_chunks ;
int schemaIndex; int schemaIndex;
bool displayText; bool displayText;
int vSpan; int vSpan;
@ -70,13 +71,13 @@ Q_OBJECT
// configure the color // configure the color
void setColor(); void setColor();
const CompressedChunkMap& _cmap ; const FileProgressInfo& _pinfo ;
public: public:
xProgressBar(const CompressedChunkMap& cmap,QRect rect, QPainter *painter, int schemaIndex = 0); xProgressBar(const FileProgressInfo& pinfo,QRect rect, QPainter *painter, int schemaIndex = 0);
void paint(); void paint();
void setColorSchema(const int value); void setColorSchema(const int value);
void setValue(const float value);
void setDisplayText(const bool display); void setDisplayText(const bool display);
void setVerticalSpan(const int value); void setVerticalSpan(const int value);
void setHorizontalSpan(const int value); void setHorizontalSpan(const int value);