From 26d472fc50c3bfb3536bd4a12db2209e868ab659 Mon Sep 17 00:00:00 2001
From: Mark Watkins <jedimark@users.sourceforge.net>
Date: Mon, 4 Jul 2011 21:37:26 +1000
Subject: [PATCH] Changing computers

---
 Graphs/gLineChart.cpp  |  3 +--
 Graphs/graphwindow.cpp | 50 ++++++++++++++++++++++++++++++++++++----
 Graphs/graphwindow.h   |  8 ++++++-
 daily.cpp              | 52 ++++++++++++++++++++++++------------------
 daily.h                |  2 +-
 daily.ui               | 33 +++++++++++++++++++++++----
 docs/index.html        |  4 +---
 overview.ui            | 10 ++++++++
 8 files changed, 125 insertions(+), 37 deletions(-)

diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp
index 2085ef37..4b766031 100644
--- a/Graphs/gLineChart.cpp
+++ b/Graphs/gLineChart.cpp
@@ -250,9 +250,8 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry)
                 // m_drawlist's index is the pixel index for the X pixel axis.
 
                 //float zz=(maxy-miny)/2.0;  // centreline
-                float jy=point[i].y();
 
-                int y1=1+(jy-miny)*ymult;
+                int y1=1+(point[i].y()-miny)*ymult;
 
                 int z=floor(px); // Hmmm... round may screw this up.
                 if (z<minz) minz=z;  // minz=First pixel
diff --git a/Graphs/graphwindow.cpp b/Graphs/graphwindow.cpp
index 8cbcb76b..9679953c 100644
--- a/Graphs/graphwindow.cpp
+++ b/Graphs/graphwindow.cpp
@@ -12,11 +12,14 @@
 gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLWidget * shared,Qt::WindowFlags f)
 : QGLWidget(parent,shared, f )
 {
+    splitter=NULL;
     m_scrX   = m_scrY   = 100;
     m_title=title;
     m_mouseRDown=m_mouseLDown=false;
     m_block_zoom=false;
     m_drag_foobar=false;
+    m_dragGraph=false;
+
     m_gradient_background=true;
     m_foobar_pos=0;
     m_foobar_moved=0;
@@ -27,7 +30,8 @@ gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLWidget * s
     if (!title.isEmpty()) {
         AddLayer(new gTitle(title));
     }
-
+    //setAcceptDrops(true);
+    setMouseTracking(true);
 }
 
 gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLContext * context,Qt::WindowFlags f)
@@ -40,6 +44,7 @@ gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLContext *
     SetMargins(10, 15, 0, 0);
     m_block_zoom=false;
     m_drag_foobar=false;
+    m_dragGraph=false;
     m_gradient_background=false;
     m_foobar_pos=0;
     m_foobar_moved=0;
@@ -50,6 +55,8 @@ gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLContext *
     if (!title.isEmpty()) {
         AddLayer(new gTitle(title));
     }
+    //setAcceptDrops(true);
+    setMouseTracking(true);
 }
 
 gGraphWindow::~gGraphWindow()
@@ -227,13 +234,17 @@ void gGraphWindow::ZoomX(double mult,int origin_px)
 }
 gGraphWindow *LastGraphLDown=NULL;
 gGraphWindow *LastGraphRDown=NULL;
-
+gGraphWindow *currentWidget=NULL;
 void gGraphWindow::mouseMoveEvent(QMouseEvent * event)
 {
 //    static bool first=true;
     static QRect last;
-
     // grabbed
+    if (m_dragGraph) {
+        if (LastGraphLDown!=this)
+            currentWidget=this;
+        return;
+    }
     if (m_mouseLDown && LastGraphLDown && (LastGraphLDown!=this)) {
         LastGraphLDown->mouseMoveEvent(event);
         return;
@@ -389,7 +400,6 @@ void gGraphWindow::OnMouseRightDown(QMouseEvent * event)
             m_drag_foobar=true;
             LastGraphRDown=this;
             return;
-            //   wxLogMessage("Foobar Area Pushed");
         } else {
             m_drag_foobar=false;
             m_mouseRDown=false;
@@ -499,6 +509,18 @@ void gGraphWindow::OnMouseLeftDown(QMouseEvent * event)
 {
     int y=event->y();
     int x=event->x();
+
+    if (x<GetLeftMargin()) {
+        LastGraphLDown=this;
+        m_dragGraph=true;
+  /*      QDrag *drag = new QDrag(this);
+        QMimeData *mimeData = new QMimeData;
+        mimeData->setText("BiteMe");
+        drag->setMimeData(mimeData);
+
+        Qt::DropAction dropAction = drag->exec(); */
+        return;
+    }
     int width=m_scrX-GetRightMargin()-GetLeftMargin();
     int height=m_scrY-GetBottomMargin()-GetTopMargin();
     QRect hot1(GetLeftMargin(),GetTopMargin(),width,height); // Graph data area.
@@ -531,8 +553,28 @@ void gGraphWindow::OnMouseLeftDown(QMouseEvent * event)
         LastGraphLDown=this;
     }
 }
+void gGraphWindow::dropEvent ( QDropEvent * event )
+{
+    int frong=23;
+    assert(splitter!=NULL);
+    //m_dragGraph=false;
+}
+
 void gGraphWindow::OnMouseLeftRelease(QMouseEvent * event)
 {
+    if (m_dragGraph) {
+        if (splitter && currentWidget && LastGraphLDown) {
+            if (LastGraphLDown!=currentWidget) {
+                int newidx=splitter->indexOf(currentWidget);
+                int idx=splitter->indexOf(LastGraphLDown);
+                splitter->insertWidget(newidx,LastGraphLDown);
+                return;
+            }
+        }
+        m_dragGraph=false;
+        return;
+    }
+
     if (LastGraphLDown && (LastGraphLDown!=this)) { // Same graph that initiated the click??
         LastGraphLDown->OnMouseLeftRelease(event);  // Nope.. Give it the event.
         return;
diff --git a/Graphs/graphwindow.h b/Graphs/graphwindow.h
index 6682adfa..f6288c8b 100644
--- a/Graphs/graphwindow.h
+++ b/Graphs/graphwindow.h
@@ -9,6 +9,7 @@
 
 #include <QGLContext>
 #include <QGLWidget>
+#include <QSplitter>
 #include <QDateTime>
 #include <list>
 using namespace std;
@@ -31,7 +32,7 @@ public:
 
 signals:
 public slots:
-
+    void dropEvent(QDropEvent * event);
 public:
     QBitmap * RenderBitmap(int width,int height);
 
@@ -141,15 +142,20 @@ public:
       void SetGradientBackground(bool b) { m_gradient_background=b; };
       bool GradientBackground() { return m_gradient_background; };
 
+      void SetSplitter(QSplitter *s) { splitter=s; };
+      bool isDraggingGraph() { return m_dragGraph; };
   protected:
       void initializeGL();
+      QSplitter *splitter;
       list<gGraphWindow *>link_zoom;
       //list<gGraphWindow *>link_move;
 
       //bool m_block_move;
       bool m_block_zoom;
       bool m_drag_foobar;
+      bool m_dragGraph;
       double m_foobar_pos,m_foobar_moved;
+
       bool m_gradient_background;
       std::list<gLayer *> layers;
       QString m_title;
diff --git a/daily.cpp b/daily.cpp
index ed55ca16..6eba2abc 100644
--- a/daily.cpp
+++ b/daily.cpp
@@ -66,7 +66,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddCPAPData(flags[8]=new FlagData(PRS1_Unknown0E,1));
     AddCPAPData(flags[9]=new FlagData(CPAP_Snore,1)); // Snore Index
 
-    AddGraph(SF=new gGraphWindow(gSplitter,tr("Event Flags"),(QGLWidget *)NULL));
+    SF=new gGraphWindow(gSplitter,tr("Event Flags"),(QGLWidget *)NULL);
 
     SF->SetLeftMargin(SF->GetLeftMargin()+gYAxis::Margin);
     SF->SetBlockZoom(true);
@@ -93,7 +93,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddCPAPData(pressure_iap=new EventData(CPAP_IAP));
     AddCPAPData(pressure_eap=new EventData(CPAP_EAP));
     AddCPAPData(prd=new EventData(CPAP_Pressure));
-    AddGraph(PRD=new gGraphWindow(gSplitter,tr("Pressure"),SF));
+    PRD=new gGraphWindow(gSplitter,tr("Pressure"),SF);
     PRD->AddLayer(new gXAxis());
     PRD->AddLayer(new gYAxis());
     //PRD->AddLayer(new gFooBar());
@@ -106,7 +106,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddCPAPData(leakdata=new EventData(CPAP_Leak,0));
     //leakdata->ForceMinY(0);
     //leakdata->ForceMaxY(120);
-    AddGraph(LEAK=new gGraphWindow(gSplitter,tr("Leaks"),SF));
+    LEAK=new gGraphWindow(gSplitter,tr("Leaks"),SF);
     LEAK->AddLayer(new gXAxis());
     LEAK->AddLayer(new gYAxis());
     //LEAK->AddLayer(new gFooBar());
@@ -118,7 +118,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddCPAPData(frw=new WaveData(CPAP_FlowRate,1000000)); //FlowRate
    // AddCPAPData(mpw=new WaveData(CPAP_MaskPressure,700000)); //FlowRate
     // Holy crap resmed stuff is huge..
-    AddGraph(FRW=new gGraphWindow(gSplitter,tr("Flow Rate"),SF));
+    FRW=new gGraphWindow(gSplitter,tr("Flow Rate"),SF);
     //FRW->AddLayer(new gFooBar());
     FRW->AddLayer(new gYAxis());
     FRW->AddLayer(new gXAxis());
@@ -139,14 +139,14 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     FRW->setMinimumHeight(190);
 
     AddCPAPData(snore=new EventData(CPAP_Snore,0));
-    AddGraph(SNORE=new gGraphWindow(gSplitter,tr("Snore"),SF));
+    SNORE=new gGraphWindow(gSplitter,tr("Snore"),SF);
     SNORE->AddLayer(new gXAxis());
     SNORE->AddLayer(new gYAxis());
     SNORE->AddLayer(new gLineChart(snore,Qt::black,4096,false,false,true));
     SNORE->setMinimumHeight(150);
 
     AddCPAPData(flg=new EventData(CPAP_FlowLimitGraph,0));
-    AddGraph(FLG=new gGraphWindow(gSplitter,tr("Flow Limitation"),SF));
+    FLG=new gGraphWindow(gSplitter,tr("Flow Limitation"),SF);
     FLG->AddLayer(new gXAxis());
     FLG->AddLayer(new gYAxis());
     FLG->AddLayer(new gLineChart(flg,Qt::black,4096,false,false,true));
@@ -154,21 +154,21 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
 
 
     AddCPAPData(mv=new WaveData(CPAP_MinuteVentilation));
-    AddGraph(MV=new gGraphWindow(gSplitter,tr("Minute Ventilation"),SF));
+    MV=new gGraphWindow(gSplitter,tr("Minute Ventilation"),SF);
     MV->AddLayer(new gXAxis());
     MV->AddLayer(new gYAxis());
     MV->AddLayer(new gLineChart(mv,QColor(0x20,0x20,0x7f),65536,false,false,false));
     MV->setMinimumHeight(150);
 
     AddCPAPData(tv=new WaveData(CPAP_TidalVolume));
-    AddGraph(TV=new gGraphWindow(gSplitter,tr("Tidal Volume"),SF));
+    TV=new gGraphWindow(gSplitter,tr("Tidal Volume"),SF);
     TV->AddLayer(new gXAxis());
     TV->AddLayer(new gYAxis());
     TV->AddLayer(new gLineChart(tv,QColor(0x7f,0x20,0x20),65536,false,false,false));
     TV->setMinimumHeight(150);
 
     AddCPAPData(rr=new WaveData(CPAP_RespiratoryRate));
-    AddGraph(RR=new gGraphWindow(gSplitter,tr("Respiratory Rate"),SF));
+    RR=new gGraphWindow(gSplitter,tr("Respiratory Rate"),SF);
     RR->AddLayer(new gXAxis());
     RR->AddLayer(new gYAxis());
     RR->AddLayer(new gLineChart(rr,Qt::gray,65536,false,false,false));
@@ -178,7 +178,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddOXIData(pulse=new EventData(OXI_Pulse,0,65536,true));
     //pulse->ForceMinY(40);
     //pulse->ForceMaxY(120);
-    AddGraph(PULSE=new gGraphWindow(gSplitter,tr("Pulse & SpO2"),SF));
+    PULSE=new gGraphWindow(gSplitter,tr("Pulse & SpO2"),SF);
     PULSE->AddLayer(new gXAxis());
     PULSE->AddLayer(new gYAxis());
    // PULSE->AddLayer(new gFooBar());
@@ -189,7 +189,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     AddOXIData(spo2=new EventData(OXI_SPO2,0,65536,true));
     //spo2->ForceMinY(60);
     //spo2->ForceMaxY(100);
-//    AddGraph(SPO2=new gGraphWindow(gSplitter,tr("SpO2"),SF));
+//    SPO2=new gGraphWindow(gSplitter,tr("SpO2"),SF);
 //    SPO2->AddLayer(new gXAxis());
 //    SPO2->AddLayer(new gYAxis());
    // SPO2->AddLayer(new gFooBar());
@@ -333,18 +333,18 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
     FLG->LinkZoom(RR);
 
 
-    gSplitter->addWidget(SF);
-    gSplitter->addWidget(FRW);
-    gSplitter->addWidget(MV);
-    gSplitter->addWidget(TV);
-    gSplitter->addWidget(RR);
-    gSplitter->addWidget(PRD);
-    gSplitter->addWidget(LEAK);
-    gSplitter->addWidget(FLG);
-    gSplitter->addWidget(SNORE);
     gSplitter->addWidget(NoData);
-    gSplitter->addWidget(PULSE);
-  //  gSplitter->addWidget(SPO2);
+    AddGraph(SF);
+    AddGraph(FRW);
+    AddGraph(MV);
+    AddGraph(TV);
+    AddGraph(RR);
+    AddGraph(PRD);
+    AddGraph(LEAK);
+    AddGraph(FLG);
+    AddGraph(SNORE);
+    AddGraph(PULSE);
+  //  AddGraph(SPO2);
     gSplitter->refresh();
 
 
@@ -371,6 +371,14 @@ Daily::~Daily()
     delete gSplitter;
     delete ui;
 }
+void Daily::AddGraph(gGraphWindow *w)
+{
+    Graphs.push_back(w);
+
+    gSplitter->addWidget(w);
+    w->SetSplitter(gSplitter);
+}
+
 void Daily::ReloadGraphs()
 {
     QDate d=profile->LastDay();
diff --git a/daily.h b/daily.h
index 06b76a7e..c7b4fcd4 100644
--- a/daily.h
+++ b/daily.h
@@ -68,7 +68,7 @@ private:
 
     void AddCPAPData(gPointData *d) { CPAPData.push_back(d); };
     void AddOXIData(gPointData *d) { OXIData.push_back(d); };
-    void AddGraph(gGraphWindow *w) { Graphs.push_back(w); };
+    void AddGraph(gGraphWindow *w);
     void UpdateCPAPGraphs(Day *day);
     void UpdateOXIGraphs(Day *day);
 
diff --git a/daily.ui b/daily.ui
index b096de1e..efffd290 100644
--- a/daily.ui
+++ b/daily.ui
@@ -40,7 +40,7 @@
      <widget class="QSplitter" name="splitter">
       <property name="maximumSize">
        <size>
-        <width>280</width>
+        <width>265</width>
         <height>16777215</height>
        </size>
       </property>
@@ -62,7 +62,7 @@
        </property>
        <property name="maximumSize">
         <size>
-         <width>280</width>
+         <width>265</width>
          <height>180</height>
         </size>
        </property>
@@ -89,6 +89,12 @@
        </property>
       </widget>
       <widget class="QTabWidget" name="tabWidget">
+       <property name="maximumSize">
+        <size>
+         <width>265</width>
+         <height>16777215</height>
+        </size>
+       </property>
        <property name="font">
         <font>
          <family>Sans Serif</family>
@@ -96,7 +102,7 @@
         </font>
        </property>
        <property name="currentIndex">
-        <number>0</number>
+        <number>2</number>
        </property>
        <property name="movable">
         <bool>true</bool>
@@ -313,6 +319,25 @@
          </property>
          <item>
           <layout class="QVBoxLayout" name="verticalLayout_11">
+           <item>
+            <widget class="QLabel" name="label_6">
+             <property name="frameShape">
+              <enum>QFrame::StyledPanel</enum>
+             </property>
+             <property name="frameShadow">
+              <enum>QFrame::Sunken</enum>
+             </property>
+             <property name="text">
+              <string>This tab is fake.. What to put here?</string>
+             </property>
+             <property name="scaledContents">
+              <bool>false</bool>
+             </property>
+             <property name="alignment">
+              <set>Qt::AlignCenter</set>
+             </property>
+            </widget>
+           </item>
            <item>
             <layout class="QHBoxLayout" name="horizontalLayout">
              <property name="spacing">
@@ -465,7 +490,7 @@
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>748</width>
+         <width>763</width>
          <height>620</height>
         </rect>
        </property>
diff --git a/docs/index.html b/docs/index.html
index 170bce6c..f5227107 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -28,9 +28,7 @@ p,a,td,body { font-size: 14px }
 <hr>
 <p><b>Copyright:</b> &copy;2011 Mark Watkins (jedimark)</p>
 <p><b>License:</b> This software is released freely under the GNU Public License.</p>
-<p><i>This software comes with absolutely no warranty, either express of implied. It comes with no guarantee of fitness for any particular purpose.
-No guarantees are made to the accuracy or usefulness of any data displayed.</i></p>
-<p><b>It would very unwise to rely soley on this software when making medical decisions. Talk to your doctor.</b></p>
+<p><b>It would very unwise to rely solely on this software when making medical decisions. Talk to your doctor.</b></p>
 </td></tr>
 </table>
 </body>
diff --git a/overview.ui b/overview.ui
index 7e7836fd..9844d29a 100644
--- a/overview.ui
+++ b/overview.ui
@@ -40,6 +40,16 @@
         <string>Summary</string>
        </attribute>
        <layout class="QVBoxLayout" name="verticalLayout_3">
+        <item>
+         <widget class="QLabel" name="label">
+          <property name="text">
+           <string>This whole page is still being figured out.</string>
+          </property>
+          <property name="wordWrap">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
         <item>
          <widget class="QWebView" name="webView">
           <property name="minimumSize">