fixed up FileTransferInfoWidget for high DPI

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8575 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-07-01 20:04:12 +00:00
parent d870b13a49
commit bdb85a3f54
6 changed files with 50 additions and 33 deletions

View File

@ -30,15 +30,15 @@
#include "FileTransferInfoWidget.h"
#include <gui/RetroShareLink.h>
// Variables to decide of display behaviour. Should be adapted to window size.
// Variables to decide of display behaviour. All variables are expressed as a factor of font height
//
static const int chunk_square_size = 13 ;
static const int text_height = 10 ; // should be set according to the font size
static const int block_sep = 4 ; // separator between blocks
static const int ch_num_size = 50 ; // size of field for chunk number
static const int availability_map_size_X = 400 ;// length of availability bar
static const int availability_map_size_Y = 20 ; // height of availability bar
static const int tab_size = 200 ;// size between tabulated entries
static const float chunk_square_size_factor = 1.0 ;
static const float text_height_factor = 0.9 ;// should be set according to the font size
static const float block_sep_factor = 0.4 ;// separator between blocks
static const float ch_num_size_factor = 5.0 ;// size of field for chunk number
static const float availability_map_size_X_factor = 40.0;// length of availability bar
static const float availability_map_size_Y_factor = 2.0 ;// height of availability bar
static const float tab_size_factor = 20.0;// size between tabulated entries
FileTransferInfoWidget::FileTransferInfoWidget(QWidget * /*parent*/, Qt::WindowFlags /*f*/ )
{
@ -48,10 +48,12 @@ FileTransferInfoWidget::FileTransferInfoWidget(QWidget * /*parent*/, Qt::WindowF
pixmap = QPixmap(size());
pixmap.fill(Qt::transparent);
downloadedPixmap.load(":images/graph-downloaded.png");
downloadingPixmap.load(":images/graph-downloading.png");
notDownloadPixmap.load(":images/graph-notdownload.png");
checkingPixmap.load(":images/graph-checking.png");
int S = 0.9*QFontMetricsF(font()).height();
downloadedPixmap = QPixmap(":/icons/tile_downloaded_48.png").scaledToHeight(S,Qt::SmoothTransformation);
downloadingPixmap = QPixmap(":/icons/tile_downloading_48.png").scaledToHeight(S,Qt::SmoothTransformation);
notDownloadPixmap = QPixmap(":/icons/tile_inactive_48.png").scaledToHeight(S,Qt::SmoothTransformation);
checkingPixmap = QPixmap(":/icons/tile_checking_48.png").scaledToHeight(S,Qt::SmoothTransformation);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
@ -77,8 +79,6 @@ void FileTransferInfoWidget::updateDisplay()
//std::cout << "got details for file " << nfo.fname << std::endl ;
// pixmap = QPixmap(size());
// pixmap.fill(this, 0, 0);
pixmap = QPixmap(maxWidth, maxHeight);
pixmap.fill(Qt::transparent);
setFixedHeight(maxHeight);
@ -86,13 +86,16 @@ void FileTransferInfoWidget::updateDisplay()
QPainter painter(&pixmap);
painter.initFrom(this);
float S = QFontMetricsF(font()).height();
int chunk_square_size = S*chunk_square_size_factor;
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.
maxHeight = y+15*S+info.active_chunks.size()*(block_sep_factor*S+text_height_factor*S); // 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(nfo,info,&painter) ;
}
@ -110,14 +113,24 @@ void FileTransferInfoWidget::paintEvent(QPaintEvent */*event*/)
void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info,QPainter *painter)
{
float S = QFontMetricsF(font()).height() ;
x=0;
y=5;
y=0.5*S;
int blocks = info.chunks.size() ;
uint64_t fileSize = info.file_size ;
uint32_t blockSize = info.chunk_size ;
if (fileSize%blockSize == 0) blocks--;
QRectF source(0.0, 0.0, 12.0, 12.0);
QRectF source(0.0, 0.0, 1.05*S, 1.05*S);
int chunk_square_size = chunk_square_size_factor*S ;
int availability_map_size_X = availability_map_size_X_factor*S ;
int availability_map_size_Y = availability_map_size_Y_factor*S ;
int text_height = text_height_factor*S ;
int block_sep = block_sep_factor*S ;
int ch_num_size = ch_num_size_factor*S ;
int tab_size = tab_size_factor*S ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
y += text_height ;
@ -133,7 +146,7 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
x = 0;
y += chunk_square_size;
}
QRectF target(x, y, 12.0, 12.0);
QRectF target(x, y, 1.05*S, 1.05*S);
switch(info.chunks[i])
{
@ -159,8 +172,8 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
painter->setPen(QColor::fromRgb(70,70,70)) ;
painter->drawLine(0,y,maxWidth,y) ;
uint32_t sizeX = 100 ;
uint32_t sizeY = 10 ;
uint32_t sizeX = 10*S ;
uint32_t sizeY = 1*S ;
y += block_sep ;
y += text_height ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
@ -170,7 +183,7 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
for(uint i=0;i<info.active_chunks.size();++i)
{
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(5,y+text_height,QString::number(info.active_chunks[i].first)) ;
painter->drawText(0.5*S,y+text_height*0.9,QString::number(info.active_chunks[i].first)) ;
int size_of_this_chunk = ( info.active_chunks[i].first == info.chunks.size()-1 && ((info.file_size % blockSize)>0) )?(info.file_size % blockSize):blockSize ;
uint32_t s = (uint32_t)rint(sizeX*(size_of_this_chunk - info.active_chunks[i].second)/(float)size_of_this_chunk) ;
@ -202,7 +215,7 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
painter->setPen(QColor::fromRgb(0,0,0)) ;
float percent = (size_of_this_chunk - info.active_chunks[i].second)*100.0/size_of_this_chunk ;
painter->drawText(sizeX+55,y+text_height,QString::number(percent,'f',2) + " %") ;
painter->drawText(sizeX+5.5*S,y+text_height*0.9,QString::number(percent,'f',2) + " %") ;
y += sizeY+block_sep ;
}
@ -244,25 +257,25 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
painter->setPen(QColor::fromRgb(0,0,0)) ;
y += text_height ; painter->drawText(0,y,tr("File info") + ":") ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("File name") + ":") ; painter->drawText(tab_size,y,QString::fromUtf8(nfo.fname.c_str())) ;
y += text_height ; painter->drawText(2*S,y,tr("File name") + ":") ; painter->drawText(tab_size,y,QString::fromUtf8(nfo.fname.c_str())) ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Destination folder") + ":") ; painter->drawText(tab_size,y,QString::fromUtf8(nfo.path.c_str())) ;
y += text_height ; painter->drawText(2*S,y,tr("Destination folder") + ":") ; painter->drawText(tab_size,y,QString::fromUtf8(nfo.path.c_str())) ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("File hash") + ":") ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash.toStdString())) ;
y += text_height ; painter->drawText(2*S,y,tr("File hash") + ":") ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash.toStdString())) ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("File size") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size) + ")") ;
y += text_height ; painter->drawText(2*S,y,tr("File size") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size) + ")") ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Chunk size") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunk_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.chunk_size) + ")") ;
y += text_height ; painter->drawText(2*S,y,tr("Chunk size") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunk_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.chunk_size) + ")") ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Number of chunks") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
y += text_height ; painter->drawText(2*S,y,tr("Number of chunks") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Transferred") + ":") ; painter->drawText(tab_size,y,QString::number(nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(nfo.transfered) + ")") ;
y += text_height ; painter->drawText(2*S,y,tr("Transferred") + ":") ; painter->drawText(tab_size,y,QString::number(nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(nfo.transfered) + ")") ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Remaining") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size - nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size - nfo.transfered) + ")") ;
y += text_height ; painter->drawText(2*S,y,tr("Remaining") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size - nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size - nfo.transfered) + ")") ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Number of sources") + ":") ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ;
y += text_height ; painter->drawText(2*S,y,tr("Number of sources") + ":") ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ;
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Chunk strategy") + ":") ;
y += text_height ; painter->drawText(2*S,y,tr("Chunk strategy") + ":") ;
switch(info.strategy)
{
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: painter->drawText(tab_size,y,"Random") ; break ;
@ -271,7 +284,7 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
case FileChunksInfo::CHUNK_STRATEGY_STREAMING: painter->drawText(tab_size,y,"Streaming") ; break ;
}
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("Transfer type") + ":") ;
y += text_height ; painter->drawText(2*S,y,tr("Transfer type") + ":") ;
if(nfo.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) painter->drawText(tab_size,y,tr("Anonymous F2F")) ;
if(nfo.transfer_info_flags & RS_FILE_REQ_ASSUME_AVAILABILITY) painter->drawText(tab_size,y,tr("Direct friend transfer / Availability assumed")) ;
y += text_height ;

View File

@ -43,5 +43,9 @@
<file>icons/security_low_128.png</file>
<file>icons/security_medium_128.png</file>
<file>icons/system_128.png</file>
<file>icons/tile_checking_48.png</file>
<file>icons/tile_downloaded_48.png</file>
<file>icons/tile_downloading_48.png</file>
<file>icons/tile_inactive_48.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB