first attempt at fixing statistics layout for high DPI screens, using the font metrics to determine the scaling ratio

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8553 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-06-24 20:55:09 +00:00
parent da8b6cbae1
commit 7334e4d5de
5 changed files with 159 additions and 130 deletions

View File

@ -388,7 +388,10 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
//std::cerr << "Got " << values.size() << " values for index 0" << std::endl;
float last_px = SCALE_WIDTH ;
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
float last_px = SCALE_WIDTH*fact ;
float last_py = 0.0f ;
for (uint i = 0; i < values.size(); ++i)
@ -400,10 +403,10 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
qreal px = x - (values[i].x()-last)*_time_scale ;
qreal py = y - valueToPixels(values[i].y()) ;
if(px >= SCALE_WIDTH && last_px < SCALE_WIDTH)
if(px >= SCALE_WIDTH *fact&& last_px < SCALE_WIDTH*fact)
{
float alpha = (SCALE_WIDTH - last_px)/(px - last_px) ;
float ipx = SCALE_WIDTH ;
float alpha = (SCALE_WIDTH*fact - last_px)/(px - last_px) ;
float ipx = SCALE_WIDTH*fact ;
float ipy = (1-alpha)*last_py + alpha*py ;
points << QPointF(ipx,y) ;
@ -415,7 +418,7 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
last_px = px ;
last_py = py ;
if(px < SCALE_WIDTH)
if(px < SCALE_WIDTH*fact)
continue ;
_maxValue = std::max(_maxValue,values[i].y()) ;
@ -475,8 +478,11 @@ void RSGraphWidget::paintLine(const QVector<QPointF>& points, QColor color, Qt::
/** Paints selected total indicators on the graph. */
void RSGraphWidget::paintTotals()
{
int x = SCALE_WIDTH + FONT_SIZE, y = 0;
int rowHeight = FONT_SIZE;
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
int x = SCALE_WIDTH*fact + FS, y = 0;
int rowHeight = FS;
#if !defined(Q_WS_MAC)
/* On Mac, we don't need vertical spacing between the text rows. */
@ -503,7 +509,10 @@ QString RSGraphWidget::totalToStr(qreal total)
/** Paints the scale on the graph. */
void RSGraphWidget::paintScale1()
{
int top = _rec.y();
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
int top = _rec.y();
int bottom = _rec.height();
qreal paintStep = (bottom - (bottom/10)) / 4;
@ -525,31 +534,34 @@ void RSGraphWidget::paintScale1()
QString text = _source->displayValue(scale) ;
_painter->setPen(SCALE_COLOR);
_painter->drawText(QPointF(5, pos+0.5*FONT_SIZE), text);
_painter->drawText(QPointF(5*fact, pos+0.5*FS), text);
_painter->setPen(GRID_COLOR);
_painter->drawLine(QPointF(SCALE_WIDTH, pos), QPointF(_rec.width(), pos));
_painter->drawLine(QPointF(SCALE_WIDTH*fact, pos), QPointF(_rec.width(), pos));
}
/* Draw vertical separator */
_painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom);
_painter->drawLine(SCALE_WIDTH*fact, top, SCALE_WIDTH*fact, bottom);
}
void RSGraphWidget::paintScale2()
{
// draw time below the graph
int bottom = _rec.height();
static const int npix = 100 ;
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
for(int i=_rec.width();i>SCALE_WIDTH;i-=npix)
int bottom = _rec.height();
static const int npix = 100*fact ;
for(int i=_rec.width();i>SCALE_WIDTH*fact;i-=npix)
{
qreal pos = bottom - FONT_SIZE;
qreal pos = bottom - FS;
int seconds = (_rec.width()-i)/_time_scale ; // pixels / (pixels per second) => seconds
QString text = QString::number(seconds)+ " secs";
_painter->setPen(SCALE_COLOR);
_painter->drawText(QPointF(i, _rec.height()-0.5*FONT_SIZE), text);
_painter->drawText(QPointF(i, _rec.height()-0.5*FS), text);
}
}
@ -571,23 +583,26 @@ void RSGraphWidget::paintLegend()
_source->getCurrentValues(vals) ;
int j=0;
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
for(uint i=0;i<vals.size();++i)
if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() )
{
if( _rec.width() - (vals[i].x()-0)*_time_scale < SCALE_WIDTH )
if( _rec.width() - (vals[i].x()-0)*_time_scale < SCALE_WIDTH*fact )
continue ;
qreal paintStep = 4+FONT_SIZE;
qreal pos = 20+j*paintStep;
qreal paintStep = 4*fact+FS;
qreal pos = 15*fact+j*paintStep;
QString text = _source->legend(i,vals[i].y()) ;
QPen oldPen = _painter->pen();
_painter->setPen(QPen(getColor(i), Qt::SolidLine));
_painter->drawLine(QPointF(SCALE_WIDTH+10.0, pos), QPointF(SCALE_WIDTH+30.0, pos));
_painter->drawLine(QPointF(SCALE_WIDTH*fact+10.0*fact, pos), QPointF(SCALE_WIDTH*fact+30.0*fact, pos));
_painter->setPen(oldPen);
_painter->setPen(SCALE_COLOR);
_painter->drawText(QPointF(SCALE_WIDTH + 40,pos + 0.5*FONT_SIZE), text) ;
_painter->drawText(QPointF(SCALE_WIDTH *fact+ 40*fact,pos + 0.5*FS), text) ;
++j ;
}

View File

@ -32,7 +32,6 @@
#include <stdint.h>
#define HOR_SPC 2 /** Space between data points */
#define SCALE_WIDTH 75 /** Width of the scale */
#define MINUSER_SCALE 2000 /** 2000 users is the minimum scale */
#define SCROLL_STEP 4 /** Horizontal change on graph update */
@ -43,8 +42,6 @@
#define RSDHT_COLOR Qt::magenta
#define ALLDHT_COLOR Qt::yellow
#define FONT_SIZE 11
// This class provides a source value that the graph can retrieve on demand.
// In order to use your own source, derive from RSGraphSource and overload the value() method.
//

View File

@ -166,9 +166,12 @@ void BWListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
painter->restore();
}
QSize BWListDelegate::sizeHint(const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const
QSize BWListDelegate::sizeHint(const QStyleOptionViewItem & option/*option*/, const QModelIndex & /*index*/) const
{
return QSize(50,17);
float FS = QFontMetricsF(option.font).height();
float fact = FS/14.0 ;
return QSize(50*fact,17*fact);
}
BwCtrlWindow::BwCtrlWindow(QWidget *parent)
@ -179,9 +182,12 @@ BwCtrlWindow::BwCtrlWindow(QWidget *parent)
BWDelegate = new BWListDelegate();
bwTreeWidget->setItemDelegate(BWDelegate);
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
/* Set header resize modes and initial section sizes Peer TreeView*/
QHeaderView * _header = bwTreeWidget->header () ;
_header->resizeSection ( COLUMN_RSNAME, 170 );
_header->resizeSection ( COLUMN_RSNAME, 170*fact );
}
BwCtrlWindow::~BwCtrlWindow()

View File

@ -52,8 +52,11 @@ static QString serviceName(uint16_t s)
void OutQueueStatisticsWidget::updateStatistics(OutQueueStatistics& stats)
{
static const int cellx = 6 ;
static const int celly = 10+4 ;
float fontHeight = QFontMetricsF(font()).height();
float fact = fontHeight/14.0;
const int cellx = 6*fact ;
const int celly = (10+4) *fact;
QPixmap tmppixmap(maxWidth, maxHeight);
tmppixmap.fill(Qt::transparent);
@ -62,11 +65,11 @@ void OutQueueStatisticsWidget::updateStatistics(OutQueueStatistics& stats)
QPainter painter(&tmppixmap);
painter.initFrom(this);
maxHeight = 500 ;
maxHeight = 500*fact ;
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
// draw...
int ox=5,oy=5 ;
int ox=5*fact,oy=5*fact ;
painter.setPen(QColor::fromRgb(70,70,70)) ;
//painter.drawLine(0,oy,maxWidth,oy) ;

View File

@ -48,129 +48,132 @@ class TRHistogram
return QColor::fromHsv((int)((1.0-f)*280),200,255) ;
}
virtual void draw(QPainter *painter,int& ox,int& oy,const QString& title)
{
static const int MaxTime = 61 ;
static const int MaxDepth = 8 ;
static const int cellx = 7 ;
static const int celly = 12 ;
virtual void draw(QPainter *painter,int& ox,int& oy,const QString& title,float fontHeight)
{
static const int MaxTime = 61 ;
static const int MaxDepth = 8 ;
int save_ox = ox ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(2+ox,celly+oy,title) ;
oy+=2+2*celly ;
float fact = fontHeight/14.0 ;
if(_infos.empty())
return ;
const int cellx = fact*7 ;
const int celly = fact*12 ;
ox += 10 ;
int save_ox = ox ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(2*fact+ox,celly+oy,title) ;
oy+=2*fact+2*celly ;
if(_infos.empty())
return ;
ox += 10 *fact;
std::map<RsPeerId,std::vector<int> > hits ;
std::map<RsPeerId,std::vector<int> > depths ;
std::map<RsPeerId,std::vector<int> >::iterator it ;
int max_hits = 1;
int max_depth = 1;
int max_hits = 1;
int max_depth = 1;
for(uint32_t i=0;i<_infos.size();++i)
{
std::vector<int>& h(hits[_infos[i].source_peer_id]) ;
std::vector<int>& g(depths[_infos[i].source_peer_id]) ;
for(uint32_t i=0;i<_infos.size();++i)
{
std::vector<int>& h(hits[_infos[i].source_peer_id]) ;
std::vector<int>& g(depths[_infos[i].source_peer_id]) ;
if(h.size() <= _infos[i].age)
h.resize(MaxTime,0) ;
if(h.size() <= _infos[i].age)
h.resize(MaxTime,0) ;
if(g.empty())
g.resize(MaxDepth,0) ;
if(g.empty())
g.resize(MaxDepth,0) ;
if(_infos[i].age < h.size())
{
++h[_infos[i].age] ;
if(h[_infos[i].age] > max_hits)
max_hits = h[_infos[i].age] ;
}
if(_infos[i].depth < g.size())
{
++g[_infos[i].depth] ;
if(_infos[i].age < h.size())
{
++h[_infos[i].age] ;
if(h[_infos[i].age] > max_hits)
max_hits = h[_infos[i].age] ;
}
if(_infos[i].depth < g.size())
{
++g[_infos[i].depth] ;
if(g[_infos[i].depth] > max_depth)
max_depth = g[_infos[i].depth] ;
}
}
if(g[_infos[i].depth] > max_depth)
max_depth = g[_infos[i].depth] ;
}
}
int max_bi = std::max(max_hits,max_depth) ;
int p=0 ;
int max_bi = std::max(max_hits,max_depth) ;
int p=0 ;
for(it=depths.begin();it!=depths.end();++it,++p)
for(int i=0;i<MaxDepth;++i)
painter->fillRect(ox+MaxTime*cellx+20+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
for(it=depths.begin();it!=depths.end();++it,++p)
for(int i=0;i<MaxDepth;++i)
painter->fillRect(ox+MaxTime*cellx+20*fact+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawRect(ox+MaxTime*cellx+20,oy,MaxDepth*cellx,p*celly) ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawRect(ox+MaxTime*cellx+20*fact,oy,MaxDepth*cellx,p*celly) ;
for(int i=0;i<MaxTime;i+=5)
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
for(int i=0;i<MaxTime;i+=5)
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4*fact,QString::number(i)) ;
p=0 ;
int great_total = 0 ;
p=0 ;
int great_total = 0 ;
for(it=hits.begin();it!=hits.end();++it,++p)
{
int total = 0 ;
for(it=hits.begin();it!=hits.end();++it,++p)
{
int total = 0 ;
for(int i=0;i<MaxTime;++i)
{
painter->fillRect(ox+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
total += it->second[i] ;
}
for(int i=0;i<MaxTime;++i)
{
painter->fillRect(ox+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
total += it->second[i] ;
}
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx,oy+(p+1)*celly,TurtleRouterStatistics::getPeerName(it->first)) ;
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly,"("+QString::number(total)+")") ;
great_total += total ;
}
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(ox+MaxDepth*cellx+30*fact+(MaxTime+1)*cellx,oy+(p+1)*celly,TurtleRouterStatistics::getPeerName(it->first)) ;
painter->drawText(ox+MaxDepth*cellx+30*fact+(MaxTime+1)*cellx+120*fact,oy+(p+1)*celly,"("+QString::number(total)+")") ;
great_total += total ;
}
painter->drawRect(ox,oy,MaxTime*cellx,p*celly) ;
painter->drawRect(ox,oy,MaxTime*cellx,p*celly) ;
for(int i=0;i<MaxTime;i+=5)
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
for(int i=0;i<MaxDepth;++i)
painter->drawText(ox+MaxTime*cellx+20+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
painter->setPen(QColor::fromRgb(255,130,80)) ;
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly+4,"("+QString::number(great_total)+")");
for(int i=0;i<MaxTime;i+=5)
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4*fact,QString::number(i)) ;
for(int i=0;i<MaxDepth;++i)
painter->drawText(ox+MaxTime*cellx+20*fact+i*cellx,oy+(p+1)*celly+4*fact,QString::number(i)) ;
painter->setPen(QColor::fromRgb(255,130,80)) ;
painter->drawText(ox+MaxDepth*cellx+30*fact+(MaxTime+1)*cellx+120*fact,oy+(p+1)*celly+4*fact,"("+QString::number(great_total)+")");
oy += (p+1)*celly+6 ;
oy += (p+1)*celly+6 ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(ox,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Age in seconds")+")");
painter->drawText(ox+MaxTime*cellx+20,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Depth")+")");
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawText(ox,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Age in seconds")+")");
painter->drawText(ox+MaxTime*cellx+20*fact,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Depth")+")");
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "total")+")");
painter->drawText(ox+MaxDepth*cellx+30*fact+(MaxTime+1)*cellx+120,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "total")+")");
oy += 3*celly ;
oy += 3*celly ;
// now, draw a scale
// now, draw a scale
int last_hts = -1 ;
int cellid = 0 ;
int last_hts = -1 ;
int cellid = 0 ;
for(int i=0;i<=10;++i)
{
int hts = (int)(max_bi*i/10.0) ;
for(int i=0;i<=10;++i)
{
int hts = (int)(max_bi*i/10.0) ;
if(hts > last_hts)
{
painter->fillRect(ox+cellid*(cellx+22),oy,cellx,celly,colorScale(i/10.0f)) ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawRect(ox+cellid*(cellx+22),oy,cellx,celly) ;
painter->drawText(ox+cellid*(cellx+22)+cellx+4,oy+celly,QString::number(hts)) ;
last_hts = hts ;
++cellid ;
}
}
if(hts > last_hts)
{
painter->fillRect(ox+cellid*(cellx+22*fact),oy,cellx,celly,colorScale(i/10.0f)) ;
painter->setPen(QColor::fromRgb(0,0,0)) ;
painter->drawRect(ox+cellid*(cellx+22*fact),oy,cellx,celly) ;
painter->drawText(ox+cellid*(cellx+22*fact)+cellx+4*fact,oy+celly,QString::number(hts)) ;
last_hts = hts ;
++cellid ;
}
}
oy += celly*2 ;
oy += celly*2 ;
ox = save_ox ;
ox = save_ox ;
}
private:
@ -275,9 +278,6 @@ void TurtleRouterStatisticsWidget::updateTunnelStatistics(const std::vector<std:
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
{
static const int cellx = 6 ;
static const int celly = 10+4 ;
QPixmap tmppixmap(maxWidth, maxHeight);
tmppixmap.fill(Qt::transparent);
setFixedHeight(maxHeight);
@ -285,19 +285,27 @@ void TurtleRouterStatisticsWidget::updateTunnelStatistics(const std::vector<std:
QPainter painter(&tmppixmap);
painter.initFrom(this);
maxHeight = 500 ;
// extracts the height of the fonts in pixels. This is used to callibrate the size of the objects to draw.
float fontHeight = QFontMetricsF(font()).height();
float fact = fontHeight/14.0;
maxHeight = 500*fact ;
int cellx = 6*fact ;
int celly = (10+4)*fact ;
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
// draw...
int ox=5,oy=5 ;
int ox=5*fact,oy=5*fact ;
TRHistogram(search_reqs_info).draw(&painter,ox,oy,tr("Search requests repartition") + ":") ;
TRHistogram(search_reqs_info).draw(&painter,ox,oy,tr("Search requests repartition") + ":",fontHeight) ;
painter.setPen(QColor::fromRgb(70,70,70)) ;
painter.drawLine(0,oy,maxWidth,oy) ;
oy += celly ;
TRHistogram(tunnel_reqs_info).draw(&painter,ox,oy,tr("Tunnel requests repartition") + ":") ;
TRHistogram(tunnel_reqs_info).draw(&painter,ox,oy,tr("Tunnel requests repartition") + ":",fontHeight) ;
// now give information about turtle traffic.
//