QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- int offset = -_view.v_offset();
+ const int v_offset = _view.v_offset();
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
const QRect signal_heading_rect(
- 0, offset, w, View::SignalHeight);
+ 0, s->get_v_offset() - v_offset,
+ w, View::SignalHeight);
s->paint_label(painter, signal_heading_rect,
s->pt_in_label_rect(signal_heading_rect, _mouse_point));
-
- offset += View::SignalHeight;
}
painter.end();
const vector< shared_ptr<Signal> > &sigs =
_view.session().get_signals();
- int offset = -_view.v_offset();
+ const int v_offset = _view.v_offset();
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
const QRect signal_heading_rect(
- 0, offset, w, View::SignalHeight);
+ 0, s->get_v_offset() - v_offset,
+ w, View::SignalHeight);
if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
QMenu menu(this);
break;
}
-
- offset += View::SignalHeight;
}
}
const int Signal::LabelHitPadding = 2;
Signal::Signal(QString name) :
- _name(name)
+ _name(name),
+ _v_offset(0)
{
}
_colour = colour;
}
+int Signal::get_v_offset() const
+{
+ return _v_offset;
+}
+
+void Signal::set_v_offset(int v_offset)
+{
+ _v_offset = v_offset;
+}
+
void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
{
p.setBrush(_colour);
*/
void set_colour(QColor colour);
+ /**
+ * Gets the vertical layout offset of this signal.
+ */
+ int get_v_offset() const;
+
+ /**
+ * Sets the vertical layout offset of this signal.
+ */
+ void set_v_offset(int v_offset);
+
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
protected:
QString _name;
QColor _colour;
+ int _v_offset;
QSizeF _text_size;
};
#include "header.h"
#include "ruler.h"
+#include "signal.h"
#include "view.h"
#include "viewport.h"
_viewport->get_total_height() - areaSize.height());
}
+void View::reset_signal_layout()
+{
+ int offset = 0;
+ vector< shared_ptr<Signal> > &sigs = _session.get_signals();
+ BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
+ s->set_v_offset(offset);
+ offset += SignalHeight;
+ }
+}
+
bool View::eventFilter(QObject *object, QEvent *event)
{
const QEvent::Type type = event->type();
// Repaint the view
_viewport->update();
+
+ /// @todo: Call this only once when the signals are first created.
+ reset_signal_layout();
}
void View::marker_time_changed()
void update_scroll();
+ void reset_signal_layout();
+
private:
bool eventFilter(QObject *object, QEvent *event);
draw_cursors_background(p);
// Plot the signal
- int offset = -_view.v_offset();
+ const int v_offset = _view.v_offset();
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
- const QRect signal_rect(0, offset,
+ const QRect signal_rect(0, s->get_v_offset() - v_offset,
width(), View::SignalHeight);
s->paint(p, signal_rect, _view.scale(), _view.offset());
-
- offset += View::SignalHeight;
}
draw_cursors_foreground(p);