mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-02 11:16:34 -04:00
- Implemented chunk-based file transfer from partial sources. This in particular means:
- exchange of chunk availability maps from different peers - correct handling of what is available to which source before asking the data - correct display of chunks in the progress bars - generalised the use of compressed chunk maps - removed the size parameters from the hash search functions - In addition: - suppressed a number of per-value transfers of std::string - improved the FileTransferInfo Widget, to show some additional info Still to be done: - chunk map exchange for non anonymous traffic (easy) - improve accuracy of completion for uploads (for now it's a integer number of chunks) - check compilation on windows git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1993 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
add5d45eeb
commit
cfaaec31c7
36 changed files with 1247 additions and 573 deletions
|
@ -19,6 +19,7 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <rsiface/rstypes.h>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionProgressBarV2>
|
||||
|
@ -27,6 +28,8 @@
|
|||
|
||||
#include "DLListDelegate.h"
|
||||
|
||||
Q_DECLARE_METATYPE(FileProgressInfo)
|
||||
|
||||
DLListDelegate::DLListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
|
||||
{
|
||||
;
|
||||
|
@ -144,14 +147,14 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
|
|||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case PROGRESS:
|
||||
{
|
||||
progress = index.data().toDouble();
|
||||
// create a xProgressBar
|
||||
xProgressBar progressBar(option.rect, painter); // the 3rd param is the color schema (0 is the default value)
|
||||
progressBar.setDisplayText(false); // should display % text?
|
||||
progressBar.setValue(progress); // set the progress value
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
{
|
||||
// create a xProgressBar
|
||||
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)
|
||||
progressBar.setDisplayText(false); // should display % text?
|
||||
progressBar.setValue(pinfo.progress); // set the progress value
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
||||
break;
|
||||
|
|
|
@ -62,23 +62,16 @@ void FileTransferInfoWidget::updateDisplay()
|
|||
{
|
||||
std::cout << "In TaskGraphPainterWidget::updateDisplay()" << std::endl ;
|
||||
|
||||
bool ok=true ;
|
||||
FileInfo nfo ;
|
||||
if(!rsFiles->FileDetails(_file_hash, RS_FILE_HINTS_DOWNLOAD, nfo))
|
||||
return ;
|
||||
ok = false ;
|
||||
FileChunksInfo info ;
|
||||
if(!rsFiles->FileChunksDetails(_file_hash, info))
|
||||
return ;
|
||||
if(!rsFiles->FileDownloadChunksDetails(_file_hash, info))
|
||||
ok = false ;
|
||||
|
||||
std::cout << "got details for file " << nfo.fname << std::endl ;
|
||||
|
||||
uint64_t fileSize = info.file_size;
|
||||
uint32_t blockSize = info.chunk_size ;
|
||||
int blocks = info.chunks.size() ;
|
||||
|
||||
int columns = maxWidth/chunk_square_size;
|
||||
y = blocks/columns*chunk_square_size;
|
||||
x = blocks%columns*chunk_square_size;
|
||||
maxHeight = y+150+info.active_chunks.size()*(block_sep+text_height); // warning: this should be computed from the different size parameter and the number of objects drawn, otherwise the last objects to be displayed will be truncated.
|
||||
pixmap = QPixmap(size());
|
||||
pixmap.fill(this, 0, 0);
|
||||
pixmap = QPixmap(maxWidth, maxHeight);
|
||||
|
@ -88,7 +81,16 @@ void FileTransferInfoWidget::updateDisplay()
|
|||
QPainter painter(&pixmap);
|
||||
painter.initFrom(this);
|
||||
|
||||
draw(info,&painter) ;
|
||||
if(ok)
|
||||
{
|
||||
int blocks = info.chunks.size() ;
|
||||
int columns = maxWidth/chunk_square_size;
|
||||
y = blocks/columns*chunk_square_size;
|
||||
x = blocks%columns*chunk_square_size;
|
||||
maxHeight = y+150+info.active_chunks.size()*(block_sep+text_height); // warning: this should be computed from the different size parameter and the number of objects drawn, otherwise the last objects to be displayed will be truncated.
|
||||
|
||||
draw(info,&painter) ;
|
||||
}
|
||||
|
||||
pixmap2 = pixmap;
|
||||
}
|
||||
|
@ -194,8 +196,8 @@ void FileTransferInfoWidget::draw(const FileChunksInfo& info,QPainter *painter)
|
|||
int nb_src = 0 ;
|
||||
int chunk_num = (int)floor(i/float(availability_map_size_X)*(nb_chunks-1)) ;
|
||||
|
||||
for(uint j=0;j<info.compressed_peer_availability_maps.size();++j)
|
||||
nb_src += (bool)(COMPRESSED_MAP_READ(info.compressed_peer_availability_maps[j].second, chunk_num)) ;
|
||||
for(std::map<std::string,CompressedChunkMap>::const_iterator it(info.compressed_peer_availability_maps.begin());it!=info.compressed_peer_availability_maps.end();++it)
|
||||
nb_src += it->second[chunk_num] ;
|
||||
|
||||
painter->setPen(QColor::fromHsv(200,50*nb_src,200)) ; // the more sources, the more saturated
|
||||
painter->drawLine(i,y,i,y+availability_map_size_Y) ;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "DLListDelegate.h"
|
||||
#include "ULListDelegate.h"
|
||||
#include "FileTransferInfoWidget.h"
|
||||
#include "xprogressbar.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
|
@ -69,6 +70,34 @@
|
|||
#define IMAGE_PRIORITYHIGH ":/images/priorityhigh.png"
|
||||
#define IMAGE_PRIORITYAUTO ":/images/priorityauto.png"
|
||||
|
||||
//static const CompressedChunkMap *getMap_tmp()
|
||||
//{
|
||||
// static CompressedChunkMap *cmap = NULL ;
|
||||
//
|
||||
// if(cmap == NULL)
|
||||
// {
|
||||
// cmap = new CompressedChunkMap ; // to be passed as a parameter
|
||||
// // Initialize the chunkmap with a dummy value, for testing. To be removed...
|
||||
// cmap->_nb_chunks = 700 ;
|
||||
// cmap->_map.resize(cmap->_nb_chunks/32+1,0) ;
|
||||
// cmap->_progress = 0.34 ;
|
||||
// for(uint i=0;i<10;++i)
|
||||
// {
|
||||
// uint32_t start = rand()%cmap->_nb_chunks;
|
||||
// uint32_t j = std::min((int)cmap->_nb_chunks,(int)start+10+(rand()%5)) ;
|
||||
//
|
||||
// for(uint32_t k=start;k<j;++k)
|
||||
// COMPRESSED_MAP_WRITE(cmap->_map,k,1) ;
|
||||
// }
|
||||
//
|
||||
// std::cerr << "Built cmap = " << (void*)cmap << std::endl ;
|
||||
// }
|
||||
// return cmap ;
|
||||
//}
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(FileProgressInfo)
|
||||
|
||||
|
||||
/** Constructor */
|
||||
TransfersDialog::TransfersDialog(QWidget *parent)
|
||||
|
@ -378,11 +407,11 @@ void TransfersDialog::playSelectedTransfer()
|
|||
|
||||
void TransfersDialog::updateProgress(int value)
|
||||
{
|
||||
for(int i = 0; i <= DLListModel->rowCount(); i++) {
|
||||
if(selection->isRowSelected(i, QModelIndex())) {
|
||||
editItem(i, PROGRESS, QVariant((double)value));
|
||||
}
|
||||
}
|
||||
// for(int i = 0; i <= DLListModel->rowCount(); i++) {
|
||||
// if(selection->isRowSelected(i, QModelIndex())) {
|
||||
// editItem(i, PROGRESS, QVariant((double)value));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
TransfersDialog::~TransfersDialog()
|
||||
|
@ -391,8 +420,7 @@ TransfersDialog::~TransfersDialog()
|
|||
}
|
||||
|
||||
|
||||
|
||||
int TransfersDialog::addItem(QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed,
|
||||
int TransfersDialog::addItem(QString symbol, QString name, QString coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
|
||||
QString sources, QString status, QString priority, qlonglong completed, qlonglong remaining)
|
||||
{
|
||||
int row;
|
||||
|
@ -408,7 +436,7 @@ int TransfersDialog::addItem(QString symbol, QString name, QString coreID, qlong
|
|||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
|
||||
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
|
||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)dlspeed));
|
||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)progress));
|
||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant::fromValue(pinfo));
|
||||
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant((QString)sources));
|
||||
DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status));
|
||||
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((QString)priority));
|
||||
|
@ -469,7 +497,7 @@ int TransfersDialog::addItem(QString symbol, QString name, QString coreID, qlong
|
|||
return row;
|
||||
}
|
||||
|
||||
bool TransfersDialog::addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining)
|
||||
bool TransfersDialog::addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining)
|
||||
{
|
||||
QStandardItem *dlItem = DLListModel->item(row);
|
||||
if (!dlItem) return false;
|
||||
|
@ -484,7 +512,7 @@ bool TransfersDialog::addPeerToItem(int row, QString symbol, QString name, QStri
|
|||
QStandardItem *i2 = new QStandardItem(); i2->setData(QVariant((qlonglong)fileSize), Qt::DisplayRole);
|
||||
QStandardItem *i3 = new QStandardItem(); i3->setData(QVariant((qlonglong)completed), Qt::DisplayRole);
|
||||
QStandardItem *i4 = new QStandardItem(); i4->setData(QVariant((double)dlspeed), Qt::DisplayRole);
|
||||
QStandardItem *i5 = new QStandardItem(); i5->setData(QVariant((double)progress), Qt::DisplayRole);
|
||||
QStandardItem *i5 = new QStandardItem(); i5->setData(QVariant::fromValue(pinfo), Qt::DisplayRole);
|
||||
QStandardItem *i6 = new QStandardItem(); i6->setData(QVariant((QString)sources), Qt::DisplayRole);
|
||||
QStandardItem *i7 = new QStandardItem(); i7->setData(QVariant((QString)status), Qt::DisplayRole);
|
||||
QStandardItem *i8 = new QStandardItem(); i8->setData(QVariant((QString)tr("")), Qt::DisplayRole); // blank field for priority
|
||||
|
@ -522,7 +550,7 @@ bool TransfersDialog::addPeerToItem(int row, QString symbol, QString name, QStri
|
|||
}
|
||||
|
||||
|
||||
int TransfersDialog::addUploadItem(QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining)
|
||||
int TransfersDialog::addUploadItem(QString symbol, QString name, QString coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, QString source, QString status, qlonglong completed, qlonglong remaining)
|
||||
{
|
||||
int row;
|
||||
QString sl;
|
||||
|
@ -535,9 +563,9 @@ int TransfersDialog::addUploadItem(QString symbol, QString name, QString coreID,
|
|||
ULListModel->setData(ULListModel->index(row, USIZE), QVariant((qlonglong)fileSize));
|
||||
ULListModel->setData(ULListModel->index(row, UTRANSFERRED), QVariant((qlonglong)completed));
|
||||
ULListModel->setData(ULListModel->index(row, ULSPEED), QVariant((double)dlspeed));
|
||||
ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant((double)progress));
|
||||
ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant::fromValue(pinfo));
|
||||
ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status));
|
||||
ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)sources));
|
||||
ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
@ -568,9 +596,9 @@ void TransfersDialog::editItem(int row, int column, QVariant data)
|
|||
case SIZE:
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), data);
|
||||
break;
|
||||
case PROGRESS:
|
||||
DLListModel->setData(DLListModel->index(row, PROGRESS), data);
|
||||
break;
|
||||
// case PROGRESS:
|
||||
// DLListModel->setData(DLListModel->index(row, PROGRESS), data);
|
||||
// break;
|
||||
case DLSPEED:
|
||||
DLListModel->setData(DLListModel->index(row, DLSPEED), data);
|
||||
break;
|
||||
|
@ -670,7 +698,8 @@ void TransfersDialog::insertTransfers()
|
|||
uint32_t ulCount = 0;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for (it = downHashes.begin(); it != downHashes.end(); it++) {
|
||||
for (it = downHashes.begin(); it != downHashes.end(); it++)
|
||||
{
|
||||
FileInfo info;
|
||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
||||
//if file transfer is a cache file index file, don't show it
|
||||
|
@ -713,7 +742,21 @@ void TransfersDialog::insertTransfers()
|
|||
completed = info.transfered;
|
||||
remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||
|
||||
int addedRow = addItem(symbol, name, coreId, fileSize, progress, dlspeed, sources, status, priority, completed, remaining);
|
||||
FileChunksInfo fcinfo ;
|
||||
if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo))
|
||||
continue ;
|
||||
|
||||
FileProgressInfo pinfo ;
|
||||
pinfo.cmap = fcinfo.chunks ;
|
||||
pinfo.progress = completed*100.0/info.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);
|
||||
|
||||
/* if found in selectedIds -> select again */
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), info.hash)) {
|
||||
|
@ -777,7 +820,11 @@ void TransfersDialog::insertTransfers()
|
|||
completed = info.transfered;
|
||||
remaining = (info.size - info.transfered) / (pit->tfRate * 1024.0);
|
||||
|
||||
if (!addPeerToItem(addedRow, symbol, name, coreId, fileSize, progress, dlspeed, sources, status, completed, remaining))
|
||||
FileProgressInfo pinfo ;
|
||||
pinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId] ;
|
||||
pinfo.progress = 0.0 ; // we don't display completion for sources.
|
||||
|
||||
if (!addPeerToItem(addedRow, symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining))
|
||||
continue;
|
||||
|
||||
/* if peers found in selectedIds, select again */
|
||||
|
@ -826,7 +873,10 @@ void TransfersDialog::insertTransfers()
|
|||
break;
|
||||
}
|
||||
|
||||
addItem("", name, coreId, fileSize, progress, dlspeed, sources, status, priority, completed, remaining);
|
||||
FileProgressInfo pinfo ;
|
||||
pinfo.progress = 0.0 ;
|
||||
|
||||
addItem("", name, coreId, fileSize, pinfo, dlspeed, sources, status, priority, completed, remaining);
|
||||
|
||||
/* if found in selectedIds -> select again */
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), dit->hash)) {
|
||||
|
@ -890,14 +940,36 @@ void TransfersDialog::insertTransfers()
|
|||
// status = "Complete";
|
||||
// }
|
||||
|
||||
FileProgressInfo pinfo ;
|
||||
|
||||
if(!rsFiles->FileUploadChunksDetails(*it,pit->peerId,pinfo.cmap) )
|
||||
continue ;
|
||||
|
||||
dlspeed = pit->tfRate * 1024.0;
|
||||
fileSize = info.size;
|
||||
completed = info.transfered;
|
||||
progress = info.transfered * 100.0 / info.size;
|
||||
remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||
|
||||
addUploadItem(symbol, name, coreId, fileSize, progress,
|
||||
dlspeed, sources, status, completed, remaining);
|
||||
// Estimate the completion. We need something more accurate, meaning that we need to
|
||||
// transmit the completion info.
|
||||
//
|
||||
uint32_t chunk_size = 1024*1024 ;
|
||||
uint32_t nb_chunks = (uint32_t)(info.size / (uint64_t)(chunk_size) ) ;
|
||||
if((info.size % (uint64_t)chunk_size) != 0)
|
||||
++nb_chunks ;
|
||||
|
||||
uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ;
|
||||
|
||||
if(filled_chunks > 1)
|
||||
{
|
||||
pinfo.progress = filled_chunks*100.0/nb_chunks ;
|
||||
completed = std::min(info.size,((uint64_t)filled_chunks)*chunk_size) ;
|
||||
}
|
||||
else
|
||||
pinfo.progress = progress ;
|
||||
|
||||
addUploadItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining);
|
||||
ulCount++;
|
||||
}
|
||||
|
||||
|
@ -935,8 +1007,11 @@ void TransfersDialog::insertTransfers()
|
|||
progress = info.transfered * 100.0 / info.size;
|
||||
remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||
|
||||
addUploadItem(symbol, name, coreId, fileSize, progress,
|
||||
dlspeed, sources, status, completed, remaining);
|
||||
FileProgressInfo pinfo ;
|
||||
pinfo.progress = progress ;
|
||||
pinfo.cmap = CompressedChunkMap() ;
|
||||
|
||||
addUploadItem(symbol, name, coreId, fileSize, pinfo, dlspeed, sources, status, completed, remaining);
|
||||
ulCount++;
|
||||
}
|
||||
}
|
||||
|
@ -1411,6 +1486,8 @@ void TransfersDialog::showFileDetails()
|
|||
std::string file_hash ;
|
||||
int nb_select = 0 ;
|
||||
|
||||
std::cout << "new selection " << std::endl ;
|
||||
|
||||
for(int i = 0; i <= DLListModel->rowCount(); i++)
|
||||
if(selection->isRowSelected(i, QModelIndex()))
|
||||
{
|
||||
|
@ -1418,15 +1495,19 @@ void TransfersDialog::showFileDetails()
|
|||
++nb_select ;
|
||||
}
|
||||
if(nb_select != 1)
|
||||
return ;
|
||||
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash("") ;
|
||||
else
|
||||
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash(file_hash) ;
|
||||
|
||||
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash(file_hash) ;
|
||||
std::cout << "calling update " << std::endl ;
|
||||
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->updateDisplay() ;
|
||||
std::cout << "done" << std::endl ;
|
||||
}
|
||||
|
||||
double TransfersDialog::getProgress(int row, QStandardItemModel *model)
|
||||
{
|
||||
return model->data(model->index(row, PROGRESS), Qt::DisplayRole).toDouble();
|
||||
// return model->data(model->index(row, PROGRESS), Qt::DisplayRole).toDouble();
|
||||
return 0.0 ;
|
||||
}
|
||||
|
||||
double TransfersDialog::getSpeed(int row, QStandardItemModel *model)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <rsiface/rstypes.h>
|
||||
#include "mainpage.h"
|
||||
#include "RsAutoUpdatePage.h"
|
||||
#include "xprogressbar.h"
|
||||
|
||||
#include "ui_TransfersDialog.h"
|
||||
|
||||
|
@ -165,11 +166,11 @@ class TransfersDialog : public RsAutoUpdatePage
|
|||
Ui::TransfersDialog ui;
|
||||
|
||||
public slots:
|
||||
int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, QString priority, qlonglong completed, qlonglong remaining);
|
||||
bool addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
int addItem(QString symbol, QString name, QString coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, QString sources, QString status, QString priority, qlonglong completed, qlonglong remaining);
|
||||
bool addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
void delItem(int row);
|
||||
|
||||
int addUploadItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
int addUploadItem(QString symbol, QString name, QString coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
void delUploadItem(int row);
|
||||
|
||||
void editItem(int row, int column, QVariant data);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <rsiface/rstypes.h>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionProgressBarV2>
|
||||
|
@ -28,6 +29,8 @@
|
|||
|
||||
#include "ULListDelegate.h"
|
||||
|
||||
Q_DECLARE_METATYPE(FileProgressInfo)
|
||||
|
||||
ULListDelegate::ULListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
|
||||
{
|
||||
;
|
||||
|
@ -123,25 +126,22 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
|
|||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case UPROGRESS:
|
||||
{
|
||||
progress = index.data().toDouble();
|
||||
// create a xProgressBar
|
||||
xProgressBar progressBar(option.rect, painter );// 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();;
|
||||
if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb")
|
||||
{
|
||||
progressBar.setColorSchema( 9);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.setColorSchema( 8);
|
||||
}
|
||||
|
||||
progressBar.setDisplayText(false); // should display % text?
|
||||
progressBar.setValue(progress); // set the progress value
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
{
|
||||
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
|
||||
|
||||
// create a xProgressBar
|
||||
xProgressBar progressBar(pinfo.cmap,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();;
|
||||
if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb")
|
||||
progressBar.setColorSchema( 9);
|
||||
else
|
||||
progressBar.setColorSchema( 8);
|
||||
|
||||
progressBar.setDisplayText(true); // should display % text?
|
||||
progressBar.setValue(pinfo.progress); // set the progress value
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
||||
break;
|
||||
|
|
|
@ -24,9 +24,12 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <rsiface/rstypes.h>
|
||||
#include "xprogressbar.h"
|
||||
|
||||
xProgressBar::xProgressBar(QRect rect, QPainter *painter, int schemaIndex)
|
||||
xProgressBar::xProgressBar(const CompressedChunkMap& cmap,QRect rect, QPainter *painter, int schemaIndex)
|
||||
: _cmap(cmap)
|
||||
{
|
||||
// assign internal data
|
||||
this->schemaIndex = schemaIndex;
|
||||
|
@ -39,7 +42,7 @@ xProgressBar::xProgressBar(QRect rect, QPainter *painter, int schemaIndex)
|
|||
vSpan = 0;
|
||||
hSpan = 0;
|
||||
// text color
|
||||
textColor = QColor("white");
|
||||
textColor = QColor("black");
|
||||
}
|
||||
|
||||
void xProgressBar::setColor()
|
||||
|
@ -187,14 +190,41 @@ void xProgressBar::paint()
|
|||
linearGrad.setColorAt(1.00, gradColor1);
|
||||
painter->setPen(gradBorderColor);
|
||||
|
||||
// calculate progress value
|
||||
int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(progressValue/100));
|
||||
int progressWidth = rect.width() - preWidth;
|
||||
if (progressWidth == rect.width() - hSpan) return;
|
||||
int width = static_cast<int>(rect.width()-1-2*hSpan) ;
|
||||
|
||||
// paint the progress
|
||||
painter->setBrush(linearGrad);
|
||||
painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - progressWidth - hSpan, rect.height() - 1 - vSpan * 2);
|
||||
|
||||
uint32_t ss = _cmap._map.size()*32 ;
|
||||
|
||||
if(ss > 1) // for small files we use a more progressive display
|
||||
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) ;
|
||||
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
|
||||
{
|
||||
// calculate progress value
|
||||
int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(progressValue/100));
|
||||
int progressWidth = rect.width() - preWidth;
|
||||
if (progressWidth == rect.width() - hSpan) return;
|
||||
|
||||
// paint the progress
|
||||
painter->setBrush(linearGrad);
|
||||
painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - progressWidth - hSpan, rect.height() - 1 - vSpan * 2);
|
||||
}
|
||||
painter->setOpacity(1.0f) ;
|
||||
|
||||
|
||||
// paint text?
|
||||
if (displayText)
|
||||
|
|
|
@ -27,11 +27,21 @@
|
|||
#ifndef XPROGRESSBAR_H
|
||||
#define XPROGRESSBAR_H
|
||||
//
|
||||
#include <stdint.h>
|
||||
#include <QRect>
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QLinearGradient>
|
||||
#include <QLocale>
|
||||
|
||||
#include <rsiface/rstypes.h>
|
||||
|
||||
class FileProgressInfo
|
||||
{
|
||||
public:
|
||||
CompressedChunkMap cmap ;
|
||||
float progress ;
|
||||
};
|
||||
//
|
||||
class xProgressBar : public QObject
|
||||
{
|
||||
|
@ -56,8 +66,11 @@ Q_OBJECT
|
|||
QColor gradColor2;
|
||||
// configure the color
|
||||
void setColor();
|
||||
|
||||
const CompressedChunkMap& _cmap ;
|
||||
public:
|
||||
xProgressBar(QRect rect, QPainter *painter, int schemaIndex = 0);
|
||||
xProgressBar(const CompressedChunkMap& cmap,QRect rect, QPainter *painter, int schemaIndex = 0);
|
||||
|
||||
void paint();
|
||||
void setColorSchema(const int value);
|
||||
void setValue(const float value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue