#include <boost/foreach.hpp>
#include <QAction>
+#include <QApplication>
#include <QComboBox>
#include <QFormLayout>
#include <QLabel>
_decoder_stack->get_start_time()) / scale;
const double samples_per_pixel = samplerate * scale;
- const int h = (_text_size.height() * 5) / 4;
+ QFontMetrics m(QApplication::font());
+ const int h = (m.boundingRect(QRect(), 0, "Tg").height() * 5) / 4;
assert(_decoder_stack);
const QString err = _decoder_stack->error_message();
namespace pv {
namespace view {
+const int Header::Padding = 12;
+
Header::Header(View &parent) :
MarginWidget(parent),
_dragging(false)
this, SLOT(on_signals_moved()));
}
+QSize Header::sizeHint() const
+{
+ int max_width = 0;
+
+ const vector< shared_ptr<Trace> > traces(_view.get_traces());
+ BOOST_FOREACH(shared_ptr<Trace> t, traces) {
+ assert(t);
+ max_width = max(max_width, (int)t->get_label_rect(0).width());
+ }
+
+ return QSize(max_width + Padding, 0);
+}
+
shared_ptr<Trace> Header::get_mouse_over_trace(const QPoint &pt)
{
const int w = width();
connect(t.get(), SIGNAL(visibility_changed()),
this, SLOT(update()));
connect(t.get(), SIGNAL(text_changed()),
- this, SLOT(update()));
+ this, SLOT(on_trace_text_changed()));
connect(t.get(), SIGNAL(colour_changed()),
this, SLOT(update()));
}
update();
}
+void Header::on_trace_text_changed()
+{
+ update();
+ geometry_updated();
+}
} // namespace view
} // namespace pv
{
Q_OBJECT
+private:
+ static const int Padding;
+
public:
Header(View &parent);
+ QSize sizeHint() const;
+
private:
boost::shared_ptr<pv::view::Trace> get_mouse_over_trace(
const QPoint &pt);
void on_signals_moved();
+ void on_trace_text_changed();
+
signals:
void signals_moved();
signals:
void selection_changed();
+ void geometry_updated();
+
protected:
pv::view::View &_view;
};
#include <assert.h>
#include <math.h>
+#include <QApplication>
#include <QFormLayout>
#include <QLineEdit>
(void)p;
(void)left;
(void)right;
-
- compute_text_size(p);
}
void Trace::paint_mid(QPainter &p, int left, int right)
const QColor colour = get_colour();
- compute_text_size(p);
const QRectF label_rect = get_label_rect(right);
// Paint the label
// Paint the text
p.setPen(get_text_colour());
+ p.setFont(QApplication::font());
p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
}
return _v_offset - _view->v_offset();
}
+QRectF Trace::get_label_rect(int right)
+{
+ using pv::view::View;
+
+ assert(_view);
+
+ QFontMetrics m(QApplication::font());
+ const QSize text_size(
+ m.boundingRect(QRect(), 0, _name).width(),
+ m.boundingRect(QRect(), 0, "Tg").height());
+ const QSizeF label_size(
+ text_size.width() + View::LabelPadding.width() * 2,
+ ceilf((text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
+ const float label_arrow_length = label_size.height() / 2;
+ return QRectF(
+ right - label_arrow_length - label_size.width() - 0.5,
+ get_y() + 0.5f - label_size.height() / 2,
+ label_size.width(), label_size.height());
+}
+
QColor Trace::get_text_colour() const
{
return (_colour.lightness() > 64) ? Qt::black : Qt::white;
add_colour_option(parent, form);
}
-void Trace::compute_text_size(QPainter &p)
-{
- _text_size = QSize(
- p.boundingRect(QRectF(), 0, _name).width(),
- p.boundingRect(QRectF(), 0, "Tg").height());
-}
-
-QRectF Trace::get_label_rect(int right)
-{
- using pv::view::View;
-
- assert(_view);
-
- const QSizeF label_size(
- _text_size.width() + View::LabelPadding.width() * 2,
- ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
- const float label_arrow_length = label_size.height() / 2;
- return QRectF(
- right - label_arrow_length - label_size.width() - 0.5,
- get_y() + 0.5f - label_size.height() / 2,
- label_size.width(), label_size.height());
-}
-
void Trace::on_popup_closed()
{
_popup = NULL;
*/
int get_y() const;
+ /**
+ * Computes the outline rectangle of a label.
+ * @param p the QPainter to lay out text with.
+ * @param right the x-coordinate of the right edge of the header
+ * area.
+ * @return Returns the rectangle of the signal label.
+ */
+ QRectF get_label_rect(int right);
+
protected:
+
/**
* Gets the text colour.
* @remarks This colour is computed by comparing the lightness
virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
-private:
-
- /**
- * Computes an caches the size of the label text.
- */
- void compute_text_size(QPainter &p);
-
- /**
- * Computes the outline rectangle of a label.
- * @param p the QPainter to lay out text with.
- * @param right the x-coordinate of the right edge of the header
- * area.
- * @return Returns the rectangle of the signal label.
- */
- QRectF get_label_rect(int right);
-
private slots:
void on_text_changed(const QString &text);
QColor _colour;
int _v_offset;
- QSizeF _text_size;
-
private:
pv::widgets::Popup *_popup;
QFormLayout *_popup_form;
const double View::MaxScale = 1e9;
const double View::MinScale = 1e-15;
-const int View::LabelMarginWidth = 70;
const int View::RulerHeight = 30;
const int View::MaxScrollValue = INT_MAX / 2;
connect(_cursors.second().get(), SIGNAL(time_changed()),
this, SLOT(marker_time_changed()));
+ connect(_header, SIGNAL(geometry_updated()),
+ this, SLOT(on_geometry_updated()));
connect(_header, SIGNAL(signals_moved()),
this, SLOT(on_signals_moved()));
connect(_ruler, SIGNAL(selection_changed()),
this, SIGNAL(selection_changed()));
- setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0);
setViewport(_viewport);
_viewport->installEventFilter(this);
areaSize.height());
}
+void View::update_layout()
+{
+ setViewportMargins(_header->sizeHint().width(), RulerHeight, 0, 0);
+ _ruler->setGeometry(_viewport->x(), 0,
+ _viewport->width(), _viewport->y());
+ _header->setGeometry(0, _viewport->y(),
+ _viewport->x(), _viewport->height());
+ update_scroll();
+}
+
bool View::compare_trace_v_offsets(const shared_ptr<Trace> &a,
const shared_ptr<Trace> &b)
{
void View::resizeEvent(QResizeEvent*)
{
- _ruler->setGeometry(_viewport->x(), 0,
- _viewport->width(), _viewport->y());
- _header->setGeometry(0, _viewport->y(),
- _viewport->x(), _viewport->height());
- update_scroll();
+ update_layout();
}
void View::h_scroll_value_changed(int value)
offset += SignalHeight + 2 * SignalMargin;
}
+ setViewportMargins(_header->sizeHint().width(), RulerHeight, 0, 0);
normalize_layout();
}
signals_moved();
}
+void View::on_geometry_updated()
+{
+ update_layout();
+}
+
} // namespace view
} // namespace pv
static const double MaxScale;
static const double MinScale;
- static const int LabelMarginWidth;
static const int RulerHeight;
static const int MaxScrollValue;
void update_scroll();
+ void update_layout();
+
static bool compare_trace_v_offsets(
const boost::shared_ptr<pv::view::Trace> &a,
const boost::shared_ptr<pv::view::Trace> &b);
void on_signals_moved();
+ void on_geometry_updated();
+
private:
SigSession &_session;