From eb83b746e039ce10043c6f23d9a3e383d3dde8e1 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sun, 4 Sep 2011 01:54:27 +1000 Subject: [PATCH] Tooltip improvements.. Still not finished yet --- Graphs/gBarChart.cpp | 45 ++++++++++++++++++++++++++++--------------- Graphs/gGraphView.cpp | 39 +++++++++++++++++++++++++------------ Graphs/gGraphView.h | 8 ++++++-- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/Graphs/gBarChart.cpp b/Graphs/gBarChart.cpp index 74a05f80..1a920f8c 100644 --- a/Graphs/gBarChart.cpp +++ b/Graphs/gBarChart.cpp @@ -150,7 +150,7 @@ void gBarChart::paint(gGraph & w,int left, int top, int width, int height) } if (total_days>0) { float val=total_val/float(total_days); - QString z=m_label+"="+QString::number(val,'f',2)+" days="+QString::number(total_days,'f',0)+" This is going in overview later"; + QString z=m_label+"="+QString::number(val,'f',2)+" days="+QString::number(total_days,'f',0)+" This needs optimising and will going in overview"; w.renderText(z,left,top-1); // val = AHI for selected area. } @@ -161,8 +161,7 @@ bool gBarChart::mouseMoveEvent(QMouseEvent *event) int y=event->y()-l_top; if (!(x>=0 && y>=0 && xredraw(); + //graph->timedRedraw(2000); return false; } @@ -173,25 +172,39 @@ bool gBarChart::mouseMoveEvent(QMouseEvent *event) mx+=l_minx; mx=mx+l_offset;//-86400000L; int zd=mx/86400000L; - if (hl_day!=zd) { + //if (hl_day!=zd) + { hl_day=zd; QHash >::iterator d=m_values.find(hl_day); if (d!=m_values.end()) { - QString z=m_label+"="+QString::number(d.value()[0],'f',2); - qstatus2->setText(z); - QColor col(255,255,128,200); - GLBuffer *lines=graph->lines(); - graph->quads()->add(event->x()-20,rtop+y-12,event->x()-20,rtop+y+5,col); - graph->quads()->add(event->x()+75,rtop+y+5,event->x()+75,rtop+y-12,col); - QColor blk(0,0,0,255); - lines->add(event->x()-21,rtop+y-12,event->x()+76,rtop+y-12,blk); - lines->add(event->x()-21,rtop+y+6,event->x()+76,rtop+y+6,blk); - lines->add(event->x()-21,rtop+y-12,event->x()-21,rtop+y+6,blk); - lines->add(event->x()+76,rtop+y-12,event->x()+76,rtop+y+6,blk); + int yy=y; + int x=event->x()-10; + int w=90; + int h=32; + int y=rtop+event->y()-42; - graph->renderText(z,event->x(),rtop+y); + //TODO: Convert this to a ToolTip class + + graph->quads()->add(x,y,x,y+h,col); + graph->quads()->add(x+w,y+h,x+w,y,col); + QColor blk(0,0,0,255); + + // The outer lines stuffs up + GLBuffer *lines=graph->lines(); // toplines? + lines->add(x-1,y-1,x+w+1,y-1,blk); + lines->add(x-1,y+h+1,x+w+1,y+h+1,blk); + lines->add(x-1,y-1,x-1,y+h+1,blk); + lines->add(x+w+1,y-1,x+w+1,y+h+1,blk); + + + QDateTime dt=QDateTime::fromTime_t(hl_day*86400); + QString z=dt.date().toString(Qt::SystemLocaleShortDate); + graph->renderText(z,event->x(),y+11); + z=m_label+"="+QString::number(d.value()[0],'f',2); + qstatus2->setText(z); + graph->renderText(z,event->x(),y+26); return true; } diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index 2dd1e967..4847b610 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -2,6 +2,7 @@ #include #include "gGraphView.h" #include "SleepLib/profiles.h" +#include bool _graph_init=false; QFont * defaultfont=NULL; @@ -567,8 +568,9 @@ void gGraph::paint(int originX, int originY, int width, int height) } if (m_selection.width()>0 && m_selecting_area) { - m_quad->add(originX+m_selection.x(),originY+top, originX+m_selection.x()+m_selection.width(),originY+top); - m_quad->add(originX+m_selection.x()+m_selection.width(),originY+height-top-bottom, originX+m_selection.x(),originY+height-top-bottom); + QColor col(128,128,255,128); + quads()->add(originX+m_selection.x(),originY+top, originX+m_selection.x()+m_selection.width(),originY+top,col); + quads()->add(originX+m_selection.x()+m_selection.width(),originY+height-top-bottom, originX+m_selection.x(),originY+height-top-bottom,col); } } @@ -581,6 +583,7 @@ void gGraph::AddLayer(Layer * l,LayerPosition position, short width, short heigh m_layers.push_back(l); } void gGraph::redraw() { m_graphview->updateGL(); } +void gGraph::timedRedraw(int ms) { m_graphview->timedRedraw(ms); } void gGraph::mouseMoveEvent(QMouseEvent * event) { @@ -595,6 +598,7 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) bool nolayer=false; + bool doredraw=false; if (m_graphview->m_selected_graph==this) { if (event->buttons() & Qt::LeftButton) { @@ -605,8 +609,9 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) if (a2>w) a2=w; m_selecting_area=true; m_selection=QRect(a1-m_marginleft-1,0,a2-a1,m_lastbounds.height()); - m_graphview->updateGL(); - nolayer=true; + //m_graphview->updateGL(); + nolayer=false; + doredraw=true; } else if (event->buttons() & Qt::RightButton) { m_graphview->setPointClicked(event->pos()); x-=left+m_marginleft; @@ -633,7 +638,8 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) min_x=rmax_x-xx; } //if (a2>rmax_x) a2=rmax_x; - m_graphview->SetXBounds(min_x,max_x,m_group); + m_graphview->SetXBounds(min_x,max_x,m_group,false); + doredraw=true; nolayer=true; } else { qint64 qq=rmax_x-rmin_x; @@ -652,21 +658,21 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) max_x=rmax_x; min_x=rmax_x-xx; } - m_graphview->SetXBounds(min_x,max_x,m_group); + m_graphview->SetXBounds(min_x,max_x,m_group,false); + doredraw=true; nolayer=true; } } } - if (!nolayer) { // no mouse button - bool doredraw=false; + //if (!nolayer) { // no mouse button for (int i=0;imouseMoveEvent(event)) doredraw=true; } if (doredraw) m_graphview->updateGL(); - } + //} //if (x>left+m_marginleft && xtop+m_margintop && ygroup()==group) @@ -1220,13 +1226,13 @@ void gGraphView::ResetBounds() //short group) updateScale(); } -void gGraphView::SetXBounds(qint64 minx, qint64 maxx,short group) +void gGraphView::SetXBounds(qint64 minx, qint64 maxx,short group,bool refresh) { for (int i=0;igroup()==group) m_graphs[i]->SetXBounds(minx,maxx); } - updateGL(); + if (refresh) updateGL(); } void gGraphView::updateScale() { @@ -1692,6 +1698,15 @@ void gGraphView::setDay(Day * day) m_graphs[i]->setDay(day); } } +void gGraphView::TimedRefresh() +{ + updateGL(); +} +void gGraphView::timedRedraw(int ms) +{ + QTimer::singleShot(ms,this,SLOT(TimedRefresh())); +} + MyScrollBar::MyScrollBar(QWidget * parent) :QScrollBar(parent) diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index d08195a6..43417c4b 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -256,6 +256,8 @@ public: gThread * thread() { return m_thread; } virtual void paint(int originX, int originY, int width, int height); void redraw(); + void timedRedraw(int ms); + void threadDone(); bool threadRunning() { return m_thread->isRunning(); } void threadStart() { if (!m_thread->isRunning()) m_thread->start(); } @@ -314,8 +316,8 @@ public: float scaleY() { return m_scaleY; } - void ResetBounds(); //short group=0); - void SetXBounds(qint64 minx, qint64 maxx, short group=0); + void ResetBounds(bool refresh=true); //short group=0); + void SetXBounds(qint64 minx, qint64 maxx, short group=0,bool refresh=true); bool hasGraphs() { return m_graphs.size()>0; } @@ -323,6 +325,7 @@ public: QPoint globalPointClicked() { return m_global_point_clicked; } void setPointClicked(QPoint p) { m_point_clicked=p; } void setGlobalPointClicked(QPoint p) { m_global_point_clicked=p; } + void timedRedraw(int ms); gGraph *m_selected_graph; @@ -395,6 +398,7 @@ signals: public slots: void scrollbarValueChanged(int val); + void TimedRefresh(); }; #endif // GGRAPHVIEW_H