Implemented a text queue to solve text color bug

This commit is contained in:
Mark Watkins 2011-07-11 11:58:51 +10:00
parent bb80f4b296
commit bbaf680bba
8 changed files with 58 additions and 13 deletions

View File

@ -20,13 +20,11 @@ void gTitle::Plot(gGraphWindow & w,float scrx,float scry)
float width,height;
GetTextExtent(m_title,width,height);
int xp=(height/2)+20;
//if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height;
DrawText(w,m_title,xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)),90.0,m_color,&m_font);
//DrawText(w,m_title,150,-40,45.0); //20+xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),90.0,m_color,&m_font);
//glColor3ub(m_color.red(),m_color.green(),m_color.blue());
//w.renderText(xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),0.35,m_title,m_font);
}

View File

@ -15,6 +15,7 @@ gYAxis::gYAxis(QColor col)
m_show_major_lines=true;
m_show_minor_lines=true;
m_yaxis_scale=1;
}
gYAxis::~gYAxis()
{
@ -89,7 +90,7 @@ void gYAxis::Plot(gGraphWindow &w,float scrx,float scry)
for (double i=miny; i<=maxy+min_ytick-0.00001; i+=min_ytick) {
ty=(i - miny) * ymult;
fd=Format(i); // Override this as a function.
fd=Format(i*m_yaxis_scale); // Override this as a function.
GetTextExtent(fd,x,y);
if (x>labelW) labelW=x;
h=start_py+ty;

View File

@ -25,11 +25,15 @@ class gYAxis:public gLayer
bool ShowMajorTicks() { return m_show_major_ticks; };
virtual const QString & Format(double v) { static QString t; t.sprintf("%.1f",v); return t; };
static const int Margin=50; // Left margin space
void SetScale(float f) { m_yaxis_scale=f; }; // Scale yaxis ticker values (only what's displayed)
float Scale() { return m_yaxis_scale; };
protected:
bool m_show_major_lines;
bool m_show_minor_lines;
bool m_show_minor_ticks;
bool m_show_major_ticks;
float m_yaxis_scale;
};
#endif // GYAXIS_H

View File

@ -55,7 +55,7 @@ void GetTextExtent(QString text, float & width, float & height, QFont *font)
width=fm.width(text); //fm.width(text);
height=fm.xHeight()+2; //fm.ascent();
}
void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font)
void RDrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font)
{
//QFontMetrics fm(*font);
float w,h;
@ -69,11 +69,13 @@ void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QCol
}
// glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glFlush();
// glDisable(GL_DEPTH_TEST);
glFinish();
QPainter painter(&wid);
painter.setFont(*font);
color=Qt::black;
painter.setPen(color);
painter.setBrush(QBrush(color));
painter.setOpacity(1);
// painter.setCompositionMode(QPainter::CompositionMode_);
if (angle==0) {
@ -93,6 +95,33 @@ void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QCol
glDisable(GL_DEPTH_TEST);
}
struct TextBuffer
{
gGraphWindow *wid;
QString text;
int x,y;
float angle;
QColor *color;
QFont *font;
TextBuffer(gGraphWindow * _wid, QString _text, int _x, int _y, float _angle, QColor *_color,QFont *_font) {
wid=_wid; text=_text; x=_x; y=_y; angle=_angle; color=_color; font=_font;
}
};
vector<TextBuffer *> TextQue;
void DrawTextQueue()
{
for (unsigned i=0;i<TextQue.size();i++) {
TextBuffer * t=TextQue[i];
RDrawText(*t->wid,t->text,t->x,t->y,t->angle,*t->color,t->font);
delete TextQue[i];
}
TextQue.clear();
}
void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font)
{
TextQue.push_back(new TextBuffer(&wid,text,x,y,angle,&color,font));
}
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color)

View File

@ -27,6 +27,7 @@ extern GLshort *vertex_array[num_vert_arrays];
class gGraphWindow;
void GetTextExtent(QString text, float & width, float & height, QFont *font=defaultfont);
void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle=0, QColor color=QColor("black"),QFont *font=defaultfont);
void DrawTextQueue();
void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor color);
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color);

View File

@ -733,6 +733,8 @@ void gGraphWindow::Render(float w, float h)
for (list<gLayer *>::iterator l=layers.begin();l!=layers.end();l++) {
(*l)->Plot(*this,w,h);
}
glFinish();
DrawTextQueue();
}
void gGraphWindow::paintGL()

View File

@ -184,7 +184,8 @@ bool PRS1Loader::ParseProperties(Machine *m,QString filename)
s=f.readLine();
}
bool ok;
int i=prop["ProductType"].toInt(&ok);
QString pt=prop["ProductType"];
int i=pt.toInt(&ok,0);
if (ok) {
if (ModelMap.find(i)!=ModelMap.end()) {
m->properties["SubModel"]=ModelMap[i];
@ -1025,14 +1026,20 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
for (int j=0;j<interleave[numsignals-1-s];j++) {
if (sampletype[numsignals-1-s]==0)
c=buffer[k++];
else if (sampletype[numsignals-1-s]==1)
else if (sampletype[numsignals-1-s]==1) {
c=ucbuffer[k++];
if (c<40) {
c=min[s];
//int q=0;
}
}
if (first[s]) {
min[s]=max[s]=c;
first[s]=false;
}
} else {
if (min[s]>c) min[s]=c;
if (max[s]<c) max[s]=c;
}
data[s][pos[s]++]=c;
}
}
@ -1054,7 +1061,7 @@ void InitModelMap()
ModelMap[34]="RemStar Pro with C-Flex+";
ModelMap[35]="RemStar Auto with A-Flex";
ModelMap[37]="RemStar BIPAP Auto with Bi-Flex";
ModelMap[0x41]="RemStar Something ASV with Funky-Flex";
ModelMap[0x41]="BiPAP autoSV Advanced";
};

View File

@ -118,11 +118,14 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
AddCPAPData(mpw=new WaveData(CPAP_MaskPressure,1000000)); //FlowRate
MP=new gGraphWindow(gSplitter,tr("Mask Pressure"),SF);
MP->AddLayer(new gYAxis());
gYAxis *y=new gYAxis();
y->SetScale(.1);
MP->AddLayer(y);
MP->AddLayer(new gXAxis());
gLineChart *g=new gLineChart(mpw,Qt::black,4000,true);
g->ReportEmpty(true);
MP->AddLayer(g);
MP->setMinimumHeight(120);
AddCPAPData(frw=new WaveData(CPAP_FlowRate,1000000)); //FlowRate
@ -634,7 +637,7 @@ void Daily::Load(QDate date)
if (mode==MODE_BIPAP) {
html+="<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;EPAP ")+QString().sprintf("%.2f",eap90)+tr("cmH2O")+"</td></tr>\n"
"<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;IPAP ")+QString().sprintf("%.2f",iap90)+"</td></tr>\n";
"<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;IPAP ")+QString().sprintf("%.2f",iap90)+tr("cmH2O")+"</td></tr>\n";
} else if (mode==MODE_APAP) {
html+=("<tr><td colspan=4 align='center'><i>")+tr("90%&nbsp;Pressure ")+QString().sprintf("%.2f",cpap->summary_weighted_avg(CPAP_PressurePercentValue))+("</i></td></tr>\n");
} else if (mode==MODE_CPAP) {