From: Joel Holdsworth Date: Sun, 2 Nov 2014 18:44:28 +0000 (+0000) Subject: RowItem: Replaced fixed signal heights with extents X-Git-Tag: pulseview-0.3.0~455 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=a5d93c27b5bd6b95000e29c6cddac56ab254b289 RowItem: Replaced fixed signal heights with extents --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index eaa25bcc..250fb94e 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -31,6 +31,7 @@ #include using std::max; +using std::make_pair; using std::min; using std::shared_ptr; using std::deque; @@ -40,6 +41,8 @@ using sigrok::Channel; namespace pv { namespace view { +const int AnalogSignal::NominalHeight = 80; + const QColor AnalogSignal::SignalColours[4] = { QColor(0xC4, 0xA0, 0x00), // Yellow QColor(0x87, 0x20, 0x7A), // Magenta @@ -79,6 +82,11 @@ void AnalogSignal::set_scale(float scale) _scale = scale; } +std::pair AnalogSignal::v_extents() const +{ + return make_pair(-NominalHeight / 2, NominalHeight / 2); +} + void AnalogSignal::paint_back(QPainter &p, int left, int right) { if (_channel->enabled()) diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index a7ae455b..71063900 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -37,6 +37,7 @@ namespace view { class AnalogSignal : public Signal { private: + static const int NominalHeight; static const QColor SignalColours[4]; static const float EnvelopeThreshold; @@ -54,6 +55,12 @@ public: void set_scale(float scale); + /** + * Computes the vertical extents of the contents of this row item. + * @return A pair containing the minimum and maximum y-values. + */ + std::pair v_extents() const; + /** * Paints the background layer of the signal with a QPainter * @param p the QPainter to paint into. diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 1cb9ce71..d97d01ef 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -60,6 +60,7 @@ using std::list; using std::lock_guard; using std::make_pair; using std::max; +using std::make_pair; using std::map; using std::min; using std::pair; @@ -155,6 +156,16 @@ const std::shared_ptr& DecodeTrace::decoder() const return _decoder_stack; } +pair DecodeTrace::v_extents() const +{ + /// @todo Replace this with an implementation that knows the true + /// height of the trace + QFontMetrics m(QApplication::font()); + const int text_height = m.boundingRect(QRect(), 0, "Tg").height(); + const int row_height = (text_height * 6) / 4; + return make_pair(-row_height / 2, row_height * 7 / 2); +} + void DecodeTrace::paint_back(QPainter &p, int left, int right) { Trace::paint_back(p, left, right); diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h index ab495fa0..2bb11541 100644 --- a/pv/view/decodetrace.h +++ b/pv/view/decodetrace.h @@ -90,6 +90,12 @@ public: const std::shared_ptr& decoder() const; + /** + * Computes the vertical extents of the contents of this row item. + * @return A pair containing the minimum and maximum y-values. + */ + std::pair v_extents() const; + /** * Paints the background layer of the trace with a QPainter * @param p the QPainter to paint into. diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 69c495e6..37445d96 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -41,6 +41,7 @@ using std::deque; using std::max; +using std::make_pair; using std::min; using std::pair; using std::shared_ptr; @@ -58,6 +59,9 @@ using sigrok::TriggerMatchType; namespace pv { namespace view { +const int LogicSignal::SignalHeight = 30; +const int LogicSignal::SignalMargin = 10; + const float LogicSignal::Oversampling = 2.0f; const QColor LogicSignal::EdgeColour(0x80, 0x80, 0x80); @@ -120,6 +124,11 @@ shared_ptr LogicSignal::logic_data() const return _data; } +std::pair LogicSignal::v_extents() const +{ + return make_pair(-SignalHeight - SignalMargin, SignalMargin); +} + void LogicSignal::paint_back(QPainter &p, int left, int right) { if (_channel->enabled()) @@ -152,7 +161,7 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) if (!_channel->enabled()) return; - const float high_offset = y - View::SignalHeight + 0.5f; + const float high_offset = y - SignalHeight + 0.5f; const float low_offset = y + 0.5f; const deque< shared_ptr > &snapshots = diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 958abd8f..a275f177 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -45,6 +45,9 @@ class LogicSignal : public Signal Q_OBJECT private: + static const int SignalHeight; + static const int SignalMargin; + static const float Oversampling; static const QColor EdgeColour; @@ -65,6 +68,12 @@ public: std::shared_ptr logic_data() const; + /** + * Computes the vertical extents of the contents of this row item. + * @return A pair containing the minimum and maximum y-values. + */ + std::pair v_extents() const; + /** * Paints the background layer of the signal with a QPainter * @param p the QPainter to paint into. diff --git a/pv/view/rowitem.h b/pv/view/rowitem.h index 2133db87..1aafca4b 100644 --- a/pv/view/rowitem.h +++ b/pv/view/rowitem.h @@ -77,6 +77,12 @@ public: */ QPoint point() const; + /** + * Computes the vertical extents of the contents of this row item. + * @return A pair containing the minimum and maximum y-values. + */ + virtual std::pair v_extents() const = 0; + /** * Paints the background layer of the trace with a QPainter * @param p the QPainter to paint into. diff --git a/pv/view/rowitemowner.cpp b/pv/view/rowitemowner.cpp index 8633525e..0fa230ab 100644 --- a/pv/view/rowitemowner.cpp +++ b/pv/view/rowitemowner.cpp @@ -23,6 +23,10 @@ #include "rowitem.h" #include "rowitemowner.h" +using std::max; +using std::make_pair; +using std::min; +using std::pair; using std::shared_ptr; using std::vector; @@ -84,5 +88,24 @@ RowItemOwner::const_iterator RowItemOwner::end() const return const_iterator(this); } +pair RowItemOwner::v_extents() const +{ + pair extents(0, 0); + for (const shared_ptr r : child_items()) { + assert(r); + if (!r->enabled()) + continue; + + const int child_offset = r->v_offset(); + const pair child_extents = r->v_extents(); + extents.first = min(child_extents.first + child_offset, + extents.first); + extents.second = max(child_extents.second + child_offset, + extents.second); + } + + return extents; +} + } // view } // pv diff --git a/pv/view/rowitemowner.h b/pv/view/rowitemowner.h index 98df5ff7..4b25a580 100644 --- a/pv/view/rowitemowner.h +++ b/pv/view/rowitemowner.h @@ -113,6 +113,12 @@ public: */ const_iterator end() const; + /** + * Computes the vertical extents of the contents of this row item owner. + * @return A pair containing the minimum and maximum y-values. + */ + std::pair v_extents() const; + virtual void update_viewport() = 0; private: diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index 9d0465fc..bc63d7f2 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -24,6 +24,7 @@ #include "tracegroup.h" +using std::pair; using std::shared_ptr; namespace pv { @@ -68,6 +69,11 @@ const pv::view::View* TraceGroup::view() const return _owner->view(); } +pair TraceGroup::v_extents() const +{ + return RowItemOwner::v_extents(); +} + void TraceGroup::paint_label(QPainter &p, int right, bool hover) { (void)p; diff --git a/pv/view/tracegroup.h b/pv/view/tracegroup.h index 21298dcb..a9f5558f 100644 --- a/pv/view/tracegroup.h +++ b/pv/view/tracegroup.h @@ -66,6 +66,12 @@ public: */ virtual const pv::view::View* view() const; + /** + * Computes the vertical extents of the contents of this row item. + * @return A pair containing the minimum and maximum y-values. + */ + std::pair v_extents() const; + /** * Paints the signal label. * @param p the QPainter to paint into. diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 61580223..37c3b14a 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -67,9 +67,6 @@ const double View::MinScale = 1e-15; const int View::MaxScrollValue = INT_MAX / 2; -const int View::SignalHeight = 30; -const int View::SignalMargin = 10; - const QColor View::CursorAreaColour(220, 231, 243); const QSizeF View::LabelPadding(4, 0); @@ -386,9 +383,11 @@ void View::update_scroll() // Set the vertical scrollbar verticalScrollBar()->setPageStep(areaSize.height()); - verticalScrollBar()->setRange(0, - _viewport->get_total_height() + SignalMargin - - areaSize.height()); + + const pair extents = v_extents(); + const int extra_scroll_height = (extents.second - extents.first) / 4; + verticalScrollBar()->setRange(extents.first - extra_scroll_height, + extents.first + extra_scroll_height); } void View::update_layout() @@ -513,10 +512,14 @@ void View::signals_changed() #endif // Create the initial layout - int offset = SignalMargin + SignalHeight; + int offset = 0; for (shared_ptr r : *this) { + const pair extents = r->v_extents(); + if (r->enabled()) + offset += -extents.first; r->set_v_offset(offset); - offset += SignalHeight + 2 * SignalMargin; + if (r->enabled()) + offset += extents.second; } update_layout(); diff --git a/pv/view/view.h b/pv/view/view.h index 9f66fc96..03528645 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -56,9 +56,6 @@ private: static const int MaxScrollValue; public: - static const int SignalHeight; - static const int SignalMargin; - static const QColor CursorAreaColour; static const QSizeF LabelPadding; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 8963e047..82d13c92 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -56,14 +56,6 @@ Viewport::Viewport(View &parent) : this, SLOT(on_signals_moved())); } -int Viewport::get_total_height() const -{ - int h = 0; - for (auto &i : _view) - h = max(i->v_offset() + View::SignalHeight, h); - return h; -} - void Viewport::signals_updated() { for (shared_ptr r : _view) { diff --git a/pv/view/viewport.h b/pv/view/viewport.h index 1f8f8f61..f88f4f10 100644 --- a/pv/view/viewport.h +++ b/pv/view/viewport.h @@ -41,8 +41,6 @@ class Viewport : public QWidget public: explicit Viewport(View &parent); - int get_total_height() const; - void signals_updated(); protected: