#include <libsigrok/libsigrok.hpp>
using std::max;
+using std::make_pair;
using std::min;
using std::shared_ptr;
using std::deque;
namespace pv {
namespace view {
+const int AnalogSignal::NominalHeight = 80;
+
const QColor AnalogSignal::SignalColours[4] = {
QColor(0xC4, 0xA0, 0x00), // Yellow
QColor(0x87, 0x20, 0x7A), // Magenta
_scale = scale;
}
+std::pair<int, int> AnalogSignal::v_extents() const
+{
+ return make_pair(-NominalHeight / 2, NominalHeight / 2);
+}
+
void AnalogSignal::paint_back(QPainter &p, int left, int right)
{
if (_channel->enabled())
class AnalogSignal : public Signal
{
private:
+ static const int NominalHeight;
static const QColor SignalColours[4];
static const float EnvelopeThreshold;
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<int, int> v_extents() const;
+
/**
* Paints the background layer of the signal with a QPainter
* @param p the QPainter to paint into.
using std::lock_guard;
using std::make_pair;
using std::max;
+using std::make_pair;
using std::map;
using std::min;
using std::pair;
return _decoder_stack;
}
+pair<int, int> 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);
const std::shared_ptr<pv::data::DecoderStack>& 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<int, int> v_extents() const;
+
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.
using std::deque;
using std::max;
+using std::make_pair;
using std::min;
using std::pair;
using std::shared_ptr;
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);
return _data;
}
+std::pair<int, int> LogicSignal::v_extents() const
+{
+ return make_pair(-SignalHeight - SignalMargin, SignalMargin);
+}
+
void LogicSignal::paint_back(QPainter &p, int left, int right)
{
if (_channel->enabled())
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<pv::data::LogicSnapshot> > &snapshots =
Q_OBJECT
private:
+ static const int SignalHeight;
+ static const int SignalMargin;
+
static const float Oversampling;
static const QColor EdgeColour;
std::shared_ptr<pv::data::Logic> 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<int, int> v_extents() const;
+
/**
* Paints the background layer of the signal with a QPainter
* @param p the QPainter to paint into.
*/
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<int, int> v_extents() const = 0;
+
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.
#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;
return const_iterator(this);
}
+pair<int, int> RowItemOwner::v_extents() const
+{
+ pair<int, int> extents(0, 0);
+ for (const shared_ptr<RowItem> r : child_items()) {
+ assert(r);
+ if (!r->enabled())
+ continue;
+
+ const int child_offset = r->v_offset();
+ const pair<int, int> 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
*/
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<int, int> v_extents() const;
+
virtual void update_viewport() = 0;
private:
#include "tracegroup.h"
+using std::pair;
using std::shared_ptr;
namespace pv {
return _owner->view();
}
+pair<int, int> TraceGroup::v_extents() const
+{
+ return RowItemOwner::v_extents();
+}
+
void TraceGroup::paint_label(QPainter &p, int right, bool hover)
{
(void)p;
*/
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<int, int> v_extents() const;
+
/**
* Paints the signal label.
* @param p the QPainter to paint into.
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);
// Set the vertical scrollbar
verticalScrollBar()->setPageStep(areaSize.height());
- verticalScrollBar()->setRange(0,
- _viewport->get_total_height() + SignalMargin -
- areaSize.height());
+
+ const pair<int, int> 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()
#endif
// Create the initial layout
- int offset = SignalMargin + SignalHeight;
+ int offset = 0;
for (shared_ptr<RowItem> r : *this) {
+ const pair<int, int> 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();
static const int MaxScrollValue;
public:
- static const int SignalHeight;
- static const int SignalMargin;
-
static const QColor CursorAreaColour;
static const QSizeF LabelPadding;
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<RowItem> r : _view) {
public:
explicit Viewport(View &parent);
- int get_total_height() const;
-
void signals_updated();
protected: