From: Soeren Apel Date: Tue, 24 Dec 2019 14:27:17 +0000 (+0100) Subject: Implement hidable rows X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c6b4e925a8c5d855a70ab2815e8bc1c371d5801a;p=pulseview.git Implement hidable rows --- diff --git a/pv/data/decode/row.cpp b/pv/data/decode/row.cpp index 12951556..31e4cc8e 100644 --- a/pv/data/decode/row.cpp +++ b/pv/data/decode/row.cpp @@ -35,7 +35,8 @@ Row::Row() : Row::Row(int index, const Decoder* decoder, const srd_decoder_annotation_row* row) : index_(index), decoder_(decoder), - row_(row) + row_(row), + visible_(true) { } @@ -74,6 +75,16 @@ int Row::index() const return index_; } +bool Row::visible() const +{ + return visible_; +} + +void Row::set_visible(bool visible) +{ + visible_ = visible; +} + bool Row::operator<(const Row& other) const { return (decoder_ < other.decoder_) || diff --git a/pv/data/decode/row.hpp b/pv/data/decode/row.hpp index 25e6fcc4..9d7992e8 100644 --- a/pv/data/decode/row.hpp +++ b/pv/data/decode/row.hpp @@ -48,6 +48,9 @@ public: const QString class_name() const; int index() const; + bool visible() const; + void set_visible(bool visible); + bool operator<(const Row& other) const; bool operator==(const Row& other) const; @@ -55,6 +58,7 @@ private: int index_; const Decoder* decoder_; const srd_decoder_annotation_row* row_; + bool visible_; }; } // namespace decode diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index b648d5da..4b793656 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -68,13 +68,13 @@ const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktra vector GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; +bool GlobalSettings::is_dark_theme_ = false; map GlobalSettings::tracked_changes_; QString GlobalSettings::default_style_; QPalette GlobalSettings::default_palette_; GlobalSettings::GlobalSettings() : - QSettings(), - is_dark_theme_(false) + QSettings() { beginGroup("Settings"); } diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index bc2a4acd..6902a097 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -89,7 +89,7 @@ public: void set_bright_theme_default_colors(); void set_dark_theme_default_colors(); - bool current_theme_is_dark(); + static bool current_theme_is_dark(); void apply_theme(); static void add_change_handler(GlobalSettingsInterface *cb); @@ -132,7 +132,7 @@ private: static QString default_style_; static QPalette default_palette_; - bool is_dark_theme_; + static bool is_dark_theme_; }; } // namespace pv diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 3555d576..8cddcd45 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -32,6 +32,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -85,6 +86,8 @@ namespace trace { const QColor DecodeTrace::ErrorBgColor = QColor(0xEF, 0x29, 0x29); const QColor DecodeTrace::NoDecodeColor = QColor(0x88, 0x8A, 0x85); +const uint8_t DecodeTrace::ExpansionAreaHeaderAlpha = 10 * 255 / 100; +const uint8_t DecodeTrace::ExpansionAreaAlpha = 5 * 255 / 100; const int DecodeTrace::ArrowSize = 6; const double DecodeTrace::EndCapWidth = 5; @@ -100,7 +103,8 @@ DecodeTrace::DecodeTrace(pv::Session &session, session_(session), max_visible_rows_(0), delete_mapper_(this), - show_hide_mapper_(this) + show_hide_mapper_(this), + row_show_hide_mapper_(this) { decode_signal_ = dynamic_pointer_cast(base_); @@ -140,6 +144,8 @@ DecodeTrace::DecodeTrace(pv::Session &session, this, SLOT(on_delete_decoder(int))); connect(&show_hide_mapper_, SIGNAL(mapped(int)), this, SLOT(on_show_hide_decoder(int))); + connect(&row_show_hide_mapper_, SIGNAL(mapped(int)), + this, SLOT(on_show_hide_row(int))); connect(&delayed_trace_updater_, SIGNAL(timeout()), this, SLOT(on_delayed_trace_update())); @@ -159,8 +165,14 @@ DecodeTrace::~DecodeTrace() { GlobalSettings::remove_change_handler(this); - for (RowData& r : rows_) + for (RowData& r : rows_) { + for (QCheckBox* cb : r.selectors) + delete cb; + + delete r.selector_container; + delete r.header_container; delete r.container; + } } bool DecodeTrace::enabled() const @@ -214,8 +226,8 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp) int y = get_visual_y(); for (RowData& r : rows_) { - // If an entire decoder is hidden, we don't want to fetch annotations - if (!r.decode_row.decoder()->shown()) { + // If the row is hidden, we don't want to fetch annotations + if ((!r.decode_row.decoder()->shown()) || (!r.decode_row.visible())) { r.currently_visible = false; continue; } @@ -570,14 +582,14 @@ void DecodeTrace::mouse_left_press_event(const QMouseEvent* event) r.expanding = true; r.anim_shape = 0; r.container->setVisible(true); + QApplication::processEvents(); + r.expanded_height = 5 * default_row_height_ + r.container->size().height(); } r.animation_step = 0; r.anim_height = r.height; - r.container->move(2 * ArrowSize, - get_row_y(&r) + default_row_height_); - + update_expanded_rows(); animation_timer_.start(); } } @@ -1175,9 +1187,25 @@ void DecodeTrace::update_rows() QFontMetrics m(QApplication::font()); + QPalette header_palette = owner_->view()->palette(); + QPalette selector_palette = owner_->view()->palette(); + + if (GlobalSettings::current_theme_is_dark()) { + header_palette.setColor(QPalette::Background, + QColor(255, 255, 255, ExpansionAreaHeaderAlpha)); + selector_palette.setColor(QPalette::Background, + QColor(255, 255, 255, ExpansionAreaAlpha)); + } else { + header_palette.setColor(QPalette::Background, + QColor(0, 0, 0, ExpansionAreaHeaderAlpha)); + selector_palette.setColor(QPalette::Background, + QColor(0, 0, 0, ExpansionAreaAlpha)); + } + for (RowData& r : rows_) r.exists = false; + unsigned int row_id = 0; for (const Row& decode_row : decode_signal_->get_rows()) { // Find row in our list auto r_it = find_if(rows_.begin(), rows_.end(), @@ -1189,14 +1217,16 @@ void DecodeTrace::update_rows() RowData nr; nr.decode_row = decode_row; nr.height = default_row_height_; - nr.expanded_height = 5*default_row_height_; + nr.expanded_height = default_row_height_; nr.currently_visible = false; nr.expand_marker_highlighted = false; nr.expanding = false; nr.expanded = false; nr.collapsing = false; nr.expand_marker_shape = default_marker_shape_; - nr.container = new QWidget(owner_->view()->viewport()); + nr.container = new QWidget(owner_->view()->scrollarea()); + nr.header_container = new QWidget(nr.container); + nr.selector_container = new QWidget(nr.container); rows_.push_back(nr); r = &rows_.back(); @@ -1211,6 +1241,44 @@ void DecodeTrace::update_rows() r->container->resize(owner_->view()->viewport()->width() - r->container->pos().x(), r->expanded_height - 2 * default_row_height_); r->container->setVisible(false); + + QVBoxLayout* vlayout = new QVBoxLayout(); + r->container->setLayout(vlayout); + + // Add header container with checkbox for this row + vlayout->addWidget(r->header_container); + vlayout->setContentsMargins(0, 0, 0, 0); + vlayout->setSpacing(0); + r->header_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + r->header_container->setMinimumSize(0, default_row_height_); + r->header_container->setLayout(new QVBoxLayout()); + r->header_container->layout()->setContentsMargins(10, 2, 0, 2); + + r->header_container->setAutoFillBackground(true); + r->header_container->setPalette(header_palette); + + QCheckBox* cb = new QCheckBox(); + r->header_container->layout()->addWidget(cb); + cb->setText(tr("Show this row")); + cb->setChecked(r->decode_row.visible()); + + row_show_hide_mapper_.setMapping(cb, row_id); + connect(cb, SIGNAL(stateChanged(int)), + &row_show_hide_mapper_, SLOT(map())); + + // Add selector container + vlayout->addWidget(r->selector_container); + r->selector_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + r->selector_container->setMinimumSize(0, 3 * default_row_height_); // FIXME + r->selector_container->setLayout(new QVBoxLayout()); + + r->selector_container->setAutoFillBackground(true); + r->selector_container->setPalette(selector_palette); + + + // Add all classes that can be toggled + + row_id++; } // Remove any rows that no longer exist, obeying that iterators are invalidated @@ -1220,7 +1288,13 @@ void DecodeTrace::update_rows() for (unsigned int i = 0; i < rows_.size(); i++) if (!rows_[i].exists) { + for (QCheckBox* cb : rows_[i].selectors) + delete cb; + + delete rows_[i].selector_container; + delete rows_[i].header_container; delete rows_[i].container; + rows_.erase(rows_.begin() + i); any_exists = true; break; @@ -1228,6 +1302,42 @@ void DecodeTrace::update_rows() } while (any_exists); } +void DecodeTrace::set_row_expanded(RowData* r) +{ + r->height = r->expanded_height; + r->expanding = false; + r->expanded = true; + + // For details on this, see on_animation_timer() + r->expand_marker_shape.setPoint(0, 0, 0); + r->expand_marker_shape.setPoint(1, ArrowSize, ArrowSize); + r->expand_marker_shape.setPoint(2, 2*ArrowSize, 0); + + r->container->resize(owner_->view()->viewport()->width() - r->container->pos().x(), + r->height - 2 * default_row_height_); +} + +void DecodeTrace::set_row_collapsed(RowData* r) +{ + r->height = default_row_height_; + r->collapsing = false; + r->expanded = false; + r->expand_marker_shape = default_marker_shape_; + r->container->setVisible(false); + + r->container->resize(owner_->view()->viewport()->width() - r->container->pos().x(), + r->height - 2 * default_row_height_); +} + +void DecodeTrace::update_expanded_rows() +{ + for (RowData& r : rows_) { + + r.container->move(2 * ArrowSize, + get_row_y(&r) + default_row_height_); + } +} + void DecodeTrace::on_setting_changed(const QString &key, const QVariant &value) { Trace::on_setting_changed(key, value); @@ -1344,8 +1454,21 @@ void DecodeTrace::on_show_hide_decoder(int index) owner_->extents_changed(false, true); } - if (owner_) - owner_->row_item_appearance_changed(false, true); + owner_->row_item_appearance_changed(false, true); +} + +void DecodeTrace::on_show_hide_row(int index) +{ + if (index >= (int)rows_.size()) + return; + + set_row_collapsed(&rows_[index]); + rows_[index].decode_row.set_visible(!rows_[index].decode_row.visible()); + + // Force re-calculation of the trace height, see paint_mid() + max_visible_rows_ = 0; + owner_->extents_changed(false, true); + owner_->row_item_appearance_changed(false, true); } void DecodeTrace::on_copy_annotation_to_clipboard() @@ -1486,11 +1609,8 @@ void DecodeTrace::on_animation_timer() r.height = r.anim_height; r.anim_shape += ArrowSize / (float)AnimationDurationInTicks; animation_finished = false; - } else { - r.height = std::min(r.height, r.expanded_height); - r.expanding = false; - r.expanded = true; - } + } else + set_row_expanded(&r); } if (r.collapsing) { @@ -1499,13 +1619,8 @@ void DecodeTrace::on_animation_timer() r.height = r.anim_height; r.anim_shape -= ArrowSize / (float)AnimationDurationInTicks; animation_finished = false; - } else { - r.height = std::max(r.height, default_row_height_); - r.collapsing = false; - r.expanded = false; - r.expand_marker_shape = default_marker_shape_; - r.container->setVisible(false); - } + } else + set_row_collapsed(&r); } // The expansion marker shape switches between @@ -1515,16 +1630,13 @@ void DecodeTrace::on_animation_timer() r.expand_marker_shape.setPoint(0, 0, -ArrowSize + r.anim_shape); r.expand_marker_shape.setPoint(1, ArrowSize, r.anim_shape); r.expand_marker_shape.setPoint(2, 2*r.anim_shape, ArrowSize - r.anim_shape); - - r.container->resize(owner_->view()->viewport()->width() - r.container->pos().x(), - r.height - 2 * default_row_height_); } if (animation_finished) animation_timer_.stop(); - if (owner_) - owner_->row_item_appearance_changed(false, true); + owner_->extents_changed(false, true); + owner_->row_item_appearance_changed(false, true); } } // namespace trace diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index 662562c3..42ceb2a5 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -83,6 +83,9 @@ struct RowData { float anim_height, anim_shape; QWidget* container; + QWidget* header_container; + QWidget* selector_container; + vector selectors; }; class DecodeTrace : public Trace @@ -92,6 +95,8 @@ class DecodeTrace : public Trace private: static const QColor ErrorBgColor; static const QColor NoDecodeColor; + static const uint8_t ExpansionAreaHeaderAlpha; + static const uint8_t ExpansionAreaAlpha; static const int ArrowSize; static const double EndCapWidth; @@ -211,6 +216,18 @@ private: void update_rows(); + /** + * Sets row r to expanded state without forcing an update of the view + */ + void set_row_expanded(RowData* r); + + /** + * Sets row r to collapsed state without forcing an update of the view + */ + void set_row_collapsed(RowData* r); + + void update_expanded_rows(); + private Q_SLOTS: void on_setting_changed(const QString &key, const QVariant &value); @@ -233,6 +250,7 @@ private Q_SLOTS: void on_delete_decoder(int index); void on_show_hide_decoder(int index); + void on_show_hide_row(int index); void on_copy_annotation_to_clipboard(); @@ -268,7 +286,7 @@ private: int min_useful_label_width_; bool always_show_all_rows_; - QSignalMapper delete_mapper_, show_hide_mapper_; + QSignalMapper delete_mapper_, show_hide_mapper_, row_show_hide_mapper_; QTimer delayed_trace_updater_, animation_timer_; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index e72770f0..ea1c290c 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -394,6 +394,11 @@ const Viewport* View::viewport() const return viewport_; } +QAbstractScrollArea* View::scrollarea() const +{ + return scrollarea_; +} + const Ruler* View::ruler() const { return ruler_; diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 7fe2bf72..d79db4d4 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -149,6 +149,8 @@ public: Viewport* viewport(); const Viewport* viewport() const; + QAbstractScrollArea* scrollarea() const; + const Ruler* ruler() const; virtual void save_settings(QSettings &settings) const;