diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index e469eddc..c70331ad 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -710,7 +710,7 @@ void gToolTip::paint() //actually paints it. void gToolTip::timerDone() { m_visible=false; - m_graphview->updateGL(); + m_graphview->redraw(); } Layer::Layer(ChannelID code) @@ -1183,7 +1183,10 @@ void gGraph::AddLayer(Layer * l,LayerPosition position, short width, short heigh l->addref(); m_layers.push_back(l); } -void gGraph::redraw() { m_graphview->updateGL(); } +void gGraph::redraw() +{ + m_graphview->redraw(); +} void gGraph::timedRedraw(int ms) { m_graphview->timedRedraw(ms); @@ -1233,7 +1236,7 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) if (qstatus2) { qstatus2->setText(str); } - //m_graphview->updateGL(); + //m_graphview->redraw(); //nolayer=false; doredraw=true; } else if (event->buttons() & Qt::RightButton) { @@ -1295,7 +1298,7 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) if (m_layers[i]->mouseMoveEvent(event)) doredraw=true; } if (doredraw) - m_graphview->updateGL(); + m_graphview->redraw(); //} //if (x>left+m_marginleft && xtop+m_margintop && yupdateGL(); + } else m_graphview->redraw(); } if ((m_graphview->horizTravel()left && xtop && yupdateGL(); + //m_graphview->redraw(); } @@ -1708,7 +1711,7 @@ void gGraph::SetXBounds(qint64 minx, qint64 maxx) max_x=maxx; //repaint(); - //m_graphview->updateGL(); + //m_graphview->redraw(); } int gGraph::flipY(int y) { @@ -1823,7 +1826,7 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) : redrawtimer=new QTimer(this); //redrawtimer->setInterval(80); //redrawtimer->start(); - connect(redrawtimer,SIGNAL(timeout()),SLOT(repaint())); + connect(redrawtimer,SIGNAL(timeout()),SLOT(updateGL())); QImage *image=new QImage(":/icons/oximeter.png"); images.push_back(image); @@ -1845,6 +1848,7 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) : m_fadingOut=false; m_fadingIn=false; m_inAnimation=false; + m_limbo=false; } gGraphView::~gGraphView() @@ -2014,7 +2018,7 @@ void gGraphView::scrollbarValueChanged(int val) //qDebug() << "Scrollbar Changed" << val; if (m_offsetY!=val) { m_offsetY=val; - updateGL(); // do this on a timer? + redraw(); // do this on a timer? } } void gGraphView::ResetBounds(bool refresh) //short group) @@ -2091,7 +2095,7 @@ void gGraphView::SetXBounds(qint64 minx, qint64 maxx,short group,bool refresh) qstatus2->setText(str); } - if (refresh) updateGL(); + if (refresh) redraw(); } void gGraphView::updateScale() { @@ -2396,20 +2400,51 @@ bool gGraphView::renderGraphs() } void gGraphView::fadeOut() { - if (m_inAnimation) m_inAnimation=false; - previous_day_snapshot=renderPixmap(width(),height(),false); - m_fadingOut=true; - m_inAnimation=true; - m_animationStarted.start(); - // updateGL(); -} -void gGraphView::fadeIn() -{ -// m_fadingOut=false; -// m_fadingIn=true; -// m_inAnimation=true; -// m_animationStarted.start(); + //if (m_fadingOut) { +// return; +// } + //if (m_inAnimation) { +// m_inAnimation=false; + // } //clone graphs to shapshot graphview object, render, and then fade in, before switching back to normal mode + /*gGraphView *sg=mainwin->snapshotGraph(); + sg->trashGraphs(); + sg->setFixedSize(width(),height()); + sg->m_graphs=m_graphs; + sg->showSplitter(); */ + + //bool restart=false; + //if (!m_inAnimation) + // restart=true; + + bool b=m_inAnimation; + m_inAnimation=false; + + previous_day_snapshot=renderPixmap(width(),height(),false); + m_inAnimation=b; + //m_fadingOut=true; + //m_fadingIn=false; + //m_inAnimation=true; + //m_limbo=false; + //m_animationStarted.start(); + // updateGL(); +} +void gGraphView::fadeIn(bool dir) +{ + m_tooltip->cancel(); + + if (m_fadingIn) { + previous_day_snapshot=current_day_snapshot; + } + m_inAnimation=false; + current_day_snapshot=renderPixmap(width(),height(),false); + m_inAnimation=true; + + m_animationStarted.start(); + m_fadingIn=true; + m_limbo=false; + m_fadedir=dir; + updateGL(); } @@ -2418,10 +2453,11 @@ void gGraphView::paintGL() QTime time; time.start(); - bool something_fun=PROFILE.ExistsAndTrue("EmptyGraphFun"); if (redrawtimer->isActive()) { redrawtimer->stop(); } + + bool something_fun=PROFILE.ExistsAndTrue("EmptyGraphFun"); if (width()<=0) return; if (height()<=0) return; @@ -2430,36 +2466,73 @@ void gGraphView::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); bool numgraphs=true; - const int animTimeout=400; - if (m_inAnimation) { - int elapsed=m_animationStarted.elapsed(); - float p=(float)elapsed / float(animTimeout); //percentage of way through animation timeslot - if (p>1.0) p=1.0; + const int animTimeout=200; + float phase=0; - p=1.0-p; + int elapsed=0; + if (m_inAnimation || m_fadingIn) { + elapsed=m_animationStarted.elapsed(); if (elapsed > animTimeout) { - m_inAnimation=false; // end animation - } else { if (m_fadingOut) { - GLuint tex=bindTexture(previous_day_snapshot); + m_fadingOut=false; + m_animationStarted.start(); + elapsed=0; + m_limbo=true; + } else if (m_fadingIn) { + m_fadingIn=false; + m_inAnimation=false; // end animation + m_limbo=false; + m_fadingOut=false; + } +// + } else { + phase=float(elapsed) / float(animTimeout); //percentage of way through animation timeslot + if (phase>1.0) phase=1.0; + if (phase<0) phase=0; + } + + if (m_inAnimation) { + if (m_fadingOut) { + // bindTexture(previous_day_snapshot); + } else if (m_fadingIn) { + int offset,offset2; + if (m_fadedir) { // forwards + offset2=-width(); + offset=0; + phase=1.0-phase; + } else { // backwards + phase=phase; + offset=-width(); + offset2=0;//-width(); + } glEnable(GL_BLEND); - glBegin(GL_QUADS); - float middle=(float)height() / 2.0; + glColor4f(255,255,255,255); - glTexCoord2f(0.0f, 1.0f); glVertex2f(0,middle-(middle*p)); - glTexCoord2f(1.0f, 1.0f); glVertex2f((float)width(),middle-(middle*p)); - glTexCoord2f(1.0f, 0.0f); glVertex2f((float)width(),middle+(middle*p)); - glTexCoord2f(0.0f, 0.0f); glVertex2f(0,middle+(middle*p)); + + bindTexture(previous_day_snapshot); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 1.0f); glVertex2f(width()*phase+offset2,0); + glTexCoord2f(1.0f, 1.0f); glVertex2f(width()+width()*phase+offset2,0); + glTexCoord2f(1.0f, 0.0f); glVertex2f(width()+width()*phase+offset2,height()); + glTexCoord2f(0.0f, 0.0f); glVertex2f(width()*phase+offset2,height()); glEnd(); - glBindTexture(GL_TEXTURE_2D,0); + + bindTexture(current_day_snapshot); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 1.0f); glVertex2f(width()*phase+offset,0); + glTexCoord2f(1.0f, 1.0f); glVertex2f(width()+width()*phase+offset,0); + glTexCoord2f(1.0f, 0.0f); glVertex2f(width()+width()*phase+offset,height()); + glTexCoord2f(0.0f, 0.0f); glVertex2f(width()*phase+offset,height()); + glEnd(); + glDisable(GL_BLEND); + glBindTexture(GL_TEXTURE_2D,0); } } } - - if (!m_inAnimation) { + if (!m_inAnimation || (!m_fadingIn)) { // Not in animation sequence, draw graphs like normal numgraphs=renderGraphs(); @@ -2494,7 +2567,7 @@ void gGraphView::paintGL() swapBuffers(); // Dump to screen. if (this->isVisible()) { - if (m_inAnimation || (something_fun && !numgraphs)) { + if (m_limbo || m_inAnimation || (something_fun && !numgraphs)) { redrawtimer->setInterval(25); redrawtimer->setSingleShot(true); redrawtimer->start(); @@ -2507,7 +2580,7 @@ void gGraphView::setOffsetY(int offsetY) { if (m_offsetY!=offsetY) { m_offsetY=offsetY; - updateGL(); //issue full redraw.. + redraw(); //issue full redraw.. } } @@ -2516,7 +2589,7 @@ void gGraphView::setOffsetX(int offsetX) { if (m_offsetX!=offsetX) { m_offsetX=offsetX; - updateGL(); //issue redraw + redraw(); //issue redraw } } @@ -2535,7 +2608,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event) m_sizer_point.setX(x); m_sizer_point.setY(y); updateScrollBar(); - updateGL(); + redraw(); } return; } @@ -2558,7 +2631,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event) m_graphs[i]=p; if (!empty) { m_sizer_point.setY(yy-graphSpacer-m_graphs[m_graph_index]->height()*m_scaleY); - updateGL(); + redraw(); } m_graph_index--; } @@ -2575,7 +2648,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event) m_graphs[i]=p; if (!empty) { m_sizer_point.setY(yy+graphSpacer+m_graphs[m_graph_index]->height()*m_scaleY); - updateGL(); + redraw(); } m_graph_index++; if (!empty) break; @@ -2626,7 +2699,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event) ChannelID code=fg->visibleLayers()[i]->code(); QString ttip=schema::channel[code].description(); m_tooltip->display(ttip,x,y-20,800); - updateGL(); + redraw(); //qDebug() << code << ttip; } } @@ -2637,7 +2710,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event) } else { if (!m_graphs[i]->units().isEmpty()) { m_tooltip->display(m_graphs[i]->units(),x,y-20,800); - updateGL(); + redraw(); } } } @@ -2881,7 +2954,7 @@ void gGraphView::setDay(Day * day) for (int i=0;isetDay(day); } - ResetBounds(); + ResetBounds(false); } bool gGraphView::isEmpty() { @@ -2897,7 +2970,7 @@ bool gGraphView::isEmpty() void gGraphView::refreshTimeout() { - updateGL(); + redraw(); } void gGraphView::timedRedraw(int ms) { @@ -2913,7 +2986,7 @@ void gGraphView::resetLayout() m_graphs[i]->setHeight(default_height); } updateScale(); - updateGL(); + redraw(); } void gGraphView::deselect() { @@ -3036,3 +3109,8 @@ int gGraphView::visibleGraphs() } return cnt; } +void gGraphView::redraw() +{ + if (!m_inAnimation) + updateGL(); +} diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index 73fa975a..3aafddb3 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -752,7 +752,10 @@ public: void fadeOut(); //! \brief Start the animation sequence showing new Day's data. (fade in) - void fadeIn(); + void fadeIn(bool dir=false); + + //! \brief Call UpdateGL unless animation is in progress + void redraw(); gGraph *m_selected_graph; gToolTip * m_tooltip; @@ -806,7 +809,6 @@ public: //! \brief Sends day object to be distributed to all Graphs Layers objects void setDay(Day * day); - GLShortBuffer * lines, * backlines, *quads, * stippled; //! \brief pops a graph off the list for multithreaded drawing code @@ -918,7 +920,10 @@ protected: QPixmap current_day_snapshot; bool m_fadingOut; bool m_fadingIn; + bool m_limbo; + bool m_fadedir; bool m_inAnimation; + bool m_blockUpdates; QTime m_animationStarted; diff --git a/daily.cpp b/daily.cpp index a975d1f3..204201cc 100644 --- a/daily.cpp +++ b/daily.cpp @@ -376,7 +376,6 @@ void Daily::ReloadGraphs() { QDate d; if (previous_date.isValid()) { - GraphView->fadeOut(); d=previous_date; Unload(d); } //else @@ -387,7 +386,6 @@ void Daily::ReloadGraphs() on_calendar_currentPageChanged(d.year(),d.month()); ui->calendar->setSelectedDate(d); Load(d); - GraphView->fadeIn(); } void Daily::on_calendar_currentPageChanged(int year, int month) { @@ -527,12 +525,15 @@ void Daily::LoadDate(QDate date) void Daily::on_calendar_selectionChanged() { - GraphView->fadeOut(); - if (previous_date.isValid()) - Unload(previous_date); + if (previous_date.isValid()) { + GraphView->fadeOut(); + Unload(previous_date); + } + bool fadedir=previous_date < ui->calendar->selectedDate(); ZombieMeterMoved=false; Load(ui->calendar->selectedDate()); + GraphView->fadeIn(fadedir); ui->calButton->setText(ui->calendar->selectedDate().toString(Qt::TextDate)); ui->calendar->setFocus(Qt::ActiveWindowFocusReason); @@ -546,7 +547,6 @@ void Daily::on_calendar_selectionChanged() ui->ouncesSpinBox->setVisible(true); ui->ouncesSpinBox->setSuffix("oz"); } - GraphView->fadeIn(); } void Daily::ResetGraphLayout() { @@ -562,7 +562,7 @@ void Daily::graphtogglebutton_toggled(bool b) (*GraphView)[i]->setVisible(GraphToggles[title]->isChecked()); } GraphView->updateScale(); - GraphView->updateGL(); + GraphView->redraw(); } void Daily::Load(QDate date) { @@ -617,9 +617,7 @@ void Daily::Load(QDate date) UpdateCPAPGraphs(cpap); UpdateEventsTree(ui->treeWidget,cpap); snapGV->setDay(cpap); - - - GraphView->ResetBounds(); + GraphView->ResetBounds(false); //snapGV->ResetBounds(); //GraphView->ResetBounds(1); @@ -633,8 +631,8 @@ void Daily::Load(QDate date) // GraphView->show(); scrollbar->show(); } - GraphView->updateGL(); - snapGV->updateGL(); + //GraphView->redraw(); + //snapGV->redraw(); //RedrawGraphs(); @@ -1225,7 +1223,7 @@ void Daily::UpdateOXIGraphs(Day *day) void Daily::RedrawGraphs() { - GraphView->updateGL(); + GraphView->redraw(); } void Daily::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column) @@ -1360,7 +1358,7 @@ void Daily::on_bookmarkTable_itemClicked(QTableWidgetItem *item) st=it->data(Qt::UserRole).toLongLong(&ok); et=it->data(Qt::UserRole+1).toLongLong(&ok); GraphView->SetXBounds(st,et); - GraphView->updateGL(); + GraphView->redraw(); } void Daily::on_addBookmarkButton_clicked() diff --git a/overview.cpp b/overview.cpp index 0f24bb18..d152add2 100644 --- a/overview.cpp +++ b/overview.cpp @@ -258,7 +258,7 @@ void Overview::ReloadGraphs() void Overview::RedrawGraphs() { - GraphView->updateGL(); + GraphView->redraw(); } void Overview::UpdateCalendarDay(QDateEdit * dateedit,QDate date) diff --git a/oximetry.cpp b/oximetry.cpp index 2b6ca6a3..f74542fb 100644 --- a/oximetry.cpp +++ b/oximetry.cpp @@ -657,7 +657,7 @@ void CMS50Serial::ReadyRead() if (c & 0x80) break; } mainwin->getOximetry()->graphView()->setEmptyText("Please Wait, Importing..."); - mainwin->getOximetry()->graphView()->updateGL(); + mainwin->getOximetry()->graphView()->redraw(); data.clear(); for (z=i;zgetOximetry()->graphView()->setEmptyText("fun"); - //mainwin->getOximetry()->graphView()->updateGL(); + //mainwin->getOximetry()->graphView()->redraw(); if (i>1000) { //mainwin->getOximetry()->graphView()->setEmptyText("fun"); - //mainwin->getOximetry()->graphView()->updateGL(); + //mainwin->getOximetry()->graphView()->redraw(); imptime.start(); failcnt++; QString a; @@ -719,13 +719,13 @@ void CMS50Serial::ReadyRead() m_mode=SO_WAIT; emit(importAborted()); mainwin->getOximetry()->graphView()->setEmptyText("Import Failed"); - mainwin->getOximetry()->graphView()->updateGL(); + mainwin->getOximetry()->graphView()->redraw(); return; } else { a="Waiting"; for (int i=0;igetOximetry()->graphView()->setEmptyText(a); - mainwin->getOximetry()->graphView()->updateGL(); + mainwin->getOximetry()->graphView()->redraw(); requestData(); // retransmit the data request code } } @@ -880,7 +880,7 @@ Oximetry::Oximetry(QWidget *parent,gGraphView * shared) : //go->SetDay(day); GraphView->setEmptyText(tr("No Oximetry Data")); - GraphView->updateGL(); + GraphView->redraw(); on_RefreshPortsButton_clicked(); ui->RunButton->setChecked(false); @@ -964,7 +964,7 @@ void Oximetry::on_RefreshPortsButton_clicked() } void Oximetry::RedrawGraphs() { - GraphView->updateGL(); + GraphView->redraw(); } void Oximetry::on_SerialPortsCombo_activated(const QString &arg1) { @@ -1013,7 +1013,7 @@ void Oximetry::on_RunButton_toggled(bool checked) } } // else it's already saved. GraphView->setEmptyText(tr("Please Wait")); - GraphView->updateGL(); + GraphView->redraw(); PLETHY->setRecMinY(0); PLETHY->setRecMaxY(128); @@ -1120,7 +1120,7 @@ void Oximetry::data_changed() } GraphView->updateScale(); - GraphView->updateGL(); + GraphView->redraw(); } @@ -1159,7 +1159,7 @@ void Oximetry::oximeter_running_check() ui->RunButton->setChecked(false); ui->saveButton->setEnabled(false); GraphView->setEmptyText(tr("Check Oximeter is Ready")); - GraphView->updateGL(); + GraphView->redraw(); } } @@ -1174,7 +1174,7 @@ void Oximetry::on_ImportButton_clicked() day->getSessions().clear(); GraphView->setDay(day); GraphView->setEmptyText("Make Sure Oximeter Is Ready"); - GraphView->updateGL(); + GraphView->redraw(); if (!oximeter->startImport()) { mainwin->Notify(tr("Oximeter Error\n\nThe device did not respond.. Make sure it's switched on.")); @@ -1303,7 +1303,7 @@ void Oximetry::on_saveButton_clicked() mainwin->getDaily()->ReloadGraphs(); mainwin->getOverview()->ReloadGraphs(); GraphView->setEmptyText("No Oximetry Data"); - GraphView->updateGL(); + GraphView->redraw(); } } void Oximetry::update_progress(float f) @@ -1396,7 +1396,7 @@ bool Oximetry::openSPOFile(QString filename) bool Oximetry::openSPORFile(QString filename) { //GraphView->setEmptyText("Please Wait"); - //GraphView->updateGL(); + //GraphView->redraw(); QFile f(filename); if (!f.open(QFile::ReadOnly)) return false; @@ -1613,7 +1613,7 @@ void Oximetry::updateGraphs() if (qstatus2) qstatus2->setText(QString().sprintf("%02i:%02i:%02i",h,m,s)); } GraphView->updateScale(); - GraphView->updateGL(); + GraphView->redraw(); } void Oximetry::on_resetTimeButton_clicked() //revert to original session time