Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

[Disasm] Fix ArrowsWidget rendering laziness #416

Open
wants to merge 1 commit into
base: wip/disasm/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ui/disasm/arrows.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ArrowsWidget : public QWidget {
Q_OBJECT

public:
ArrowsWidget();
ArrowsWidget(QWidget* parent);

void updateArrows(std::vector<int> row_attach_points,
Expand Down
7 changes: 6 additions & 1 deletion include/ui/disasm/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -63,10 +64,14 @@ class Widget : public QScrollArea {
std::unique_ptr<Blob> blob_;
std::unique_ptr<Window> window_;

ArrowsWidget* arrows_;
ArrowsWidget* arrows_widget_;

std::vector<Row*> rows_;
QVBoxLayout* rows_layout_;

protected:
void paintEvent(QPaintEvent* event) override;
bool event(QEvent* event) override;
};

} // namespace disasm
Expand Down
4 changes: 2 additions & 2 deletions src/ui/disasm/arrows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
27 changes: 23 additions & 4 deletions src/ui/disasm/widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -85,7 +86,6 @@ void Widget::getWindow() {

void Widget::updateRows() {
generateRows(window_->entries());
std::cout << "Update rows" << std::endl;
update();
}

Expand Down Expand Up @@ -147,7 +147,9 @@ void Widget::generateRows(std::vector<std::shared_ptr<Entry>> entries) {
default: { break; }
}
}
}

void Widget::updateArrows() {
// TODO(zpp) row_attach_points_ should be updated when toggling chunk
std::vector<int> row_attach_points;
for (auto rowPtr : rows_) {
Expand All @@ -171,8 +173,9 @@ void Widget::generateRows(std::vector<std::shared_ptr<Entry>> 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<Row*>();
std::for_each(rows.begin(), rows.end(),
Expand All @@ -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<QPaintEvent*>(event));
return true;
}
return QScrollArea::event(event);
}

} // namespace disasm
} // namespace ui
Expand Down