More graphical tinkering

This commit is contained in:
Mark Watkins 2011-12-21 03:22:02 +10:00
parent 64c4143848
commit 1a9ec935c3
11 changed files with 94 additions and 43 deletions

View File

@ -37,6 +37,8 @@ bool evil_intel_graphics_chip=false;
extern QLabel * qstatus2; extern QLabel * qstatus2;
const int mouse_movement_threshold=6; const int mouse_movement_threshold=6;
QHash<QString, QImage *> images;
// Must be called from a thread inside the application. // Must be called from a thread inside the application.
void InitGraphs() void InitGraphs()
{ {
@ -81,6 +83,16 @@ void InitGraphs()
mediumfont->setStyleHint(QFont::AnyStyle,QFont::OpenGLCompatible); mediumfont->setStyleHint(QFont::AnyStyle,QFont::OpenGLCompatible);
bigfont->setStyleHint(QFont::AnyStyle,QFont::OpenGLCompatible); bigfont->setStyleHint(QFont::AnyStyle,QFont::OpenGLCompatible);
images["mask"]=new QImage(":/icons/mask.png");
images["oximeter"]=new QImage(":/icons/cubeoximeter.png");
images["smiley"]=new QImage(":/icons/smileyface.png");
images["sad"]=new QImage(":/icons/sadface.png");
images["brick"]=new QImage(":/icons/brick.png");
//images["warning"]=new QImage(":/icons/warning.png");
//images["bug"]=new QImage(":/icons/bug.png");
images["sheep"]=new QImage(":/icons/sheep.png");
images["nodata"]=new QImage(":/icons/nodata.png");
_graph_init=true; _graph_init=true;
} }
} }
@ -90,6 +102,9 @@ void DoneGraphs()
delete defaultfont; delete defaultfont;
delete bigfont; delete bigfont;
delete mediumfont; delete mediumfont;
for (QHash<QString,QImage *>::iterator i=images.begin();i!=images.end();i++) {
delete i.value();
}
_graph_init=false; _graph_init=false;
} }
} }
@ -1827,23 +1842,9 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) :
//redrawtimer->setInterval(80); //redrawtimer->setInterval(80);
//redrawtimer->start(); //redrawtimer->start();
connect(redrawtimer,SIGNAL(timeout()),SLOT(updateGL())); connect(redrawtimer,SIGNAL(timeout()),SLOT(updateGL()));
QImage *image=new QImage(":/icons/oximeter.png");
images.push_back(image);
image=new QImage(":/docs/sheep.png"); //cubeimg.push_back(images["brick"]);
images.push_back(image); //cubeimg.push_back(images[""]);
image=new QImage(":/icons/sdcard.png");
images.push_back(image);
image=new QImage(":/icons/preferences.png");
images.push_back(image);
image=new QImage(":/icons/overview.png");
images.push_back(image);
image=new QImage(":/icons/edit-find.png");
images.push_back(image);
m_fadingOut=false; m_fadingOut=false;
m_fadingIn=false; m_fadingIn=false;
@ -1875,9 +1876,6 @@ gGraphView::~gGraphView()
disconnect(timer,0,0,0); disconnect(timer,0,0,0);
timer->stop(); timer->stop();
delete timer; delete timer;
for (int i=0;i<images.size();i++) {
delete images[i];
}
} }
void gGraphView::DrawTextQue() void gGraphView::DrawTextQue()
{ {
@ -2154,10 +2152,13 @@ void gGraphView::initializeGL()
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
texid.resize(images.size()); if (cubeimg.size()>0) {
for(int i=0;i<images.size();i++) { cubetex=bindTexture(*cubeimg[0]);
texid[i]=bindTexture(*images[i]);
} }
// texid.resize(images.size());
// for(int i=0;i<images.size();i++) {
// texid[i]=bindTexture(*images[i]);
// }
glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D,0);
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
@ -2176,6 +2177,7 @@ void gGraphView::resizeGL(int w, int h)
void gGraphView::renderSomethingFun() void gGraphView::renderSomethingFun()
{ {
if (cubeimg.size()==0) return;
// glPushMatrix(); // glPushMatrix();
float w=width(); float w=width();
float h=height(); float h=height();
@ -2204,7 +2206,7 @@ void gGraphView::renderSomethingFun()
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glDisable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL);
int imgcount=6; //int imgcount=cubeimg.size();
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -2215,9 +2217,10 @@ void gGraphView::renderSomethingFun()
int i=0; int i=0;
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); cubetex=bindTexture(*cubeimg[0]);
//glBindTexture(GL_TEXTURE_2D, cubetex); //texid[i % imgcount]);
i++; i++;
glColor4f(255,255,255,255); glColor4f(1,1,1,1);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
@ -2226,7 +2229,8 @@ void gGraphView::renderSomethingFun()
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glEnd(); glEnd();
// Back Face // Back Face
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); //bindTexture(*cubeimg[i % imgcount]);
//glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]);
i++; i++;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
@ -2235,7 +2239,8 @@ void gGraphView::renderSomethingFun()
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glEnd(); glEnd();
// Top Face // Top Face
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); //bindTexture(*cubeimg[i % imgcount]);
// glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]);
i++; i++;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
@ -2244,7 +2249,8 @@ void gGraphView::renderSomethingFun()
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glEnd(); glEnd();
// Bottom Face // Bottom Face
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); //bindTexture(*cubeimg[i % imgcount]);
//glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]);
i++; i++;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
@ -2253,7 +2259,8 @@ void gGraphView::renderSomethingFun()
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glEnd(); glEnd();
// Right face // Right face
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); //bindTexture(*cubeimg[i % imgcount]);
// glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]);
i++; i++;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
@ -2262,7 +2269,8 @@ void gGraphView::renderSomethingFun()
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glEnd(); glEnd();
// Left Face // Left Face
glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]); //bindTexture(*cubeimg[i % imgcount]);
//glBindTexture(GL_TEXTURE_2D, texid[i % imgcount]);
i++; i++;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
@ -2434,7 +2442,11 @@ void gGraphView::fadeIn(bool dir)
m_tooltip->cancel(); m_tooltip->cancel();
if (m_fadingIn) { if (m_fadingIn) {
previous_day_snapshot=current_day_snapshot; m_fadingIn=false;
m_inAnimation=false;
updateGL();
return;
// previous_day_snapshot=current_day_snapshot;
} }
m_inAnimation=false; m_inAnimation=false;
current_day_snapshot=renderPixmap(width(),height(),false); current_day_snapshot=renderPixmap(width(),height(),false);
@ -2466,7 +2478,7 @@ void gGraphView::paintGL()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
bool numgraphs=true; bool numgraphs=true;
const int animTimeout=200; const int animTimeout=500;
float phase=0; float phase=0;
int elapsed=0; int elapsed=0;
@ -2515,6 +2527,7 @@ void gGraphView::paintGL()
glEnable(GL_BLEND); glEnable(GL_BLEND);
glColor4f(1.0,1.0,1.0,aphase); glColor4f(1.0,1.0,1.0,aphase);
// glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
bindTexture(previous_day_snapshot); bindTexture(previous_day_snapshot);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -2525,7 +2538,10 @@ void gGraphView::paintGL()
glEnd(); glEnd();
glColor4f(1.0,1.0,1.0,phase); glColor4f(1.0,1.0,1.0,phase);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glAlphaFunc(GL_GREATER,0.9);
//glEnable(GL_ALPHA_TEST);
bindTexture(current_day_snapshot); bindTexture(current_day_snapshot);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0,0); glTexCoord2f(0.0f, 1.0f); glVertex2f(0,0);
@ -2534,6 +2550,7 @@ void gGraphView::paintGL()
glTexCoord2f(0.0f, 0.0f); glVertex2f(0,height()); glTexCoord2f(0.0f, 0.0f); glVertex2f(0,height());
glEnd(); glEnd();
//glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D,0);
} }
@ -2545,16 +2562,20 @@ void gGraphView::paintGL()
numgraphs=renderGraphs(); numgraphs=renderGraphs();
if (!numgraphs) { // No graphs drawn? if (!numgraphs) { // No graphs drawn?
if (something_fun && this->isVisible()) // Do something fun instead
renderSomethingFun();
// Then display the empty text message
QColor col=Qt::black;
int x,y; int x,y;
GetTextExtent(m_emptytext,x,y,bigfont); GetTextExtent(m_emptytext,x,y,bigfont);
AddTextQue(m_emptytext,(width()/2)-x/2,(height()/2)+y/2,0.0,col,bigfont); int tp;
if (something_fun && this->isVisible()) {// Do something fun instead
renderSomethingFun();
tp=height()-(y/2);
} else {
tp=height() / 2 + y / 2;
}
// Then display the empty text message
QColor col=Qt::black;
AddTextQue(m_emptytext,(width()/2)-x/2,tp,0.0,col,bigfont);
DrawTextQue(); DrawTextQue();
} }
} }
@ -2576,13 +2597,22 @@ void gGraphView::paintGL()
if (this->isVisible()) { if (this->isVisible()) {
if (m_limbo || m_inAnimation || (something_fun && !numgraphs)) { if (m_limbo || m_inAnimation || (something_fun && !numgraphs)) {
redrawtimer->setInterval(25); redrawtimer->setInterval(15);
redrawtimer->setSingleShot(true); redrawtimer->setSingleShot(true);
redrawtimer->start(); redrawtimer->start();
} }
} }
} }
void gGraphView::setCubeImage(QImage *img)
{
cubeimg.clear();
cubeimg.push_back(img);
cubetex=bindTexture(*img);
glBindTexture(GL_TEXTURE_2D,0);
}
// For manual scrolling // For manual scrolling
void gGraphView::setOffsetY(int offsetY) void gGraphView::setOffsetY(int offsetY)
{ {

View File

@ -35,6 +35,8 @@ extern QFont * defaultfont;
extern QFont * mediumfont; extern QFont * mediumfont;
extern QFont * bigfont; extern QFont * bigfont;
extern QHash<QString, QImage *> images;
/*! \brief Gets the width and height parameters for supplied text /*! \brief Gets the width and height parameters for supplied text
\param QString text - The text string in question \param QString text - The text string in question
\param int & width \param int & width
@ -796,6 +798,12 @@ public:
//! \brief Sets the message displayed when there are no graphs to draw //! \brief Sets the message displayed when there are no graphs to draw
void setEmptyText(QString s) { m_emptytext=s; } void setEmptyText(QString s) { m_emptytext=s; }
void setCubeImage(QImage *);
// Cube fun
QVector<QImage *> cubeimg;
GLuint cubetex;
#ifdef ENABLE_THREADED_DRAWING #ifdef ENABLE_THREADED_DRAWING
QMutex text_mutex; QMutex text_mutex;
QMutex gl_mutex; QMutex gl_mutex;
@ -927,9 +935,7 @@ protected:
QTime m_animationStarted; QTime m_animationStarted;
// Cube fun //QVector<GLuint> texid;
QVector<QImage *> images;
QVector<GLuint> texid;
signals: signals:

View File

@ -27,5 +27,12 @@
<file>icons/arrow-end.png</file> <file>icons/arrow-end.png</file>
<file>icons/arrow-left.png</file> <file>icons/arrow-left.png</file>
<file>icons/arrow-right.png</file> <file>icons/arrow-right.png</file>
<file>icons/smileyface.png</file>
<file>icons/sadface.png</file>
<file>icons/mask.png</file>
<file>icons/brick.png</file>
<file>icons/sheep.png</file>
<file>icons/nodata.png</file>
<file>icons/cubeoximeter.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -647,8 +647,11 @@ void Daily::Load(QDate date)
PRTypes pr; PRTypes pr;
QString a; QString a;
bool isBrick=false; bool isBrick=false;
GraphView->setCubeImage(images["nodata"]);
if (cpap) { if (cpap) {
if (GraphView->isEmpty()) { if (GraphView->isEmpty()) {
GraphView->setCubeImage(images["brick"]);
GraphView->setEmptyText(tr("Brick Machine :(")); GraphView->setEmptyText(tr("Brick Machine :("));
isBrick=true; isBrick=true;
} else { } else {

BIN
icons/brick.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
icons/cubeoximeter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
icons/mask.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

BIN
icons/sheep.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
icons/smileyface.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -71,6 +71,9 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
GraphView=new gGraphView(ui->graphArea,m_shared); GraphView=new gGraphView(ui->graphArea,m_shared);
GraphView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); GraphView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
GraphView->setEmptyText("Import some data!");
GraphView->setCubeImage(images["nodata"]);
// Create the custom scrollbar and attach to GraphView // Create the custom scrollbar and attach to GraphView
scrollbar=new MyScrollBar(ui->graphArea); scrollbar=new MyScrollBar(ui->graphArea);
scrollbar->setOrientation(Qt::Vertical); scrollbar->setOrientation(Qt::Vertical);
@ -78,6 +81,7 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
scrollbar->setMaximumWidth(20); scrollbar->setMaximumWidth(20);
GraphView->setScrollBar(scrollbar); GraphView->setScrollBar(scrollbar);
// Add the graphView and scrollbar to the layout. // Add the graphView and scrollbar to the layout.
layout->addWidget(GraphView,1); layout->addWidget(GraphView,1);
layout->addWidget(scrollbar,0); layout->addWidget(scrollbar,0);

View File

@ -887,6 +887,7 @@ Oximetry::Oximetry(QWidget *parent,gGraphView * shared) :
ui->saveButton->setEnabled(false); ui->saveButton->setEnabled(false);
GraphView->LoadSettings("Oximetry"); GraphView->LoadSettings("Oximetry");
GraphView->setCubeImage(images["oximeter"]);
QLocale locale=QLocale::system(); QLocale locale=QLocale::system();
QString shortformat=locale.dateFormat(QLocale::ShortFormat); QString shortformat=locale.dateFormat(QLocale::ShortFormat);