Graph Printing improvements

This commit is contained in:
Mark Watkins 2011-12-07 20:19:28 +10:00
parent 3bb7d13e38
commit eadb25fb7d
5 changed files with 89 additions and 44 deletions

View File

@ -1045,16 +1045,29 @@ void gGraph::paint(int originX, int originY, int width, int height)
*/ */
//glColor4f(0,0,0,1); //glColor4f(0,0,0,1);
renderText(title(),20*m_graphview->printScaleX(),originY+height/2,90,Qt::black,mediumfont); left=marginLeft(),right=marginRight(),top=marginTop(),bottom=marginBottom();
int x,y;
GetTextExtent(title(),x,y,mediumfont);
int title_x=(float(y)*2);
renderText(title(),marginLeft()+title_x,originY+height/2,90,Qt::black,mediumfont);
left+=title_x;
//#define DEBUG_LAYOUT
#ifdef DEBUG_LAYOUT
QColor col=Qt::red;
lines()->add(0,originY,0,originY+height,col);
lines()->add(left,originY,left,originY+height,col);
#endif
//renderText(title(),0,originY+height/2,90,Qt::black,mediumfont);
left=0,right=0,top=0,bottom=0;
int tmp; int tmp;
originX+=marginLeft(); //originX=0;//marginLeft()+title_x;
originY+=marginTop(); left=0;
width-=marginLeft()+marginRight(); //originY+=marginTop();
height-=marginTop()+marginBottom(); //width-=marginLeft()+marginRight();
//height-=marginTop()+marginBottom();
//int lsize=m_layers.size(); //int lsize=m_layers.size();
for (int i=0;i<m_layers.size();i++) { for (int i=0;i<m_layers.size();i++) {
@ -1070,14 +1083,20 @@ void gGraph::paint(int originX, int originY, int width, int height)
if (ll->position()==LayerLeft) { if (ll->position()==LayerLeft) {
ll->paint(*this,originX+left,originY+top,tmp,height-top-bottom); ll->paint(*this,originX+left,originY+top,tmp,height-top-bottom);
left+=tmp; left+=tmp;
#ifdef DEBUG_LAYOUT
lines()->add(originX+left-1,originY,originX+left-1,originY+height,col);
#endif
} }
if (ll->position()==LayerRight) { if (ll->position()==LayerRight) {
right+=tmp; right+=tmp;
ll->paint(*this,originX+width-right,originY+top,tmp,height-top-bottom); ll->paint(*this,originX+width-right,originY+top,tmp,height-top-bottom);
#ifdef DEBUG_LAYOUT
lines()->add(originX+width-right,originY,originX+width-right,originY+height,col);
#endif
} }
} }
bottom=0; top=0; bottom=marginBottom(); top=marginTop();
for (int i=0;i<m_layers.size();i++) { for (int i=0;i<m_layers.size();i++) {
Layer *ll=m_layers[i]; Layer *ll=m_layers[i];
tmp=ll->Height()*m_graphview->printScaleY(); tmp=ll->Height()*m_graphview->printScaleY();
@ -1618,7 +1637,7 @@ QPixmap gGraph::renderPixmap(int w, int h)
gGraphView *sg=mainwin->snapshotGraph(); gGraphView *sg=mainwin->snapshotGraph();
if (!sg) return QPixmap(); if (!sg) return QPixmap();
float scale=sg->printScaleX(); double scale=sg->printScaleY(); //sqrt(sg->printScaleX()*sg->printScaleX()+sg->printScaleY()*sg->printScaleY());
fa.setPointSize(fa.pointSize()*scale); fa.setPointSize(fa.pointSize()*scale);
fb.setPointSize(fb.pointSize()*scale); fb.setPointSize(fb.pointSize()*scale);
@ -2735,7 +2754,7 @@ int gGraphView::visibleGraphs()
{ {
int cnt=0; int cnt=0;
for (int i=0;i<m_graphs.size();i++) { for (int i=0;i<m_graphs.size();i++) {
if (!m_graphs[i]->isEmpty() && m_graphs[i]->visible()) cnt++; if (m_graphs[i]->visible() && !m_graphs[i]->isEmpty()) cnt++;
} }
return cnt; return cnt;
} }

View File

@ -155,9 +155,9 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
py=left+float(aligned_start-minx)*xmult; py=left+float(aligned_start-minx)*xmult;
int texttop=top+18*w.printScaleX(); int texttop=top+18*w.printScaleY();
int mintop=top+4*w.printScaleX(); int mintop=top+4*w.printScaleY();
int majtop=top+6*w.printScaleX(); int majtop=top+6*w.printScaleY();
for (int i=0;i<num_minor_ticks;i++) { for (int i=0;i<num_minor_ticks;i++) {
py-=step_pixels; py-=step_pixels;
if (py<start_px) continue; if (py<start_px) continue;

View File

@ -57,7 +57,7 @@ class gYAxis:public Layer
bool ShowMinorTicks() { return m_show_minor_ticks; } bool ShowMinorTicks() { return m_show_minor_ticks; }
bool ShowMajorTicks() { return m_show_major_ticks; } bool ShowMajorTicks() { return m_show_major_ticks; }
virtual const QString Format(EventDataType v, int dp); virtual const QString Format(EventDataType v, int dp);
static const int Margin=55; // Left margin space static const int Margin=60; // Left margin space
void SetScale(float f) { m_yaxis_scale=f; } // Scale yaxis ticker values (only what's displayed) void SetScale(float f) { m_yaxis_scale=f; } // Scale yaxis ticker values (only what's displayed)
float Scale() { return m_yaxis_scale; } float Scale() { return m_yaxis_scale; }

View File

@ -200,15 +200,15 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
bool square=PROFILE["SquareWavePlots"].toBool(); bool square=PROFILE["SquareWavePlots"].toBool();
PRD->AddLayer(AddCPAP(new gLineChart(CPAP_EPAP,Qt::blue,square))); PRD->AddLayer(AddCPAP(new gLineChart(CPAP_EPAP,Qt::blue,square)));
PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAPLo,Qt::red,square))); PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAPLo,Qt::darkRed,square)));
PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAP,Qt::yellow,square))); PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAP,Qt::red,square)));
PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAPHi,Qt::red,square))); PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAPHi,Qt::darkRed,square)));
PRD->AddLayer(AddCPAP(new gLineChart(CPAP_Pressure,QColor("dark green"),square))); PRD->AddLayer(AddCPAP(new gLineChart(CPAP_Pressure,QColor("dark green"),square)));
AHI->AddLayer(AddCPAP(new gLineChart(CPAP_AHI,QColor("light green"),square))); AHI->AddLayer(AddCPAP(new gLineChart(CPAP_AHI,QColor("light green"),square)));
//AHI->AddLayer(AddCPAP(new AHIChart(QColor("#37a24b")))); //AHI->AddLayer(AddCPAP(new AHIChart(QColor("#37a24b"))));
LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_LeakTotal,Qt::yellow,square))); LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_LeakTotal,Qt::darkYellow,square)));
LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_Leak,Qt::darkMagenta,square))); LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_Leak,Qt::darkMagenta,square)));
LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_MaxLeak,Qt::darkRed,square))); LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_MaxLeak,Qt::darkRed,square)));
SNORE->AddLayer(AddCPAP(new gLineChart(CPAP_Snore,Qt::darkGray,true))); SNORE->AddLayer(AddCPAP(new gLineChart(CPAP_Snore,Qt::darkGray,true)));

View File

@ -678,10 +678,13 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QPrinter * zprinter; QPrinter * zprinter;
bool highres;
if (PROFILE.ExistsAndTrue("HighResPrinting")) { if (PROFILE.ExistsAndTrue("HighResPrinting")) {
zprinter=new QPrinter(QPrinter::HighResolution); zprinter=new QPrinter(QPrinter::HighResolution);
highres=true;
} else { } else {
zprinter=new QPrinter(QPrinter::ScreenResolution); zprinter=new QPrinter(QPrinter::ScreenResolution);
highres=false;
} }
QPrinter & printer=*zprinter;; QPrinter & printer=*zprinter;;
@ -712,22 +715,39 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
qDebug() << "Printer Resolution is" << res.width() << "x" << res.height(); qDebug() << "Printer Resolution is" << res.width() << "x" << res.height();
const int graphs_per_page=5; const int graphs_per_page=5;
const int footer_height=(res.height()/22); const int footer_height=(res.height()/21);
float gw=res.width();
float gh=(res.height()-footer_height)/graphs_per_page;
float gw2=gv->width();
//float gh2=gv->totalHeight();
float xscale=gw / gw2;
float yscale=gh / PROFILE["GraphHeight"].toDouble();
float div=1;
if (gh>500)
div=4;
//yscale=xscale;
SnapshotGraph->setPrintScaleX(xscale/div);
SnapshotGraph->setPrintScaleY(yscale/div);
mainwin->snapshotGraph()->setMinimumSize(gw/div,gh/div); float pw=res.width();
mainwin->snapshotGraph()->setMaximumSize(gw/div,gh/div); float realheight=res.height()-footer_height;
float ph=realheight / graphs_per_page;
float div=highres ? 4.0 : 1.0;
float fontdiv=highres ? 2.3 : 0.75;
float gw=pw/div;
float gh=ph/div;
SnapshotGraph->setPrintScaleX(fontdiv);
SnapshotGraph->setPrintScaleY(fontdiv);
/*float sw=1280; //highres ? 1280 : gv->width();
float gheight=350; //PROFILE["GraphHeight"].toDouble()*2;
float gz=gheight / sw; // aspect ratio
float gw=pw; //highres ? 1280 : gv->width();
float gh=pw * gz;
float rh=gh*div;
float rw=gw*div;
float xscale=pw / sw;
float yscale=gh / gheight;
SnapshotGraph->setPrintScaleX(xscale);
SnapshotGraph->setPrintScaleY(yscale); */
mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh);
int page=1; int page=1;
int pages=ceil(float(visgraphs+1)/float(graphs_per_page)); int pages=ceil(float(visgraphs+1)/float(graphs_per_page));
@ -742,7 +762,7 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
//int header_height=200; //int header_height=200;
QString title=name+" Report"; QString title=name+" Report";
QTextOption t_op(Qt::AlignCenter); //QTextOption t_op(Qt::AlignCenter);
painter.setFont(*bigfont); painter.setFont(*bigfont);
QRectF bounds=painter.boundingRect(QRectF(0,0,res.width(),0),title,QTextOption(Qt::AlignCenter)); QRectF bounds=painter.boundingRect(QRectF(0,0,res.width(),0),title,QTextOption(Qt::AlignCenter));
painter.drawText(bounds,title,QTextOption(Qt::AlignCenter)); painter.drawText(bounds,title,QTextOption(Qt::AlignCenter));
@ -804,18 +824,18 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
stats+="LKI\t"+QString::number(lki,'f',2)+"\n"; stats+="LKI\t"+QString::number(lki,'f',2)+"\n";
stats+="EPI\t"+QString::number(exp,'f',2)+"\n"; stats+="EPI\t"+QString::number(exp,'f',2)+"\n";
} }
QRectF bounds=painter.boundingRect(QRectF(res.width()-(250*xscale),top,250*xscale,0),stats,QTextOption(Qt::AlignRight)); QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),stats,QTextOption(Qt::AlignRight));
painter.drawText(bounds,stats,QTextOption(Qt::AlignRight)); painter.drawText(bounds,stats,QTextOption(Qt::AlignRight));
if (bounds.height()>maxy) maxy=bounds.height(); if (bounds.height()>maxy) maxy=bounds.height();
} }
QRectF bounds=painter.boundingRect(QRectF((res.width()/2)-(res.width()/6),top,res.width()-(250*xscale),0),cpapinfo,QTextOption(Qt::AlignLeft)); QRectF bounds=painter.boundingRect(QRectF((res.width()/2)-(res.width()/6),top,res.width()/2,0),cpapinfo,QTextOption(Qt::AlignLeft));
painter.drawText(bounds,cpapinfo,QTextOption(Qt::AlignLeft)); painter.drawText(bounds,cpapinfo,QTextOption(Qt::AlignLeft));
if (bounds.height()>maxy) maxy=bounds.height(); if (bounds.height()>maxy) maxy=bounds.height();
} else if (name=="Overview") { } else if (name=="Overview") {
QDateTime first=QDateTime::fromTime_t((*gv)[0]->min_x/1000L); QDateTime first=QDateTime::fromTime_t((*gv)[0]->min_x/1000L);
QDateTime last=QDateTime::fromTime_t((*gv)[0]->max_x/1000L); QDateTime last=QDateTime::fromTime_t((*gv)[0]->max_x/1000L);
QString ovinfo="Reporting from "+first.date().toString(Qt::SystemLocaleShortDate)+" to "+last.date().toString(Qt::SystemLocaleShortDate); QString ovinfo="Reporting from "+first.date().toString(Qt::SystemLocaleShortDate)+" to "+last.date().toString(Qt::SystemLocaleShortDate);
QRectF bounds=painter.boundingRect(QRectF(250*xscale,top,res.width()-(250*xscale),0),ovinfo,QTextOption(Qt::AlignLeft)); QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),ovinfo,QTextOption(Qt::AlignCenter));
painter.drawText(bounds,ovinfo,QTextOption(Qt::AlignLeft)); painter.drawText(bounds,ovinfo,QTextOption(Qt::AlignLeft));
if (bounds.height()>maxy) maxy=bounds.height(); if (bounds.height()>maxy) maxy=bounds.height();
@ -830,24 +850,24 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
if (first) { if (first) {
QString footer="SleepyHead v"+PREF["VersionString"].toString()+" - http://sleepyhead.sourceforge.net"; QString footer="SleepyHead v"+PREF["VersionString"].toString()+" - http://sleepyhead.sourceforge.net";
QRectF bounds=painter.boundingRect(QRectF(0,res.height()-footer_height,res.width(),footer_height),footer,QTextOption(Qt::AlignHCenter)); QRectF bounds=painter.boundingRect(QRectF(0,res.height(),res.width(),footer_height),footer,QTextOption(Qt::AlignHCenter));
//bounds.moveTop(20);
painter.drawText(bounds,footer,QTextOption(Qt::AlignHCenter)); painter.drawText(bounds,footer,QTextOption(Qt::AlignHCenter));
QString pagestr="Page "+QString::number(page)+" of "+QString::number(pages); QString pagestr="Page "+QString::number(page)+" of "+QString::number(pages);
QRectF pagebnds=painter.boundingRect(QRectF(0,res.height()-footer_height,res.width(),footer_height),pagestr,QTextOption(Qt::AlignRight)); QRectF pagebnds=painter.boundingRect(QRectF(0,res.height(),res.width(),footer_height),pagestr,QTextOption(Qt::AlignRight));
painter.drawText(pagebnds,pagestr,QTextOption(Qt::AlignRight)); painter.drawText(pagebnds,pagestr,QTextOption(Qt::AlignRight));
first=false; first=false;
} }
gGraph *g=(*gv)[i]; gGraph *g=(*gv)[i];
if (g->title()=="Minute Vent.") {
int i=0;
}
if (g->isEmpty()) continue; if (g->isEmpty()) continue;
if (!g->visible()) continue; if (!g->visible()) continue;
g->deselect(); g->deselect();
QPixmap pm=g->renderPixmap(gw/div,gh/div);
QPixmap pm2=pm.scaledToWidth(res.width()); if (top+ph>realheight) { //top+pm.height()>res.height()) {
painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2);
top+=gh;
gcnt++;
if ((gcnt>=graphs_per_page) || (top+gh>(res.height()-footer_height))) { //top+pm.height()>res.height()) {
top=0; top=0;
gcnt=0; gcnt=0;
//header_height=0; //header_height=0;
@ -859,6 +879,12 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
break; break;
} }
} }
QPixmap pm=g->renderPixmap(gw,gh);
QPixmap pm2=pm.scaledToWidth(pw);
painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2);
top+=pm2.height();
gcnt++;
if (qprogress) { if (qprogress) {
qprogress->setValue(i); qprogress->setValue(i);
QApplication::processEvents(); QApplication::processEvents();