X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Fheader.cpp;h=af67abddd899f401b01eeb3d8665e271f959547c;hb=3925091ab254d42f1ce29ee0df042d343b4113e0;hp=77a887f9fe4c9b6b232fa78aaf31cd11b3b5ecd3;hpb=aca00b1e0d3483926c53dfd856483a397f1c29a5;p=pulseview.git diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 77a887f9..af67abdd 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -36,16 +36,22 @@ #include -using namespace boost; -using namespace std; +using boost::shared_ptr; +using std::max; +using std::make_pair; +using std::pair; +using std::vector; namespace pv { namespace view { +const int Header::Padding = 12; + Header::Header(View &parent) : MarginWidget(parent), _dragging(false) { + setFocusPolicy(Qt::ClickFocus); setMouseTracking(true); connect(&_view.session(), SIGNAL(signals_changed()), @@ -55,6 +61,19 @@ Header::Header(View &parent) : this, SLOT(on_signals_moved())); } +QSize Header::sizeHint() const +{ + int max_width = 0; + + const vector< shared_ptr > traces(_view.get_traces()); + BOOST_FOREACH(shared_ptr t, traces) { + assert(t); + max_width = max(max_width, (int)t->get_label_rect(0).width()); + } + + return QSize(max_width + Padding, 0); +} + shared_ptr Header::get_mouse_over_trace(const QPoint &pt) { const int w = width(); @@ -235,6 +254,23 @@ void Header::contextMenuEvent(QContextMenuEvent *event) t->create_context_menu(this)->exec(event->globalPos()); } +void Header::keyPressEvent(QKeyEvent *e) +{ + assert(e); + + switch (e->key()) + { + case Qt::Key_Delete: + { + const vector< shared_ptr > traces(_view.get_traces()); + BOOST_FOREACH(const shared_ptr t, traces) + if (t->selected()) + t->delete_pressed(); + break; + } + } +} + void Header::on_signals_changed() { const vector< shared_ptr > traces(_view.get_traces()); @@ -243,7 +279,7 @@ void Header::on_signals_changed() 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())); } @@ -254,6 +290,11 @@ void Header::on_signals_moved() update(); } +void Header::on_trace_text_changed() +{ + update(); + geometry_updated(); +} } // namespace view } // namespace pv