Fix font scaling issue

This commit is contained in:
Mark Watkins 2011-12-13 02:32:10 +10:00
parent 6e07522dbe
commit 42fcd0a389
6 changed files with 114 additions and 85 deletions

View File

@ -953,6 +953,7 @@ gGraph::gGraph(gGraphView *graphview,QString title,QString units, int height,sho
f_miny=f_maxy=0; f_miny=f_maxy=0;
m_enforceMinY=m_enforceMaxY=false; m_enforceMinY=m_enforceMaxY=false;
rec_miny=rec_maxy=0; rec_miny=rec_maxy=0;
m_showTitle=true;
} }
gGraph::~gGraph() gGraph::~gGraph()
{ {
@ -996,6 +997,12 @@ bool gGraph::isEmpty()
} }
return empty; return empty;
} }
void gGraph::showTitle(bool b)
{
m_showTitle=b;
}
float gGraph::printScaleX() { return m_graphview->printScaleX(); } float gGraph::printScaleX() { return m_graphview->printScaleX(); }
float gGraph::printScaleY() { return m_graphview->printScaleY(); } float gGraph::printScaleY() { return m_graphview->printScaleY(); }
@ -1017,43 +1024,6 @@ void gGraph::setDay(Day * day)
ResetBounds(); ResetBounds();
} }
/*void gGraph::invalidate()
{ // this may not be necessary, as scrollbar & resize issues a full redraw..
//m_lastbounds.setWidth(m_graphview->width());
m_lastbounds.setY(m_graphview->findTop(this));
m_lastbounds.setX(gGraphView::titleWidth);
m_lastbounds.setHeight(m_height * m_graphview->scaleY());
m_lastbounds.setWidth(m_graphview->width()-gGraphView::titleWidth);
int i=0;
//m_lastbounds.setHeight(0);
}
void gGraph::repaint()
{
if (m_lastbounds.height()>0) {
//glScissor(0,m_lastbounds.y(),m_lastbounds.width(),m_lastbounds.height());
// m_graphview->swapBuffers(); // how fast is this??
//glEnable(GL_SCISSOR_BOX);
glBegin(GL_QUADS);
glColor4f(1,1,1,1.0); // Gradient End
glVertex2i(0,m_lastbounds.y());
glVertex2i(gGraphView::titleWidth,m_lastbounds.y());
glVertex2i(gGraphView::titleWidth,m_lastbounds.y()+height());
glVertex2i(0,m_lastbounds.y()+height());
glEnd();
paint(m_lastbounds.x(),m_lastbounds.y(),m_lastbounds.width(),m_lastbounds.height());
m_graphview->swapBuffers();
//glDisable(GL_SCISSOR_BOX);
} else {
qDebug() << "Wanted to redraw graph" << m_title << "but previous bounds were invalid.. Issuing a slower full redraw instead. Todo: Find out why.";
m_graphview->updateGL();
}
}
*/
void gGraph::qglColor(QColor col) void gGraph::qglColor(QColor col)
{ {
m_graphview->qglColor(col); m_graphview->qglColor(col);
@ -1087,11 +1057,13 @@ void gGraph::paint(int originX, int originY, int width, int height)
//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();
int x,y; int x=0,y=0;
GetTextExtent(title(),x,y,mediumfont); if (m_showTitle) {
int title_x=(float(y)*2); GetTextExtent(title(),x,y,mediumfont);
renderText(title(),marginLeft()+title_x,originY+height/2,90,Qt::black,mediumfont); int title_x=(float(y)*2);
left+=title_x; renderText(title(),marginLeft()+title_x,originY+height/2,90,Qt::black,mediumfont);
left+=title_x;
} else left=0;
//#define DEBUG_LAYOUT //#define DEBUG_LAYOUT
#ifdef DEBUG_LAYOUT #ifdef DEBUG_LAYOUT
@ -1113,6 +1085,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
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];
if (!ll->visible()) continue;
tmp=ll->Height()*m_graphview->printScaleY(); tmp=ll->Height()*m_graphview->printScaleY();
if (ll->position()==LayerTop) top+=tmp; if (ll->position()==LayerTop) top+=tmp;
if (ll->position()==LayerBottom) bottom+=tmp; if (ll->position()==LayerBottom) bottom+=tmp;
@ -1120,6 +1093,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
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];
if (!ll->visible()) continue;
tmp=ll->Width()*m_graphview->printScaleX(); tmp=ll->Width()*m_graphview->printScaleX();
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);
@ -1140,6 +1114,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
bottom=marginBottom(); top=marginTop(); 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];
if (!ll->visible()) continue;
tmp=ll->Height()*m_graphview->printScaleY(); tmp=ll->Height()*m_graphview->printScaleY();
if (ll->position()==LayerTop) { if (ll->position()==LayerTop) {
ll->paint(*this,originX+left,originY+top,width-left-right,tmp); ll->paint(*this,originX+left,originY+top,width-left-right,tmp);
@ -1153,6 +1128,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
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];
if (!ll->visible()) continue;
if (ll->position()==LayerCenter) { if (ll->position()==LayerCenter) {
ll->paint(*this,originX+left,originY+top,width-left-right,height-top-bottom); ll->paint(*this,originX+left,originY+top,width-left-right,height-top-bottom);
} }

View File

@ -291,6 +291,8 @@ public:
int maxHeight() { return m_max_height; } int maxHeight() { return m_max_height; }
void setMaxHeight(int height) { m_max_height=height; } void setMaxHeight(int height) { m_max_height=height; }
void showTitle(bool b);
float printScaleX(); float printScaleX();
float printScaleY(); float printScaleY();
bool isEmpty(); bool isEmpty();
@ -399,6 +401,7 @@ protected:
Day * m_day; Day * m_day;
GLBuffer * m_quad; GLBuffer * m_quad;
bool m_enforceMinY,m_enforceMaxY; bool m_enforceMinY,m_enforceMaxY;
bool m_showTitle;
signals: signals:
protected slots: protected slots:

View File

@ -494,11 +494,10 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
int x,y; int x,y;
for (int j=0;j<m_codes.size();j++) { for (int j=0;j<m_codes.size();j++) {
//if (totalcounts[j]==0) continue;
if (!m_goodcodes[j]) continue; if (!m_goodcodes[j]) continue;
ChannelID code=m_codes[j]; ChannelID code=m_codes[j];
a=schema::channel[code].label(); a="";
a+=" "; a+=schema::channel[code].label()+" ";
switch(m_type[j]) { switch(m_type[j]) {
case ST_WAVG: a+="Avg"; break; case ST_WAVG: a+="Avg"; break;
case ST_AVG: a+="Avg"; break; case ST_AVG: a+="Avg"; break;
@ -531,9 +530,10 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
} }
a+="="+val; a+="="+val;
GetTextExtent(a,x,y); GetTextExtent(a,x,y);
px-=20+x; float wt=20*w.printScaleX();
w.renderText(a,px+20,py+1); px-=wt+x;
quads->add(px+5,py-7,px+18,py-7,px+18,py+1,px+5,py+1,m_colors[j]); w.renderText(a,px+wt,py+1);
quads->add(px+wt-y/4-y,py-y,px+wt-y/4,py-y,px+wt-y/4,py+1,px+wt-y/4-y,py+1,m_colors[j]);
//lines->add(px,py,px+20,py,m_colors[j]); //lines->add(px,py,px+20,py,m_colors[j]);
//lines->add(px,py+1,px+20,py+1,m_colors[j]); //lines->add(px,py+1,px+20,py+1,m_colors[j]);
} }

View File

@ -49,7 +49,7 @@ public:
void UnitsChanged(); void UnitsChanged();
Session * GetJournalSession(QDate date); Session * GetJournalSession(QDate date);
QString GetDetailsText(); QString GetDetailsText();
gGraph * eventBreakdownPie() { return GAHI; }
private slots: private slots:
void on_calendar_currentPageChanged(int year, int month); void on_calendar_currentPageChanged(int year, int month);

View File

@ -711,12 +711,12 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
bool highres; bool highres;
bool aa_setting=PROFILE.ExistsAndTrue("UseAntiAliasing"); bool aa_setting=PROFILE.ExistsAndTrue("UseAntiAliasing");
#ifdef Q_WS_MAC /*#ifdef Q_WS_MAC
PROFILE["HighResPrinting"]=true; // forced on PROFILE["HighResPrinting"]=true; // forced on
bool force_antialiasing=true; bool force_antialiasing=true;
#else #else */
bool force_antialiasing=PROFILE.ExistsAndTrue("UseAntiAliasing"); bool force_antialiasing=PROFILE.ExistsAndTrue("UseAntiAliasing");
#endif //#endif
if (PROFILE.ExistsAndTrue("HighResPrinting")) { if (PROFILE.ExistsAndTrue("HighResPrinting")) {
printer=new QPrinter(QPrinter::HighResolution); printer=new QPrinter(QPrinter::HighResolution);
@ -754,7 +754,7 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QSizeF pres=printer->paperSize(QPrinter::Point); QSizeF pres=printer->paperSize(QPrinter::Point);
QSizeF pxres=printer->paperSize(QPrinter::DevicePixel); QSizeF pxres=printer->paperSize(QPrinter::DevicePixel);
//float hscale=pxres.width()/pres.width(); float hscale=pxres.width()/pres.width();
float vscale=pxres.height()/pres.height(); float vscale=pxres.height()/pres.height();
QFontMetrics fm(*bigfont); QFontMetrics fm(*bigfont);
@ -765,6 +765,8 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
//QRect screen=QApplication::desktop()->screenGeometry(); //QRect screen=QApplication::desktop()->screenGeometry();
QRect res=printer->pageRect(); QRect res=printer->pageRect();
qDebug() << "X" << printer->logicalDpiX() << printer->physicalDpiX();
qDebug() << "Y" << printer->logicalDpiY() << printer->physicalDpiY();
qDebug() << "Printer Resolution is" << res.width() << "x" << res.height(); qDebug() << "Printer Resolution is" << res.width() << "x" << res.height();
qDebug() << "res:" << printer->resolution() << "dpi" << float(res.width()) / float(res.height()); qDebug() << "res:" << printer->resolution() << "dpi" << float(res.width()) / float(res.height());
@ -788,9 +790,6 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
//float scalex=1.0/graph_xscale; //float scalex=1.0/graph_xscale;
float gh=full_graph_height*graph_xscale; float gh=full_graph_height*graph_xscale;
mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh);
QString title=name+" Report"; QString title=name+" Report";
painter.setFont(*bigfont); painter.setFont(*bigfont);
int top=0; int top=0;
@ -798,6 +797,7 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
painter.drawText(bounds,title,QTextOption(Qt::AlignHCenter | Qt::AlignTop)); painter.drawText(bounds,title,QTextOption(Qt::AlignHCenter | Qt::AlignTop));
top+=bounds.height(); top+=bounds.height();
painter.setFont(*defaultfont); painter.setFont(*defaultfont);
float font_scale=float(printer->physicalDpiX())/float(QApplication::desktop()->physicalDpiX());
int maxy=0; int maxy=0;
if (!PROFILE["FirstName"].toString().isEmpty()) { if (!PROFILE["FirstName"].toString().isEmpty()) {
@ -853,26 +853,70 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
float lki=cpap->count(CPAP_LeakFlag)/cpap->hours(); float lki=cpap->count(CPAP_LeakFlag)/cpap->hours();
float exp=cpap->count(CPAP_ExP)/cpap->hours(); float exp=cpap->count(CPAP_ExP)/cpap->hours();
QString stats; getDaily()->eventBreakdownPie()->showTitle(false);
stats="AHI\t"+QString::number(ahi,'f',2)+"\n"; int piesize=1.5*72.0*vscale;
stats+="AI \t"+QString::number(oai,'f',2)+"\n"; mainwin->snapshotGraph()->setMinimumSize(piesize,piesize);
stats+="HI \t"+QString::number(hi,'f',2)+"\n"; mainwin->snapshotGraph()->setMaximumSize(piesize,piesize);
stats+="CAI\t"+QString::number(cai,'f',2)+"\n";
if (cpap->machine->GetClass()=="PRS1") { QFont * _defaultfont=defaultfont;
stats+="REI\t"+QString::number(rei,'f',2)+"\n"; QFont * _mediumfont=mediumfont;
stats+="VSI\t"+QString::number(vsi,'f',2)+"\n"; QFont * _bigfont=bigfont;
stats+="FLI\t"+QString::number(fli,'f',2)+"\n";
stats+="PB/CSR\t"+QString::number(csr,'f',2)+"%\n"; QFont fa=*defaultfont;
} else if (cpap->machine->GetClass()=="ResMed") { QFont fb=*mediumfont;
stats+="UAI\t"+QString::number(uai,'f',2)+"\n"; QFont fc=*bigfont;
} else if (cpap->machine->GetClass()=="Intellipap") {
stats+="NRI\t"+QString::number(nri,'f',2)+"\n"; if (!no_scaling ) {
stats+="LKI\t"+QString::number(lki,'f',2)+"\n";
stats+="EPI\t"+QString::number(exp,'f',2)+"\n"; // fa.setPointSizeF((fa.pointSizeF()/graph_xscale)*2);
// fb.setPointSizeF((fb.pointSizeF()/graph_xscale)*2);
// fc.setPointSizeF((fc.pointSizeF()/graph_xscale)*2);
qDebug() << QApplication::desktop()->physicalDpiX();
fa.setPointSizeF(fa.pointSizeF()*font_scale);
fb.setPointSizeF(fb.pointSizeF()*font_scale);
fc.setPointSizeF(fc.pointSizeF()*font_scale);
} }
QRectF bounds=painter.boundingRect(QRectF(0,top,res.width(),0),stats,QTextOption(Qt::AlignRight));
defaultfont=&fa;
mediumfont=&fb;
bigfont=&fc;
QPixmap ebp=getDaily()->eventBreakdownPie()->renderPixmap(piesize,piesize);
defaultfont=_defaultfont;
mediumfont=_mediumfont;
bigfont=_bigfont;
painter.drawPixmap(res.width()-piesize,top,piesize,piesize,ebp);
getDaily()->eventBreakdownPie()->showTitle(true);
QString stats;
painter.setFont(*mediumfont);
stats="AHI\t"+QString::number(ahi,'f',2)+"\n";
QRectF bounds=painter.boundingRect(QRectF(0,0,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();
painter.setFont(*defaultfont);
stats="AI="+QString::number(oai,'f',2)+" ";
stats+="HI="+QString::number(hi,'f',2)+" ";
stats+="CAI="+QString::number(cai,'f',2)+" ";
if (cpap->machine->GetClass()=="PRS1") {
stats+="REI="+QString::number(rei,'f',2)+" ";
stats+="VSI="+QString::number(vsi,'f',2)+" ";
stats+="FLI="+QString::number(fli,'f',2)+" ";
stats+="PB/CSR="+QString::number(csr,'f',2)+"%";
} else if (cpap->machine->GetClass()=="ResMed") {
stats+="UAI="+QString::number(uai,'f',2)+" ";
} else if (cpap->machine->GetClass()=="Intellipap") {
stats+="NRI="+QString::number(nri,'f',2)+" ";
stats+="LKI="+QString::number(lki,'f',2)+" ";
stats+="EPI="+QString::number(exp,'f',2)+" ";
}
bounds=painter.boundingRect(QRectF(0,top+maxy,res.width(),0),stats,QTextOption(Qt::AlignLeft));
painter.drawText(bounds,stats,QTextOption(Qt::AlignLeft));
if (top+maxy+bounds.height()>maxy) maxy=top+maxy+bounds.height();
} }
QRectF bounds=painter.boundingRect(QRectF((res.width()/2)-(res.width()/6),top,res.width()/2,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));
@ -894,6 +938,9 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
} }
top+=maxy; top+=maxy;
mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh);
bool first=true; bool first=true;
QStringList labels; QStringList labels;
QVector<gGraph *> graphs; QVector<gGraph *> graphs;
@ -981,10 +1028,11 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
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;
float fscale=font_scale*graph_xscale;
if (!no_scaling ) { if (!no_scaling ) {
SnapshotGraph->setPrintScaleX(1.5); SnapshotGraph->setPrintScaleX(fscale);
SnapshotGraph->setPrintScaleY(1.5); SnapshotGraph->setPrintScaleY(fscale);
} }
QFont * _defaultfont=defaultfont; QFont * _defaultfont=defaultfont;
QFont * _mediumfont=mediumfont; QFont * _mediumfont=mediumfont;
@ -995,16 +1043,18 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
QFont fc=*bigfont; QFont fc=*bigfont;
if (!no_scaling ) { if (!no_scaling ) {
fa.setPointSizeF(fa.pointSizeF()*2); fa.setPointSizeF(fa.pointSizeF()*fscale);
fb.setPointSizeF(fb.pointSizeF()*2); fb.setPointSizeF(fb.pointSizeF()*fscale);
fc.setPointSizeF(fc.pointSizeF()*2); fc.setPointSizeF(fc.pointSizeF()*fscale);
} }
defaultfont=&fa; defaultfont=&fa;
mediumfont=&fb; mediumfont=&fb;
bigfont=&fc; bigfont=&fc;
//g->showTitle(false);
QPixmap pm=g->renderPixmap(gw,gh); QPixmap pm=g->renderPixmap(gw,gh);
//g->showTitle(true);
defaultfont=_defaultfont; defaultfont=_defaultfont;
mediumfont=_mediumfont; mediumfont=_mediumfont;

View File

@ -195,13 +195,13 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) :
ui->skipEmptyDays->setChecked(general["SkipEmptyDays"].value().toBool()); ui->skipEmptyDays->setChecked(general["SkipEmptyDays"].value().toBool());
ui->enableMultithreading->setChecked(general["EnableMultithreading"].value().toBool()); ui->enableMultithreading->setChecked(general["EnableMultithreading"].value().toBool());
ui->cacheSessionData->setChecked(general["MemoryHog"].value().toBool()); ui->cacheSessionData->setChecked(general["MemoryHog"].value().toBool());
#ifdef Q_WS_MAC //#ifdef Q_WS_MAC
general["HighResPrinting"].setValue(true); // general["HighResPrinting"].setValue(true);
ui->highResolutionPrinting->setChecked(true); // ui->highResolutionPrinting->setChecked(true);
ui->highResolutionPrinting->setEnabled(false); // ui->highResolutionPrinting->setEnabled(false);
#else //#else
ui->highResolutionPrinting->setChecked(general["HighResPrinting"].value().toBool()); ui->highResolutionPrinting->setChecked(general["HighResPrinting"].value().toBool());
#endif //#endif
ui->graphHeight->setValue(general["GraphHeight"].value().toInt()); ui->graphHeight->setValue(general["GraphHeight"].value().toInt());