]> sigrok.org Git - pulseview.git/blobdiff - pv/view/trace.cpp
Trace: Make popup forms compatible with OSX
[pulseview.git] / pv / view / trace.cpp
index fd6107f63acc9e643518226525593b012ac61485..87d3dc1dc095fa7ebd7b1dd2b7dba0bf5c255c8e 100644 (file)
@@ -41,8 +41,9 @@ namespace view {
 const QPen Trace::AxisPen(QColor(0, 0, 0, 30*256/100));
 const int Trace::LabelHitPadding = 2;
 
-const QColor Trace::DarkBGColour(235, 235, 235);    // Quite light grey
-const QColor Trace::BrightBGColour(245, 245, 245);  // Very light grey
+const int Trace::ColourBGAlpha = 8*256/100;
+const QColor Trace::BrightGrayBGColour = QColor(0, 0, 0, 10*255/100);
+const QColor Trace::DarkGrayBGColour = QColor(0, 0, 0, 15*255/100);
 
 Trace::Trace(QString name) :
        name_(name),
@@ -72,7 +73,7 @@ void Trace::set_colour(QColor colour)
        colour_ = colour;
 
        bgcolour_ = colour;
-       bgcolour_.setAlpha(20);
+       bgcolour_.setAlpha(ColourBGAlpha);
 }
 
 void Trace::set_coloured_bg(bool state)
@@ -180,7 +181,7 @@ void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
        if (coloured_bg_)
                p.setBrush(bgcolour_);
        else
-               p.setBrush(bgcolour_state_ ? BrightBGColour : DarkBGColour);
+               p.setBrush(bgcolour_state_ ? BrightGrayBGColour : DarkGrayBGColour);
 
        p.setPen(QPen(Qt::NoPen));
 
@@ -223,10 +224,14 @@ void Trace::create_popup_form()
        // Clear the layout
 
        // Transfer the layout and the child widgets to a temporary widget
-       // which then goes out of scope destroying the layout and all the child
-       // widgets.
-       if (popup_form_)
-               QWidget().setLayout(popup_form_);
+       // which we delete after the event was handled. This way, the layout
+       // and all widgets contained therein are deleted after the event was
+       // handled, leaving the parent popup_ time to handle the change.
+       if (popup_form_) {
+               QWidget *suicidal = new QWidget();
+               suicidal->setLayout(popup_form_);
+               suicidal->deleteLater();
+       }
 
        // Repopulate the popup
        popup_form_ = new QFormLayout(popup_);