]> sigrok.org Git - pulseview.git/commitdiff
Use alternating trace background colors when not using their own
authorSoeren Apel <redacted>
Mon, 28 Dec 2015 20:20:23 +0000 (21:20 +0100)
committerSoeren Apel <redacted>
Mon, 28 Dec 2015 20:20:23 +0000 (21:20 +0100)
pv/view/trace.cpp
pv/view/trace.hpp
pv/view/tracetreeitem.cpp
pv/view/tracetreeitem.hpp
pv/view/tracetreeitemowner.cpp
pv/view/tracetreeitemowner.hpp
pv/view/view.cpp

index 3727afa2de246912c8834dc0f3977d5131ec25bc..f7bba9ff31506e5a5fa68abaacfe1fe3163e321e 100644 (file)
@@ -41,6 +41,9 @@ namespace view {
 const QPen Trace::AxisPen(QColor(128, 128, 128, 64));
 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
+
 Trace::Trace(QString name) :
        name_(name),
        coloured_bg_(true), // Default setting is set in MainWindow::setup_ui()
@@ -181,19 +184,21 @@ QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const
 
 void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
 {
-       if (coloured_bg_) {
-               p.setPen(QPen(Qt::NoPen));
+       if (coloured_bg_)
                p.setBrush(bgcolour_);
+       else
+               p.setBrush(bgcolour_state_ ? BrightBGColour : DarkBGColour);
 
-               const std::pair<int, int> extents = v_extents();
+       p.setPen(QPen(Qt::NoPen));
 
-               const int x = 0;
-               const int y = get_visual_y() + extents.first;
-               const int w = pp.right() - pp.left();
-               const int h = extents.second - extents.first;
+       const std::pair<int, int> extents = v_extents();
 
-               p.drawRect(x, y, w, h);
-       }
+       const int x = 0;
+       const int y = get_visual_y() + extents.first;
+       const int w = pp.right() - pp.left();
+       const int h = extents.second - extents.first;
+
+       p.drawRect(x, y, w, h);
 }
 
 void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y)
index 74daf4a53cd69d8303709b0ae3a57da92830cab2..95efb60718df78f02b457f759028759cf39a7507 100644 (file)
@@ -49,6 +49,9 @@ private:
        static const QPen AxisPen;
        static const int LabelHitPadding;
 
+       static const QColor BrightBGColour;
+       static const QColor DarkBGColour;
+
 protected:
        Trace(QString name);
 
@@ -136,7 +139,7 @@ private Q_SLOTS:
 protected:
        QString name_;
        QColor colour_, bgcolour_;
-       bool coloured_bg_;
+       bool coloured_bg_, coloured_bg_state_;
 
 private:
        pv::widgets::Popup *popup_;
index 21fecb7e30f779ec71364caacde4faafe7f567cf..44c5d4b9feedd7a7827ea3bee3303c5ebbf86e70 100644 (file)
@@ -138,5 +138,10 @@ QPoint TraceTreeItem::point(const QRect &rect) const
        return QPoint(rect.right(), get_visual_y());
 }
 
+void TraceTreeItem::set_bgcolour_state(bool state)
+{
+       bgcolour_state_ = state;
+}
+
 } // namespace view
 } // namespace pv
index c41b67d75d1d2ab1a2dc503048d80d7c4241b63b..3632ded2f3fb51553ec402a3126f25165561fdf5 100644 (file)
@@ -110,6 +110,14 @@ public:
         */
        QPoint point(const QRect &rect) const;
 
+       /**
+     * Sets the new background colour state: false means dark, true means bright.
+        * This is to allow for alternating backgrounds but has no effect
+        * when coloured background colours are used.
+        * @param state New bg color state to use.
+        */
+       void set_bgcolour_state(bool state);
+
        /**
         * Computes the vertical extents of the contents of this row item.
         * @return A pair containing the minimum and maximum y-values.
@@ -122,6 +130,8 @@ protected:
        int layout_v_offset_;
        int visual_v_offset_;
 
+       bool bgcolour_state_;
+
 private:
        QPropertyAnimation v_offset_animation_;
 };
index 56433752889987d01becd4b92eb5c27cd86917cb..24174794456d01ffb2fd05cbf27601cdc1e16334 100644 (file)
@@ -105,6 +105,23 @@ pair<int, int> TraceTreeItemOwner::v_extents() const
        return extents;
 }
 
+bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state)
+{
+       vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items();
+
+       // Sort items according to vertical position
+       sort(items.begin(), items.end(),
+               [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) {
+               return a->layout_v_offset() > b->layout_v_offset(); });
+
+       for (const shared_ptr<TraceTreeItem> item : items) {
+               item->set_bgcolour_state(next_bgcolour_state);
+               next_bgcolour_state = !next_bgcolour_state;
+       }
+
+       return next_bgcolour_state;
+}
+
 void TraceTreeItemOwner::restack_items()
 {
 }
index cbb74427049af1db5b87eaeeb5d6ae0a31075a73..3e7927a8794a13659764b8801856c90c78ad06e3 100644 (file)
@@ -97,6 +97,14 @@ public:
         */
        std::pair<int, int> v_extents() const;
 
+       /*
+        * Reassigns background color states to all its children, thereby
+        * providing them with alternating backgrounds.
+        * @param next_brightness_state First brightness state to use.
+        * @return The next brightness state to use.
+        */
+       bool reassign_bgcolour_states(bool next_bgcolour_state);
+
 public:
        virtual void row_item_appearance_changed(bool label, bool content) = 0;
 
index eeb8afd236529e442bac91d6f4eeae6b5a065f05..c9b08bf8c0445de0783d5bbb16d4d4275f5066f1 100644 (file)
@@ -546,6 +546,12 @@ void View::restack_all_trace_tree_items()
        for (auto &o : sorted_owners)
                o->restack_items();
 
+       // Re-assign background colors
+       bool next_bgcolour_state = 0;
+
+       for (auto &o : sorted_owners)
+               next_bgcolour_state = o->reassign_bgcolour_states(next_bgcolour_state);
+
        // Animate the items to their destination
        for (const auto &i : items)
                i->animate_to_layout_v_offset();