From de1f63b6412e3dc5f51dd70e8964996a6000938b Mon Sep 17 00:00:00 2001
From: LoudSnorer <just4me.1947@gmail.com>
Date: Sat, 4 Mar 2023 10:14:21 -0500
Subject: [PATCH] added hise-show button the daily events combo && cleanup -
 removed unused toggle code & ui

---
 oscar/daily.cpp | 132 ++++++++++++++++++++++++------------------------
 oscar/daily.h   |  12 +++--
 oscar/daily.ui  |  73 --------------------------
 3 files changed, 72 insertions(+), 145 deletions(-)

diff --git a/oscar/daily.cpp b/oscar/daily.cpp
index 545104f4..f3314df5 100644
--- a/oscar/daily.cpp
+++ b/oscar/daily.cpp
@@ -1008,17 +1008,7 @@ void Daily::ResetGraphOrder(int type)
 
     // Enable all graphs (make them not hidden)
     showAllGraphs(true);
-
-    // Mark all events as active
-    for (int i=1;i<ui->eventsCombo->count();i++) {
-        // If disabled, emulate a click to enable the event
-        ChannelID code = ui->eventsCombo->itemData(i, Qt::UserRole).toUInt();
-        schema::Channel * chan = &schema::channel[code];
-        if (!chan->enabled()) {
-//            qDebug() << "resetting event" << i;
-            Daily::on_eventsCombo_activated(i);
-        }
-    }
+    showAllEvents(true);
 
     // Reset graph heights (and repaint)
     ResetGraphLayout();
@@ -1683,23 +1673,8 @@ void Daily::Load(QDate date)
     bool isBrick=false;
 
     updateGraphCombo();
-    ui->eventsCombo->clear();
 
-    quint32 chans = schema::SPAN | schema::FLAG | schema::MINOR_FLAG;
-    if (p_profile->general->showUnknownFlags()) chans |= schema::UNKNOWN;
-
-    QList<ChannelID> available;
-    if (day) available.append(day->getSortedMachineChannels(chans));
-
-    ui->eventsCombo->addItem(*icon_up_down, tr("10 of 10 Event Types"), 0); // Translation used only for spacing
-    for (int i=0; i < available.size(); ++i) {
-        ChannelID code = available.at(i);
-        int comboxBoxIndex = i+1;
-        schema::Channel & chan = schema::channel[code];
-        ui->eventsCombo->addItem(chan.enabled() ? *icon_on : * icon_off, chan.label(), code);
-        ui->eventsCombo->setItemData(comboxBoxIndex, chan.fullname(), Qt::ToolTipRole);
-    }
-    setFlagText();
+    updateEventsCombo(day);
 
     if (!cpap) {
         GraphView->setEmptyImage(QPixmap(":/icons/logo-md.png"));
@@ -1926,9 +1901,6 @@ void Daily::Load(QDate date)
     ui->BMI->setVisible(false);
     ui->BMIlabel->setVisible(false);
 #endif
-    ui->toggleGraphs->setVisible(false);
-    ui->toggleEvents->setVisible(false);
-
     BookmarksChanged=false;
     Session *journal=GetJournalSession(date);
     if (journal) {
@@ -2664,13 +2636,13 @@ void Daily::setGraphText () {
     if (numOff == 0) {
         // all graphs are shown
         graphText = QObject::tr("%1 Graphs").arg(numTotal);
-        ui->graphCombo->setItemText(lastIndex,STR_HIDE_ALL);
+        ui->graphCombo->setItemText(lastIndex,STR_HIDE_ALL_GRAPHS);
     } else {
         // some graphs are hidden
         graphText = QObject::tr("%1 of %2 Graphs").arg(numTotal-numOff).arg(numTotal);
         if (numOff == numTotal) {
             // all graphs are hidden
-            ui->graphCombo->setItemText(lastIndex,STR_SHOW_ALL);
+            ui->graphCombo->setItemText(lastIndex,STR_SHOW_ALL_GRAPHS);
         }
     }
     ui->graphCombo->setItemText(0, graphText);
@@ -2680,7 +2652,8 @@ void Daily::setFlagText () {
     int numOff = 0;
     int numTotal = 0;
 
-    for (int i=1; i < ui->eventsCombo->count(); ++i) {
+    int lastIndex = ui->eventsCombo->count()-1;  // account for hideshow button
+    for (int i=1; i < lastIndex; ++i) {
         numTotal++;
         ChannelID code = ui->eventsCombo->itemData(i, Qt::UserRole).toUInt();
         schema::Channel * chan = &schema::channel[code];
@@ -2691,8 +2664,14 @@ void Daily::setFlagText () {
 
     ui->eventsCombo->setItemIcon(0, numOff ? *icon_warning : *icon_up_down);
     QString flagsText;
-    if (numOff == 0) flagsText = (QObject::tr("%1 Event Types")+"       ").arg(numTotal);
-    else             flagsText = QObject::tr("%1 of %2 Event Types").arg(numTotal-numOff).arg(numTotal);
+    if (numOff == 0) {
+        flagsText = (QObject::tr("%1 Event Types")+"       ").arg(numTotal);
+        ui->eventsCombo->setItemText(lastIndex,STR_HIDE_ALL_EVENTS);
+    } else {
+        int numOn=numTotal-numOff;
+        flagsText = QObject::tr("%1 of %2 Event Types").arg(numOn).arg(numTotal);
+        if (numOn==0) ui->eventsCombo->setItemText(lastIndex,STR_SHOW_ALL_EVENTS);
+    }
     ui->eventsCombo->setItemText(0, flagsText);
 }
 
@@ -2743,13 +2722,6 @@ void Daily::updateCube()
 {
     //brick..
     if ((GraphView->visibleGraphs()==0)) {
-        ui->toggleGraphs->setVisible(false);
-//        ui->toggleGraphs->setArrowType(Qt::UpArrow);
-//        ui->toggleGraphs->setToolTip(tr("Show all graphs"));
-//        ui->toggleGraphs->blockSignals(true);
-//        ui->toggleGraphs->setChecked(true);
-//        ui->toggleGraphs->blockSignals(false);
-
         if (ui->graphCombo->count() > 0) {
             GraphView->setEmptyText(STR_Empty_NoGraphs);
         } else {
@@ -2764,34 +2736,16 @@ void Daily::updateCube()
                     GraphView->setEmptyText(STR_Empty_SummaryOnly);
             }
         }
-    } else {
-        ui->toggleGraphs->setVisible(false);
-//        ui->toggleGraphs->setArrowType(Qt::DownArrow);
-//        ui->toggleGraphs->setToolTip(tr("Hide all graphs"));
-//        ui->toggleGraphs->blockSignals(true);
-//        ui->toggleGraphs->setChecked(false);
-//        ui->toggleGraphs->blockSignals(false);
     }
 }
 
 
-void Daily::on_toggleGraphs_clicked(bool /*checked*/)
-{
-    //QString s;
-    //QIcon *icon=checked ? icon_off : icon_on;
-    if (ui->graphCombo == nullptr )
-        qDebug() << "ToggleGraphs clicked with null graphCombo ptr";
-    else
-        qDebug() << "ToggleGraphs clicked with non-null graphCombo ptr";
-    return;
-}
-
 void Daily::updateGraphCombo()
 {
     ui->graphCombo->clear();
     gGraph *g;
 
-    ui->graphCombo->addItem(*icon_up_down, tr("10 of 10 Graphs"), true); // Translation only to define space required
+    ui->graphCombo->addItem(*icon_up_down, "", true);   // text updated in setGRaphText
 
     for (int i=0;i<GraphView->size();i++) {
         g=(*GraphView)[i];
@@ -2803,24 +2757,68 @@ void Daily::updateGraphCombo()
             ui->graphCombo->addItem(*icon_off,g->title(),false);
         }
     }
+    ui->graphCombo->addItem(*icon_on,STR_HIDE_ALL_GRAPHS,true);
     ui->graphCombo->setCurrentIndex(0);
-    ui->graphCombo->addItem(*icon_on,STR_HIDE_ALL,true);
     setGraphText();
     updateCube();
 }
 
+void Daily::updateEventsCombo(Day* day) {
+
+    quint32 chans = schema::SPAN | schema::FLAG | schema::MINOR_FLAG;
+    if (p_profile->general->showUnknownFlags()) chans |= schema::UNKNOWN;
+
+    QList<ChannelID> available;
+    if (day) available.append(day->getSortedMachineChannels(chans));
+
+    ui->eventsCombo->clear();
+    ui->eventsCombo->addItem(*icon_up_down, "", 0);   // text updated in setflagText
+    for (int i=0; i < available.size(); ++i) {
+        ChannelID code = available.at(i);
+        int comboxBoxIndex = i+1;
+        schema::Channel & chan = schema::channel[code];
+        ui->eventsCombo->addItem(chan.enabled() ? *icon_on : * icon_off, chan.label(), code);
+        ui->eventsCombo->setItemData(comboxBoxIndex, chan.fullname(), Qt::ToolTipRole);
+    }
+    ui->eventsCombo->addItem(*icon_on,"" , Qt::ToolTipRole);
+    ui->eventsCombo->setCurrentIndex(0);
+    setFlagText();
+}
+
+void Daily::showAllEvents(bool show) {
+    // Mark all events as active
+    int lastIndex = ui->eventsCombo->count()-1;  // account for hideshow button
+    for (int i=1;i<lastIndex;i++) {
+        // If disabled, emulate a click to enable the event
+        ChannelID code = ui->eventsCombo->itemData(i, Qt::UserRole).toUInt();
+        schema::Channel * chan = &schema::channel[code];
+        if (chan->enabled()!=show) {
+            Daily::on_eventsCombo_activated(i);
+        }
+    }
+    ui->eventsCombo->setItemData(lastIndex,show,Qt::UserRole);
+    ui->eventsCombo->setCurrentIndex(0);
+    setFlagText();
+}
+
 void Daily::on_eventsCombo_activated(int index)
 {
     if (index<0)
         return;
 
+    int lastIndex = ui->eventsCombo->count()-1;
     if (index > 0) {
-        ChannelID code = ui->eventsCombo->itemData(index, Qt::UserRole).toUInt();
-        schema::Channel * chan = &schema::channel[code];
+        if ( index == lastIndex ) {
+            bool nextOn =!ui->eventsCombo->itemData(index,Qt::UserRole).toBool();
+            showAllEvents(nextOn);
+        } else {
+            ChannelID code = ui->eventsCombo->itemData(index, Qt::UserRole).toUInt();
+            schema::Channel * chan = &schema::channel[code];
 
-        bool b = !chan->enabled();
-        chan->setEnabled(b);
-        ui->eventsCombo->setItemIcon(index,b ? *icon_on : *icon_off);
+            bool b = !chan->enabled();
+            chan->setEnabled(b);
+            ui->eventsCombo->setItemIcon(index,b ? *icon_on : *icon_off);
+        }
         ui->eventsCombo->showPopup();
     }
 
diff --git a/oscar/daily.h b/oscar/daily.h
index c0d5ccca..5dc319af 100644
--- a/oscar/daily.h
+++ b/oscar/daily.h
@@ -141,8 +141,13 @@ public:
 
     void showAllGraphs(bool show);
     void showGraph(int index,bool show, bool updateGraph=true);
-    QString STR_HIDE_ALL =QString(tr("Hide All"));
-    QString STR_SHOW_ALL =QString(tr("Show All"));
+    void showAllEvents(bool show);
+    void showEvent(int index,bool show, bool updateEvent=true);
+    void updateEventsCombo(Day*);
+    QString STR_HIDE_ALL_EVENTS =QString(tr("Hide All Events"));
+    QString STR_SHOW_ALL_EVENTS =QString(tr("Show All Events"));
+    QString STR_HIDE_ALL_GRAPHS =QString(tr("Hide All Graphs"));
+    QString STR_SHOW_ALL_GRAPHS =QString(tr("Show All Graphs"));
 
 public slots:
     void on_LineCursorUpdate(double time);
@@ -237,9 +242,6 @@ private slots:
 
     void on_graphCombo_activated(int index);
 
-    void on_toggleGraphs_clicked(bool checked);
-
-
 #ifndef REMOVE_FITNESS
     /*! \fn on_ouncesSpinBox_valueChanged(int arg1);
         \brief Called when the zombie slider has been moved.. Updates the BMI dislpay and journal objects.
diff --git a/oscar/daily.ui b/oscar/daily.ui
index 284d91f0..cdec6521 100644
--- a/oscar/daily.ui
+++ b/oscar/daily.ui
@@ -1475,44 +1475,6 @@ QSlider::handle:horizontal  {
           <property name="bottomMargin">
            <number>0</number>
           </property>
-          <item>
-           <widget class="QToolButton" name="toggleEvents">
-            <property name="styleSheet">
-             <string notr="true">QToolButton {
- background: transparent;
- border-radius: 8px;
- border: 2px solid transparent;
-}
-
-QToolButton:hover {
- border: 2px solid #456789;
-}
-
-QToolButton:pressed {
- border: 2px solid #456789;
- background-color: #89abcd;
-}</string>
-            </property>
-            <property name="text">
-             <string>Flags</string>
-            </property>
-            <property name="checkable">
-             <bool>true</bool>
-            </property>
-            <property name="checked">
-             <bool>true</bool>
-            </property>
-            <property name="toolButtonStyle">
-             <enum>Qt::ToolButtonTextBesideIcon</enum>
-            </property>
-            <property name="autoRaise">
-             <bool>false</bool>
-            </property>
-            <property name="arrowType">
-             <enum>Qt::DownArrow</enum>
-            </property>
-           </widget>
-          </item>
           <item>
            <widget class="QComboBox" name="eventsCombo">
             <property name="maxVisibleItems">
@@ -1527,41 +1489,6 @@ QToolButton:pressed {
             </property>
            </layout>
           </item>
-          <item>
-           <widget class="QToolButton" name="toggleGraphs">
-            <property name="styleSheet">
-             <string notr="true">QToolButton {
- background: transparent;
- border-radius: 8px;
- border: 2px solid transparent;
-}
-
-QToolButton:hover {
- border: 2px solid #456789;
-}
-
-QToolButton:pressed {
- border: 2px solid #456789;
- background-color: #89abcd;
-}</string>
-            </property>
-            <property name="text">
-             <string>Graphs</string>
-            </property>
-            <property name="checkable">
-             <bool>true</bool>
-            </property>
-            <property name="toolButtonStyle">
-             <enum>Qt::ToolButtonTextBesideIcon</enum>
-            </property>
-            <property name="autoRaise">
-             <bool>false</bool>
-            </property>
-            <property name="arrowType">
-             <enum>Qt::DownArrow</enum>
-            </property>
-           </widget>
-          </item>
           <item>
            <widget class="QPushButton" name="layout">
             <property name="text">