More Report cleanup work

This commit is contained in:
Mark Watkins 2011-12-13 00:06:08 +10:00
parent 83b64776e9
commit eb83731a3e
2 changed files with 94 additions and 90 deletions

View File

@ -1083,6 +1083,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
int fw,font_height; int fw,font_height;
GetTextExtent("Wg@",fw,font_height); GetTextExtent("Wg@",fw,font_height);
m_margintop=font_height+(8*printScaleY()); m_margintop=font_height+(8*printScaleY());
m_marginbottom=5;
//glColor4f(0,0,0,1); //glColor4f(0,0,0,1);
left=marginLeft(),right=marginRight(),top=marginTop(),bottom=marginBottom(); left=marginLeft(),right=marginRight(),top=marginTop(),bottom=marginBottom();
@ -1671,26 +1672,19 @@ short gGraph::marginBottom() { return m_marginbottom; } //*m_graphview->printSca
QPixmap gGraph::renderPixmap(int w, int h) QPixmap gGraph::renderPixmap(int w, int h)
{ {
QFont * _defaultfont=defaultfont;
QFont * _mediumfont=mediumfont;
QFont * _bigfont=bigfont;
QFont fa=*defaultfont;
QFont fb=*mediumfont;
QFont fc=*bigfont;
gGraphView *sg=mainwin->snapshotGraph(); gGraphView *sg=mainwin->snapshotGraph();
if (!sg) return QPixmap(); if (!sg) return QPixmap();
double scale=sg->printScaleY(); //sqrt(sg->printScaleX()*sg->printScaleX()+sg->printScaleY()*sg->printScaleY()); 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);
fc.setPointSize(fc.pointSize()*scale); fc.setPointSize(fc.pointSize()*scale);
defaultfont=&fa; defaultfont=&fa;
mediumfont=&fb; mediumfont=&fb;
bigfont=&fc; bigfont=&fc; */
sg->hideSplitter(); sg->hideSplitter();
gGraphView *tgv=m_graphview; gGraphView *tgv=m_graphview;
@ -1706,16 +1700,19 @@ QPixmap gGraph::renderPixmap(int w, int h)
//sg->SetXBounds(mx,Mx); //sg->SetXBounds(mx,Mx);
//sg->updateScrollBar(); //sg->updateScrollBar();
sg->updateScale(); sg->updateScale();
//QImage image=sg->grabFrameBuffer();
//QPixmap pm=QPixmap::fromImage(image);
QPixmap pm=sg->renderPixmap(w,h,false); QPixmap pm=sg->renderPixmap(w,h,false);
sg->trashGraphs(); sg->trashGraphs();
m_graphview=tgv; m_graphview=tgv;
m_height=tmp; m_height=tmp;
/*
defaultfont=_defaultfont; defaultfont=_defaultfont;
mediumfont=_mediumfont; mediumfont=_mediumfont;
bigfont=_bigfont; bigfont=_bigfont; */
return pm; return pm;
} }

View File

@ -21,6 +21,7 @@
#include <QPrintDialog> #include <QPrintDialog>
#include <QPainter> #include <QPainter>
#include <QProcess> #include <QProcess>
#include <QFontMetrics>
#include <cmath> #include <cmath>
#include "mainwindow.h" #include "mainwindow.h"
@ -751,70 +752,53 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QPainter painter; QPainter painter;
painter.begin(printer); painter.begin(printer);
QSizeF pres=printer->paperSize(QPrinter::Point);
QSizeF pxres=printer->paperSize(QPrinter::DevicePixel);
//float hscale=pxres.width()/pres.width();
float vscale=pxres.height()/pres.height();
QFontMetrics fm(*bigfont);
float title_height=fm.ascent()*vscale;
QFontMetrics fm2(*defaultfont);
float normal_height=fm2.ascent()*vscale;
//QRect screen=QApplication::desktop()->screenGeometry();
QRect res=printer->pageRect(); QRect res=printer->pageRect();
qDebug() << "Printer Resolution is" << res.width() << "x" << res.height(); qDebug() << "Printer Resolution is" << res.width() << "x" << res.height();
qDebug() << "res:" << printer->resolution() << "dpi";
float printer_width=res.width();
float printer_height=res.height()-normal_height;
const int graphs_per_page=6; const int graphs_per_page=6;
float full_graph_height=(printer_height-(normal_height*graphs_per_page)) / float(graphs_per_page);
float pw=res.width(); GLint gw;
QRectF pagebnds=painter.boundingRect(QRectF(0,0,res.width(),0),"Wg",QTextOption(Qt::AlignCenter)); glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE,&gw);
const int labelheight=pagebnds.height()*1.33;
const int footer_height=labelheight;
float realheight=res.height()-footer_height; bool no_scaling;
float ph=(realheight-(labelheight*graphs_per_page)) / graphs_per_page; if (printer_width<=gw) {
gw=printer_width;
no_scaling=true;
} else no_scaling=false;
float div,fontscale; float graph_xscale=gw / printer_width;
if (pw>8000) { //float scalex=1.0/graph_xscale;
div=4; float gh=full_graph_height*graph_xscale;
#if defined(Q_WS_WIN32)
fontscale=2.3;
#elif defined(Q_WS_MAC)
fontscale=3;
#else
fontscale=2.3;
#endif
} else if (pw>2000) {
div=2.0;
#if defined(Q_WS_MAC)
fontscale=3;
#else
fontscale=2.0;
#endif
} else {
div=1;
#if defined(Q_WS_WIN32)
fontscale=1; // windows will crash if it's any smaller than this
#else
fontscale=0.75;
#endif
}
float gw=pw/div;
float gh=ph/div;
SnapshotGraph->setPrintScaleX(fontscale);
SnapshotGraph->setPrintScaleY(fontscale);
mainwin->snapshotGraph()->setMinimumSize(gw,gh); mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh); mainwin->snapshotGraph()->setMaximumSize(gw,gh);
int page=1;
int i=0;
int top=0;
int gcnt=0;
//int header_height=200;
QString title=name+" Report"; QString title=name+" Report";
//QTextOption t_op(Qt::AlignCenter);
painter.setFont(*bigfont); painter.setFont(*bigfont);
QRectF bounds=painter.boundingRect(QRectF(0,0,res.width(),0),title,QTextOption(Qt::AlignHCenter | Qt::AlignTop)); int top=0;
QRectF bounds(0,top,printer_width,title_height);
painter.drawText(bounds,title,QTextOption(Qt::AlignHCenter | Qt::AlignTop)); painter.drawText(bounds,title,QTextOption(Qt::AlignHCenter | Qt::AlignTop));
top+=bounds.height();
painter.setFont(*defaultfont); painter.setFont(*defaultfont);
top=bounds.height();
//top+=15*yscale; //spacer
int maxy=0; int maxy=0;
if (!PROFILE["FirstName"].toString().isEmpty()) { if (!PROFILE["FirstName"].toString().isEmpty()) {
QString userinfo="Name:\t"+PROFILE["LastName"].toString()+", "+PROFILE["FirstName"].toString()+"\n"; QString userinfo="Name:\t"+PROFILE["LastName"].toString()+", "+PROFILE["FirstName"].toString()+"\n";
@ -822,8 +806,8 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
userinfo+="Phone:\t"+PROFILE["Phone"].toString()+"\n"; userinfo+="Phone:\t"+PROFILE["Phone"].toString()+"\n";
userinfo+="Email:\t"+PROFILE["EmailAddress"].toString()+"\n"; userinfo+="Email:\t"+PROFILE["EmailAddress"].toString()+"\n";
if (!PROFILE["Address"].toString().isEmpty()) userinfo+="\nAddress:\n"+PROFILE["Address"].toString()+"\n"; if (!PROFILE["Address"].toString().isEmpty()) userinfo+="\nAddress:\n"+PROFILE["Address"].toString()+"\n";
QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),userinfo,QTextOption(Qt::AlignLeft)); QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),userinfo,QTextOption(Qt::AlignLeft | Qt::AlignTop));
painter.drawText(bounds,userinfo,QTextOption(Qt::AlignLeft)); painter.drawText(bounds,userinfo,QTextOption(Qt::AlignLeft | Qt::AlignTop));
if (bounds.height()>maxy) maxy=bounds.height(); if (bounds.height()>maxy) maxy=bounds.height();
} }
if (name=="Daily") { if (name=="Daily") {
@ -848,9 +832,12 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
CPAPMode mode=(CPAPMode)cpap->settings_max(CPAP_Mode); CPAPMode mode=(CPAPMode)cpap->settings_max(CPAP_Mode);
cpapinfo+="\nMode: "; cpapinfo+="\nMode: ";
if (mode==MODE_CPAP) cpapinfo+="CPAP"; EventDataType min=cpap->settings_min(CPAP_PressureMin);
else if (mode==MODE_APAP) cpapinfo+="Auto-PAP"; EventDataType max=cpap->settings_max(CPAP_PressureMax);
else if (mode==MODE_BIPAP) cpapinfo+="Bi-Level";
if (mode==MODE_CPAP) cpapinfo+="CPAP "+QString::number(min)+"cmH2O";
else if (mode==MODE_APAP) cpapinfo+="APAP "+QString::number(min)+"-"+QString::number(max)+"cmH2O";
else if (mode==MODE_BIPAP) cpapinfo+="Bi-Level"+QString::number(min)+"-"+QString::number(max)+"cmH2O";
else if (mode==MODE_ASV) cpapinfo+="ASV"; else if (mode==MODE_ASV) cpapinfo+="ASV";
float ahi=(cpap->count(CPAP_Obstructive)+cpap->count(CPAP_Hypopnea)+cpap->count(CPAP_ClearAirway)+cpap->count(CPAP_Apnea))/cpap->hours(); float ahi=(cpap->count(CPAP_Obstructive)+cpap->count(CPAP_Hypopnea)+cpap->count(CPAP_ClearAirway)+cpap->count(CPAP_Apnea))/cpap->hours();
@ -897,18 +884,15 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),ovinfo,QTextOption(Qt::AlignCenter)); QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),ovinfo,QTextOption(Qt::AlignCenter));
painter.drawText(bounds,ovinfo,QTextOption(Qt::AlignCenter)); painter.drawText(bounds,ovinfo,QTextOption(Qt::AlignCenter));
if (bounds.height()>maxy) maxy=bounds.height();
} else if (name=="Oximetry") {
QString ovinfo="Reporting data goes here";
QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),ovinfo,QTextOption(Qt::AlignCenter));
painter.drawText(bounds,ovinfo,QTextOption(Qt::AlignCenter));
if (bounds.height()>maxy) maxy=bounds.height(); if (bounds.height()>maxy) maxy=bounds.height();
} }
top+=maxy; top+=maxy;
/*if (name=="Daily") {
QString text=getDaily()->GetDetailsText();
QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),text,QTextOption(Qt::AlignLeft));
painter.drawText(bounds,text,QTextOption(Qt::AlignLeft));
top+=bounds.height();
}*/
// top+=15*yscale; //spacer
//top=header_height;
bool first=true; bool first=true;
QStringList labels; QStringList labels;
@ -928,19 +912,16 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
graphs.push_back(g); graphs.push_back(g);
labels.push_back("Current Selection"); labels.push_back("Current Selection");
if (journal) { if (journal) {
if (journal->settings.contains("BookmarkStart")) { if (journal->settings.contains("BookmarkStart")) {
QVariantList st1=journal->settings["BookmarkStart"].toList(); QVariantList st1=journal->settings["BookmarkStart"].toList();
QVariantList et1=journal->settings["BookmarkEnd"].toList(); QVariantList et1=journal->settings["BookmarkEnd"].toList();
QStringList notes=journal->settings["BookmarkNotes"].toStringList(); QStringList notes=journal->settings["BookmarkNotes"].toStringList();
for (int i=0;i<notes.size();i++) { for (int i=0;i<notes.size();i++) {
labels.push_back(notes.at(i)); labels.push_back(notes.at(i));
start.push_back(st1.at(i).toLongLong()); start.push_back(st1.at(i).toLongLong());
end.push_back(et1.at(i).toLongLong()); end.push_back(et1.at(i).toLongLong());
graphs.push_back(g); graphs.push_back(g);
} }
} }
} }
} }
@ -959,18 +940,17 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
qprogress->show(); qprogress->show();
} }
i=0; int page=1;
do { int gcnt=0;
//+" on "+d.toString(Qt::SystemLocaleLongDate) for (int i=0;i<graphs.size();i++) {
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(),res.width(),footer_height),footer,QTextOption(Qt::AlignHCenter)); QRectF bounds=painter.boundingRect(QRectF(0,res.height(),res.width(),normal_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(),res.width(),footer_height),pagestr,QTextOption(Qt::AlignRight)); QRectF pagebnds=painter.boundingRect(QRectF(0,res.height(),res.width(),normal_height),pagestr,QTextOption(Qt::AlignRight));
painter.drawText(pagebnds,pagestr,QTextOption(Qt::AlignRight)); painter.drawText(pagebnds,pagestr,QTextOption(Qt::AlignRight));
first=false; first=false;
} }
@ -978,12 +958,11 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
g->SetXBounds(start[i],end[i]); g->SetXBounds(start[i],end[i]);
g->deselect(); g->deselect();
if ((top+ph+labelheight) > realheight) { //top+pm.height()>res.height()) { if ((top+full_graph_height+normal_height) > printer_height) {
top=0; top=0;
gcnt=0; gcnt=0;
//header_height=0;
page++; page++;
if (page>pages) break; if (page > pages) break;
first=true; first=true;
if (!printer->newPage()) { if (!printer->newPage()) {
qWarning("failed in flushing page to disk, disk full?"); qWarning("failed in flushing page to disk, disk full?");
@ -994,18 +973,46 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QString label=labels[i]; QString label=labels[i];
if (!label.isEmpty()) { if (!label.isEmpty()) {
label+=":"; label+=":";
QRectF pagebnds=QRectF(0,top,res.width(),labelheight); QRectF pagebnds=QRectF(0,top,res.width(),normal_height);
painter.drawText(pagebnds,label,QTextOption(Qt::AlignHCenter | Qt::AlignTop)); painter.drawText(pagebnds,label,QTextOption(Qt::AlignHCenter | Qt::AlignTop));
top+=labelheight; //pagebnds.height(); top+=normal_height;
} else top+=labelheight/2; } else top+=normal_height/2;
PROFILE["UseAntiAliasing"]=force_antialiasing; PROFILE["UseAntiAliasing"]=force_antialiasing;
int tmb=g->m_marginbottom; int tmb=g->m_marginbottom;
g->m_marginbottom=0; g->m_marginbottom=0;
if (!no_scaling ) {
SnapshotGraph->setPrintScaleX(1.5);
SnapshotGraph->setPrintScaleY(1.5);
}
QFont * _defaultfont=defaultfont;
QFont * _mediumfont=mediumfont;
QFont * _bigfont=bigfont;
QFont fa=*defaultfont;
QFont fb=*mediumfont;
QFont fc=*bigfont;
if (!no_scaling ) {
fa.setPointSizeF(fa.pointSizeF()*1.7);
fb.setPointSizeF(fb.pointSizeF()*1.7);
fc.setPointSizeF(fc.pointSizeF()*1.7);
}
defaultfont=&fa;
mediumfont=&fb;
bigfont=&fc;
QPixmap pm=g->renderPixmap(gw,gh); QPixmap pm=g->renderPixmap(gw,gh);
defaultfont=_defaultfont;
mediumfont=_mediumfont;
bigfont=_bigfont;
g->m_marginbottom=tmb; g->m_marginbottom=tmb;
PROFILE["UseAntiAliasing"]=aa_setting; PROFILE["UseAntiAliasing"]=aa_setting;
QPixmap pm2=pm.scaledToWidth(pw); QPixmap pm2=pm.scaledToWidth(printer_width);
painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2); painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2);
top+=pm2.height(); top+=pm2.height();
@ -1014,7 +1021,7 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
qprogress->setValue(i); qprogress->setValue(i);
QApplication::processEvents(); QApplication::processEvents();
} }
} while (++i<graphs.size()); }
qprogress->hide(); qprogress->hide();
painter.end(); painter.end();