From 562cd9cc37af2e997533f00a4b095b75c98ac2fe Mon Sep 17 00:00:00 2001
From: LoudSnorer <Just4Me.1947@gmail.com>
Date: Sun, 21 Mar 2021 14:15:47 -0400
Subject: [PATCH] fix display issues for short span events

---
 oscar/Graphs/gFlagsLine.cpp   | 16 +++++++++-------
 oscar/Graphs/gLineOverlay.cpp | 19 ++++++++++++++-----
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/oscar/Graphs/gFlagsLine.cpp b/oscar/Graphs/gFlagsLine.cpp
index 50f39e37..f4738c1f 100644
--- a/oscar/Graphs/gFlagsLine.cpp
+++ b/oscar/Graphs/gFlagsLine.cpp
@@ -366,23 +366,25 @@ void gFlagsLine::paint(QPainter &painter, gGraph &w, const QRegion &region)
 
                     x1 = double(X - minx) * xmult + left;
                     x2 = double(X2 - minx) * xmult + left;
+                    int width = x1-x2;
+                    width = qMax(2,width);    // Insure Rectangle will be visable. Flag events are 2 pixels wide.
 
                     brush = QBrush(color);
-                    painter.fillRect(x2, bartop, x1-x2, bottom-bartop, brush);
-                    if (!w.selectingArea() && !hover && QRect(x2, bartop, x1-x2, bottom-bartop).contains(w.graphView()->currentMousePos())) {
+                    painter.fillRect(x2, bartop, width, bottom-bartop, brush);
+                    if (!w.selectingArea() && !hover && QRect(x2, bartop, width , bottom-bartop).contains(w.graphView()->currentMousePos())) {
                         hover = true;
                         painter.setPen(QPen(Qt::red,1));
 
-                        painter.drawRect(x2, bartop, x1-x2, bottom-bartop);
+                        painter.drawRect(x2, bartop, width, bottom-bartop);
                         int x,y;
-                        int s = *dptr;
-                        int m = s / 60;
-                        s %= 60;
+                        double s = *dptr;
+                        double m;
+                        s=60*modf(s/60,&m);
                         QString lab = QString("%1").arg(schema::channel[m_code].fullname());
                         if (m>0) {
                             lab += QObject::tr(" (%2 min, %3 sec)").arg(m).arg(s);
                         } else {
-                            lab += QObject::tr(" (%3 sec)").arg(m).arg(s);
+                            lab += QObject::tr(" (%3 sec)").arg(s);
                         }
                         GetTextExtent(lab, x, y);
                         w.ToolTip(lab, x2 - 10, bartop + (3 * w.printScaleY()), TT_AlignRight, tooltipTimeout);
diff --git a/oscar/Graphs/gLineOverlay.cpp b/oscar/Graphs/gLineOverlay.cpp
index b6e1484f..ce42c37c 100644
--- a/oscar/Graphs/gLineOverlay.cpp
+++ b/oscar/Graphs/gLineOverlay.cpp
@@ -28,7 +28,6 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion &region)
     if (!schema::channel[m_code].enabled())
         return;
 
-
     int left = region.boundingRect().left();
     int topp = region.boundingRect().top(); // FIXME: Misspelling intentional.
     double width = region.boundingRect().width();
@@ -42,10 +41,12 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion &region)
 
     double xx = w.max_x - w.min_x;
     //double yy = w.max_y - w.min_y;
+
+    if (xx <= 0) { return; }
+
     double jj = width / xx;
 
 
-    if (xx <= 0) { return; }
 
     double x1, x2;
 
@@ -138,12 +139,20 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion &region)
                     x1 = jj * double(X - w.min_x);
                     x2 = jj * double(Y - w.min_x);
 
-                    x2 += (int(x1)==int(x2)) ? 1 : 0;
-
                     x2 = qMax(0.0, x2)+left;
                     x1 = qMin(width, x1)+left;
 
-                    painter.fillRect(QRect(x2, start_py, x1-x2, height), brush);
+                    // x2 represents the begining of a span in pixels
+                    // x1 represent the end of the span in pixels
+                    // BUG HERE
+                    //x2 += (int(x1)==int(x2)) ? 1 : 0;
+                    // Fixed BY 
+                    int duration = x1-x2;
+                    if (duration<2) duration=2;     // display minial span with 2 pixels.
+                    x2 =x1-duration;
+
+                    painter.fillRect(QRect(x2, start_py, duration, height), brush);
+
                 }
             }/* else if (m_flt == FT_Dot) {
                 ////////////////////////////////////////////////////////////////////////////