diff --git a/include/ui/disasm/arrows.h b/include/ui/disasm/arrows.h index b64479e6..12230ca9 100644 --- a/include/ui/disasm/arrows.h +++ b/include/ui/disasm/arrows.h @@ -65,6 +65,7 @@ class ArrowsWidget : public QWidget { Q_OBJECT public: + ArrowsWidget(); ArrowsWidget(QWidget* parent); void updateArrows(std::vector row_attach_points, diff --git a/include/ui/disasm/widget.h b/include/ui/disasm/widget.h index 14859334..74b736b9 100644 --- a/include/ui/disasm/widget.h +++ b/include/ui/disasm/widget.h @@ -47,6 +47,7 @@ class Widget : public QScrollArea { void updateRows(); void chunkCollapse(const ChunkID& id); void toggleColumn(Row::ColumnName column_name); + void updateArrows(); public: Widget(); @@ -63,10 +64,14 @@ class Widget : public QScrollArea { std::unique_ptr blob_; std::unique_ptr window_; - ArrowsWidget* arrows_; + ArrowsWidget* arrows_widget_; std::vector rows_; QVBoxLayout* rows_layout_; + + protected: + void paintEvent(QPaintEvent* event) override; + bool event(QEvent* event) override; }; } // namespace disasm diff --git a/src/ui/disasm/arrows.cc b/src/ui/disasm/arrows.cc index a3e662bf..b3234758 100644 --- a/src/ui/disasm/arrows.cc +++ b/src/ui/disasm/arrows.cc @@ -36,6 +36,8 @@ std::ostream& operator<<(std::ostream& out, const Arrow& arrow) { return out; } +ArrowsWidget::ArrowsWidget() : ArrowsWidget(nullptr) {} + ArrowsWidget::ArrowsWidget(QWidget* parent) : QWidget(parent), width_(DEFAULT_WIDTH), height_(0), levels_(MIN_LEVELS) { setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed); @@ -55,8 +57,6 @@ void ArrowsWidget::paintEvent(QPaintEvent* event) { pen.setColor(palette().color(QPalette::Text)); painter.setPen(pen); - painter.fillRect(event->rect(), palette().color(QPalette::AlternateBase)); - for (const auto& arrow : arrows_) { if (arrow.level == 0) { std::cerr << "Warning: unspecified level of an arrow! " << arrow diff --git a/src/ui/disasm/widget.cc b/src/ui/disasm/widget.cc index 1bfd3132..4c2cc80d 100644 --- a/src/ui/disasm/widget.cc +++ b/src/ui/disasm/widget.cc @@ -25,11 +25,12 @@ Widget::Widget() { setWidgetResizable(true); setFont(util::settings::theme::font()); - arrows_ = new ArrowsWidget(this); + arrows_widget_ = new ArrowsWidget; rows_layout_ = new QVBoxLayout(); rows_layout_->setSpacing(0); rows_layout_->setContentsMargins(0, 0, 0, 0); + // rows_layout_->addStretch(); auto rows_with_stretch = new QVBoxLayout(); rows_with_stretch->setSpacing(0); @@ -40,7 +41,7 @@ Widget::Widget() { auto split_layout = new QHBoxLayout; split_layout->setSpacing(0); split_layout->setMargin(0); - split_layout->addWidget(arrows_, 0, Qt::AlignTop); + split_layout->addWidget(arrows_widget_, 0, Qt::AlignTop); split_layout->addLayout(rows_with_stretch, 0); auto split_view = new QWidget; @@ -85,7 +86,6 @@ void Widget::getWindow() { void Widget::updateRows() { generateRows(window_->entries()); - std::cout << "Update rows" << std::endl; update(); } @@ -147,7 +147,9 @@ void Widget::generateRows(std::vector> entries) { default: { break; } } } +} +void Widget::updateArrows() { // TODO(zpp) row_attach_points_ should be updated when toggling chunk std::vector row_attach_points; for (auto rowPtr : rows_) { @@ -171,8 +173,9 @@ void Widget::generateRows(std::vector> entries) { arrows_vec.emplace_back(row_range(g), row_range(g), level_range(g)); } - arrows_->updateArrows(row_attach_points, arrows_vec); + arrows_widget_->updateArrows(row_attach_points, arrows_vec); } + void Widget::toggleColumn(Row::ColumnName column_name) { auto rows = this->findChildren(); std::for_each(rows.begin(), rows.end(), @@ -182,6 +185,22 @@ void Widget::toggleColumn(Row::ColumnName column_name) { void Widget::chunkCollapse(const ChunkID& id) { window_->chunkCollapseToggle(id); } +void Widget::paintEvent(QPaintEvent* event) { + static bool first = true; + if (first) { + updateArrows(); + first = false; + } + QAbstractScrollArea::paintEvent(event); +} + +bool Widget::event(QEvent* event) { + if (event->type() == QEvent::Paint) { + paintEvent(dynamic_cast(event)); + return true; + } + return QScrollArea::event(event); +} } // namespace disasm } // namespace ui