Graph Layout fixes

This commit is contained in:
Mark Watkins 2011-12-12 17:10:45 +10:00
parent babc896955
commit 136918a563
6 changed files with 48 additions and 30 deletions

View File

@ -1080,6 +1080,10 @@ void gGraph::paint(int originX, int originY, int width, int height)
glDisable(GL_BLEND); glDisable(GL_BLEND);
*/ */
int fw,font_height;
GetTextExtent("Wg@",fw,font_height);
m_margintop=font_height+(6*printScaleY());
//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,y;
@ -1660,10 +1664,10 @@ GLShortBuffer * gGraph::stippled()
{ {
return m_graphview->stippled; return m_graphview->stippled;
} }
short gGraph::marginLeft() { return m_marginleft*m_graphview->printScaleX(); } short gGraph::marginLeft() { return m_marginleft; }//*m_graphview->printScaleX(); }
short gGraph::marginRight() { return m_marginright*m_graphview->printScaleX(); } short gGraph::marginRight() { return m_marginright; } //*m_graphview->printScaleX(); }
short gGraph::marginTop() { return m_margintop*m_graphview->printScaleY(); } short gGraph::marginTop() { return m_margintop; } //*m_graphview->printScaleY(); }
short gGraph::marginBottom() { return m_marginbottom*m_graphview->printScaleY(); } short gGraph::marginBottom() { return m_marginbottom; } //*m_graphview->printScaleY(); }
QPixmap gGraph::renderPixmap(int w, int h) QPixmap gGraph::renderPixmap(int w, int h)
{ {

View File

@ -368,8 +368,8 @@ public:
QTimer * timer; QTimer * timer;
QVector<Layer *> & layers() { return m_layers; } QVector<Layer *> & layers() { return m_layers; }
protected:
short m_marginleft, m_marginright, m_margintop, m_marginbottom; short m_marginleft, m_marginright, m_margintop, m_marginbottom;
protected:
//void invalidate(); //void invalidate();
virtual void wheelEvent(QWheelEvent * event); virtual void wheelEvent(QWheelEvent * event);

View File

@ -65,6 +65,8 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
if (width<0) if (width<0)
return; return;
// lines=w.lines(); // lines=w.lines();
EventDataType miny,maxy; EventDataType miny,maxy;
double minx,maxx; double minx,maxx;
@ -82,6 +84,8 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
miny=-MAX(fabs(miny),fabs(maxy)); miny=-MAX(fabs(miny),fabs(maxy));
}*/ }*/
w.roundY(miny,maxy); w.roundY(miny,maxy);
double xx=maxx-minx; double xx=maxx-minx;

View File

@ -532,7 +532,7 @@ 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; px-=20+x;
w.renderText(a,px+20,py+2); w.renderText(a,px+20,py+1);
quads->add(px+5,py-7,px+18,py-7,px+18,py+1,px+5,py+1,m_colors[j]); quads->add(px+5,py-7,px+18,py-7,px+18,py+1,px+5,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]);
@ -543,7 +543,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
a=m_label+"="+QString::number(val,'f',2)+" "; a=m_label+"="+QString::number(val,'f',2)+" ";
GetTextExtent(a,x,y); GetTextExtent(a,x,y);
px-=20+x; px-=20+x;
w.renderText(a,px+24,py+2); w.renderText(a,px+24,py+1);
// //
} }
} }
@ -561,7 +561,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
px-=30+x; px-=30+x;
//w.renderText(a,px+24,py+5); //w.renderText(a,px+24,py+5);
w.renderText(a,left,py+2); w.renderText(a,left,py+1);
} }
QString formatTime(EventDataType v, bool show_seconds=false, bool duration=false,bool show_12hr=false) QString formatTime(EventDataType v, bool show_seconds=false, bool duration=false,bool show_12hr=false)

View File

@ -150,12 +150,12 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
SF->AddLayer(new gShadowArea()); SF->AddLayer(new gShadowArea());
SF->AddLayer(new gYSpacer(),LayerLeft,gYAxis::Margin); SF->AddLayer(new gYSpacer(),LayerLeft,gYAxis::Margin);
//SF->AddLayer(new gFooBar(),LayerBottom,0,1); //SF->AddLayer(new gFooBar(),LayerBottom,0,1);
SF->AddLayer(new gXAxis(Qt::black,false),LayerBottom,0,gXAxis::Margin); SF->AddLayer(new gXAxis(Qt::black,false),LayerBottom,0,20); //gXAxis::Margin);
gLineChart *l; gLineChart *l;
l=new gLineChart(CPAP_FlowRate,Qt::black,false,false); l=new gLineChart(CPAP_FlowRate,Qt::black,false,false);
gLineOverlaySummary *los=new gLineOverlaySummary("Selection AHI",5,-3); gLineOverlaySummary *los=new gLineOverlaySummary("Selection AHI",5,-4);
AddCPAP(l); AddCPAP(l);
FRW->AddLayer(new gXGrid()); FRW->AddLayer(new gXGrid());
FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_CSR,QColor("light green"),"CSR",FT_Span))); FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_CSR,QColor("light green"),"CSR",FT_Span)));

View File

@ -758,39 +758,44 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
const int graphs_per_page=6; const int graphs_per_page=6;
float pw=res.width(); float pw=res.width();
QRectF pagebnds=painter.boundingRect(QRectF(0,0,res.width(),0),"W",QTextOption(Qt::AlignCenter)); QRectF pagebnds=painter.boundingRect(QRectF(0,0,res.width(),0),"Wg",QTextOption(Qt::AlignCenter));
pagebnds.moveBottom(pagebnds.bottom()+ceil(pagebnds.height()/2.5)); const int labelheight=pagebnds.height()*1.33;
const int labelheight=pagebnds.height();
const int footer_height=labelheight; const int footer_height=labelheight;
float realheight=res.height()-footer_height; float realheight=res.height()-footer_height;
float ph=(realheight-(labelheight*graphs_per_page)) / graphs_per_page; float ph=(realheight-(labelheight*graphs_per_page)) / graphs_per_page;
float div,fontdiv; float div,fontscale;
if (pw>8000) { if (pw>8000) {
div=4; div=4;
#ifdef Q_WS_WIN32 #if defined(Q_WS_WIN32)
fontdiv=2.3; fontscale=2.3;
#elif defined(Q_WS_MAC)
fontscale=3;
#else #else
fontdiv=2.3; fontscale=2.3;
#endif #endif
} else if (pw>2000) { } else if (pw>2000) {
div=2.0; div=2.0;
fontdiv=2.0; #if defined(Q_WS_MAC)
fontscale=3;
#else
fontscale=2.0;
#endif
} else { } else {
div=1; div=1;
#ifdef Q_WS_WIN32 #if defined(Q_WS_WIN32)
fontdiv=1; // windows will crash if it's any smaller than this fontscale=1; // windows will crash if it's any smaller than this
#else #else
fontdiv=0.75; fontscale=0.75;
#endif #endif
} }
float gw=pw/div; float gw=pw/div;
float gh=ph/div; float gh=ph/div;
SnapshotGraph->setPrintScaleX(fontdiv); SnapshotGraph->setPrintScaleX(fontscale);
SnapshotGraph->setPrintScaleY(fontdiv); SnapshotGraph->setPrintScaleY(fontscale);
mainwin->snapshotGraph()->setMinimumSize(gw,gh); mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh); mainwin->snapshotGraph()->setMaximumSize(gw,gh);
@ -960,7 +965,7 @@ 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>realheight) { //top+pm.height()>res.height()) { if ((top+ph+labelheight) > realheight) { //top+pm.height()>res.height()) {
top=0; top=0;
gcnt=0; gcnt=0;
//header_height=0; //header_height=0;
@ -974,19 +979,24 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date)
} }
QString label=labels[i]; QString label=labels[i];
//if (!label.isEmpty()) { if (!label.isEmpty()) {
QRectF pagebnds=painter.boundingRect(QRectF(0,top,res.width(),labelheight),label,QTextOption(Qt::AlignCenter)); label+=":";
painter.drawText(pagebnds,label,QTextOption(Qt::AlignCenter)); QRectF pagebnds=QRectF(0,top,res.width(),labelheight);
top+=labelheight; //pagebnds.height(); painter.drawText(pagebnds,label,QTextOption(Qt::AlignHCenter | Qt::AlignTop));
//} }
top+=labelheight; //pagebnds.height();
PROFILE["UseAntiAliasing"]=force_antialiasing; PROFILE["UseAntiAliasing"]=force_antialiasing;
int tmb=g->m_marginbottom;
g->m_marginbottom=0;
QPixmap pm=g->renderPixmap(gw,gh); QPixmap pm=g->renderPixmap(gw,gh);
g->m_marginbottom=tmb;
PROFILE["UseAntiAliasing"]=aa_setting; PROFILE["UseAntiAliasing"]=aa_setting;
QPixmap pm2=pm.scaledToWidth(pw); QPixmap pm2=pm.scaledToWidth(pw);
painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2); painter.drawPixmap(0,top,pm2.width(),pm2.height(),pm2);
top+=ph; //pm2.height(); top+=ph; //pm2.height();
gcnt++;
gcnt++;
if (qprogress) { if (qprogress) {
qprogress->setValue(i); qprogress->setValue(i);
QApplication::processEvents(); QApplication::processEvents();