From 06e892b53b1f0b9ca5edae4e69dcfe46d770dad7 Mon Sep 17 00:00:00 2001
From: Mark Watkins <jedimark@users.sourceforge.net>
Date: Tue, 20 Dec 2011 13:22:45 +1000
Subject: [PATCH] Added compliance preference settings (in General)

---
 Graphs/gSummaryChart.cpp |  10 +-
 SleepLib/preferences.h   |   2 +-
 mainwindow.cpp           |   3 +
 preferencesdialog.cpp    |  16 ++-
 preferencesdialog.ui     | 233 +++++++++++++++++++++++++--------------
 5 files changed, 170 insertions(+), 94 deletions(-)

diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp
index 0aec3114..fc720b65 100644
--- a/Graphs/gSummaryChart.cpp
+++ b/Graphs/gSummaryChart.cpp
@@ -340,6 +340,10 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
         }
         lastY[i]=top+height-1-h;
     }
+    float compliance_hours=0;
+    if (PROFILE.ExistsAndTrue("ShowCompliance")) {
+        compliance_hours=PROFILE["ComplianceHours"].toDouble();
+    }
 
     Day * day;
     EventDataType hours;
@@ -366,7 +370,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
                 int j;
                 QHash<int,QHash<short,EventDataType> >::iterator times=m_times.find(zd);
                 QColor col=m_colors[0];
-                //if (hours<4) col=QColor("#f03030");
+                //if (hours<compliance_hours) col=QColor("#f03030");
 
                 if (zd==hl_day) {
                     col=QColor("gold");
@@ -416,9 +420,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
 
                     QColor col=m_colors[j];
                     if (m_type[j]==ST_HOURS) {
-                        if (tmp<4) {
-                            col=QColor("#f04040");
-                        }
+                        if (tmp<compliance_hours) col=QColor("#f04040");
                     }
 
                     if (zd==hl_day) {
diff --git a/SleepLib/preferences.h b/SleepLib/preferences.h
index 9ab75d3c..0d853902 100644
--- a/SleepLib/preferences.h
+++ b/SleepLib/preferences.h
@@ -121,7 +121,7 @@ protected:
     QString p_path;
 };
 
-enum PrefType { PT_Checkbox, PT_Integer, PT_Number, PT_Date, PT_Time, PT_DateTime, PT_LineEdit, PT_TextEdit, PT_Dropdown };
+enum PrefType { PT_Checkbox, PT_Spinbox, PT_Integer, PT_Number, PT_Date, PT_Time, PT_DateTime, PT_LineEdit, PT_TextEdit, PT_Dropdown };
 
 /*! \class Preference
     \brief Holds a single preference
diff --git a/mainwindow.cpp b/mainwindow.cpp
index bef5803b..66afe12f 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -103,6 +103,7 @@ MainWindow::MainWindow(QWidget *parent) :
 
     // This next section is a mess..
     // Preferences & Profile variables really need to initialize somewhere else
+    // The General object in PreferencesDialog kinda defines where I want to go with the profile default stuff
 
     if (!PROFILE.Exists("ShowDebug")) PROFILE["ShowDebug"]=false;
     ui->actionDebug->setChecked(PROFILE["ShowDebug"].toBool());
@@ -132,6 +133,8 @@ MainWindow::MainWindow(QWidget *parent) :
     if (!PROFILE.Exists("PulseChangeDuration")) PROFILE["PulseChangeDuration"]=8;
     if (!PROFILE.Exists("GraphHeight")) PROFILE["GraphHeight"]=180;
     if (!PROFILE.Exists("OxiDiscardThreshold")) PROFILE["OxiDiscardThreshold"]=10;
+    if (!PROFILE.Exists("ComplianceHours")) PROFILE["ComplianceHours"]=4;
+    if (!PROFILE.Exists("ShowCompliance")) PROFILE["ShowCompliance"]=true;
 
     //ui->actionUse_AntiAliasing->setChecked(PROFILE["UseAntiAliasing"].toBool());
     ui->action_Link_Graph_Groups->setChecked(PROFILE["LinkGroups"].toBool());
diff --git a/preferencesdialog.cpp b/preferencesdialog.cpp
index 4597d9b0..a894ddc0 100644
--- a/preferencesdialog.cpp
+++ b/preferencesdialog.cpp
@@ -168,10 +168,12 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) :
     general["SkipEmptyDays"]=Preference(p_profile,"SkipEmptyDays",PT_Checkbox,tr("Skip Empty Days"),tr("Skip over calendar days that don't have any data"),true);
     general["EnableMultithreading"]=Preference(p_profile,"EnableMultithreading",PT_Checkbox,tr("Enable Multithreading"),tr("Try to use extra processor cores where possible"),false);
     general["MemoryHog"]=Preference(p_profile,"MemoryHog",PT_Checkbox,tr("Cache Session Data"),tr("Keep session data in memory to improve load speed revisiting the date."),false);
-    general["GraphHeight"]=Preference(p_profile,"GraphHeight",PT_Checkbox,tr("Graph Height"),tr("Default Graph Height"),160);
-    general["MaskDescription"]=Preference(p_profile,"MaskDescription",PT_Checkbox,tr("Mask Description"),tr("Whatever you want to record about your mask."),QString());
-    general["HighResPrinting"]=Preference(p_profile,"HighResPrinting",PT_Checkbox,tr("High Resolution Printing"),tr("Use much slower but better quality high resolution printing."),QString());
-    general["EmptyGraphFun"]=Preference(p_profile,"EmptyGraphFun",PT_Checkbox,tr("Less Boring Empty Graph Pages"),tr("Make empty graph pages more attractive."),QString());
+    general["GraphHeight"]=Preference(p_profile,"GraphHeight",PT_Spinbox,tr("Graph Height"),tr("Default Graph Height"),160);
+    general["MaskDescription"]=Preference(p_profile,"MaskDescription",PT_LineEdit,tr("Mask Description"),tr("Whatever you want to record about your mask."),QString());
+    general["HighResPrinting"]=Preference(p_profile,"HighResPrinting",PT_Checkbox,tr("High Resolution Printing"),tr("Use much slower but better quality high resolution printing."),true);
+    general["EmptyGraphFun"]=Preference(p_profile,"EmptyGraphFun",PT_Checkbox,tr("Less Boring Empty Graph Pages"),tr("Make empty graph pages more attractive."),false);
+    general["ShowCompliance"]=Preference(p_profile,"ShowCompliance",PT_Checkbox,tr("Show Compliance Information"),tr("Allow compliance information to be shown."),true);
+    general["ComplianceHours"]=Preference(p_profile,"ComplianceHours",PT_Spinbox,tr("Compliance Hours"),tr("Regard days over this combined session length as compliant."),4.0);
 
     if (!(p_profile)->Exists("MaskStartDate")) {
         (PROFILE["MaskStartDate"]=PROFILE.FirstDay());
@@ -200,6 +202,9 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) :
     ui->enableMultithreading->setChecked(general["EnableMultithreading"].value().toBool());
     ui->cacheSessionData->setChecked(general["MemoryHog"].value().toBool());
     ui->lessBoringEmptyGraphPages->setChecked(general["EmptyGraphFun"].value().toBool());
+    ui->complianceGroupbox->setChecked(general["ShowCompliance"].value().toBool());
+    ui->complianceHours->setValue(general["ComplianceHours"].value().toDouble());
+
 #ifdef Q_WS_MAC
     general["HighResPrinting"].setValue(true);
     ui->highResolutionPrinting->setChecked(true);
@@ -329,6 +334,9 @@ void PreferencesDialog::Save()
     general["HighResPrinting"].setValue(ui->highResolutionPrinting->isChecked());
     general["EmptyGraphFun"].setValue(ui->lessBoringEmptyGraphPages->isChecked());
 
+    general["ShowCompliance"].setValue(ui->complianceGroupbox->isChecked());
+    general["ComplianceHours"].setValue(ui->complianceHours->value());
+
     (*profile)["MaskStartDate"]=ui->startedUsingMask->date();
     (*profile)["GraphHeight"]=ui->graphHeight->value();
 
diff --git a/preferencesdialog.ui b/preferencesdialog.ui
index da625d1e..2af24339 100644
--- a/preferencesdialog.ui
+++ b/preferencesdialog.ui
@@ -38,7 +38,7 @@
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>7</number>
+      <number>6</number>
      </property>
      <widget class="QWidget" name="importTab">
       <attribute name="title">
@@ -1171,6 +1171,12 @@ p, li { white-space: pre-wrap; }
           <string>General Settings</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_10">
+          <property name="margin">
+           <number>4</number>
+          </property>
+          <property name="spacing">
+           <number>4</number>
+          </property>
           <item row="0" column="0">
            <widget class="QCheckBox" name="skipLoginScreen">
             <property name="toolTip">
@@ -1232,6 +1238,70 @@ this application to be unstable with this feature enabled.</string>
          </layout>
         </widget>
        </item>
+       <item>
+        <widget class="QGroupBox" name="complianceGroupbox">
+         <property name="title">
+          <string>Show Compliance</string>
+         </property>
+         <property name="checkable">
+          <bool>true</bool>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_7">
+          <property name="margin">
+           <number>4</number>
+          </property>
+          <property name="spacing">
+           <number>4</number>
+          </property>
+          <item row="0" column="1">
+           <widget class="QDoubleSpinBox" name="complianceHours">
+            <property name="toolTip">
+             <string>Regard days with under this usage as &quot;incompliant&quot;.</string>
+            </property>
+            <property name="suffix">
+             <string> hours</string>
+            </property>
+            <property name="decimals">
+             <number>1</number>
+            </property>
+            <property name="maximum">
+             <double>8.000000000000000</double>
+            </property>
+            <property name="value">
+             <double>4.000000000000000</double>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="3">
+           <spacer name="horizontalSpacer_7">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item row="0" column="0">
+           <widget class="QLabel" name="label_39">
+            <property name="text">
+             <string>Define compliance as over</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="2">
+           <widget class="QLabel" name="label_40">
+            <property name="text">
+             <string>of usage per night</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
        <item>
         <spacer name="verticalSpacer_3">
          <property name="orientation">
@@ -1428,6 +1498,12 @@ this application to be unstable with this feature enabled.</string>
        <string>&amp;Appearance</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_11">
+       <property name="spacing">
+        <number>0</number>
+       </property>
+       <property name="margin">
+        <number>2</number>
+       </property>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_13">
          <item>
@@ -1435,92 +1511,73 @@ this application to be unstable with this feature enabled.</string>
            <property name="title">
             <string>General Settings</string>
            </property>
-           <layout class="QGridLayout" name="gridLayout_7">
-            <property name="leftMargin">
-             <number>0</number>
-            </property>
-            <property name="topMargin">
-             <number>4</number>
-            </property>
-            <property name="rightMargin">
-             <number>4</number>
-            </property>
-            <property name="bottomMargin">
-             <number>0</number>
-            </property>
-            <property name="spacing">
-             <number>0</number>
-            </property>
+           <layout class="QGridLayout" name="gridLayout_5">
             <item row="0" column="0">
-             <layout class="QGridLayout" name="gridLayout_5">
-              <item row="0" column="0">
-               <widget class="QLabel" name="label_18">
-                <property name="sizePolicy">
-                 <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
-                  <horstretch>0</horstretch>
-                  <verstretch>0</verstretch>
-                 </sizepolicy>
-                </property>
-                <property name="text">
-                 <string>Overlay Flags</string>
-                </property>
-               </widget>
-              </item>
-              <item row="0" column="1">
-               <widget class="QComboBox" name="overlayFlagsCombo">
-                <property name="sizePolicy">
-                 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-                  <horstretch>0</horstretch>
-                  <verstretch>0</verstretch>
-                 </sizepolicy>
-                </property>
-                <property name="toolTip">
-                 <string>The visual method of displaying waveform overlay flags.</string>
-                </property>
-                <item>
-                 <property name="text">
-                  <string>Standard Bars</string>
-                 </property>
-                </item>
-                <item>
-                 <property name="text">
-                  <string>Top &amp; Bottom Markers</string>
-                 </property>
-                </item>
-               </widget>
-              </item>
-              <item row="1" column="0">
-               <widget class="QLabel" name="label_26">
-                <property name="text">
-                 <string>Graph Height</string>
-                </property>
-               </widget>
-              </item>
-              <item row="1" column="1">
-               <widget class="QSpinBox" name="graphHeight">
-                <property name="sizePolicy">
-                 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
-                  <horstretch>0</horstretch>
-                  <verstretch>0</verstretch>
-                 </sizepolicy>
-                </property>
-                <property name="minimum">
-                 <number>50</number>
-                </property>
-                <property name="maximum">
-                 <number>600</number>
-                </property>
-                <property name="singleStep">
-                 <number>10</number>
-                </property>
-                <property name="value">
-                 <number>180</number>
-                </property>
-               </widget>
-              </item>
-             </layout>
+             <widget class="QLabel" name="label_18">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="text">
+               <string>Overlay Flags</string>
+              </property>
+             </widget>
             </item>
-            <item row="2" column="0">
+            <item row="0" column="1">
+             <widget class="QComboBox" name="overlayFlagsCombo">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="toolTip">
+               <string>The visual method of displaying waveform overlay flags.</string>
+              </property>
+              <item>
+               <property name="text">
+                <string>Standard Bars</string>
+               </property>
+              </item>
+              <item>
+               <property name="text">
+                <string>Top &amp; Bottom Markers</string>
+               </property>
+              </item>
+             </widget>
+            </item>
+            <item row="1" column="0">
+             <widget class="QLabel" name="label_26">
+              <property name="text">
+               <string>Graph Height</string>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="1">
+             <widget class="QSpinBox" name="graphHeight">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="minimum">
+               <number>50</number>
+              </property>
+              <property name="maximum">
+               <number>600</number>
+              </property>
+              <property name="singleStep">
+               <number>10</number>
+              </property>
+              <property name="value">
+               <number>180</number>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="0" colspan="2">
              <spacer name="verticalSpacer">
               <property name="orientation">
                <enum>Qt::Vertical</enum>
@@ -1589,9 +1646,15 @@ this application to be unstable with this feature enabled.</string>
           <property name="leftMargin">
            <number>0</number>
           </property>
+          <property name="topMargin">
+           <number>4</number>
+          </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
+          <property name="bottomMargin">
+           <number>4</number>
+          </property>
           <item>
            <layout class="QGridLayout" name="gridLayout_3">
             <item row="0" column="1">