From 3728f977a22e17b9b3f896b89d4d13501d4ddfe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 12 Jan 2019 19:01:43 +0100 Subject: [PATCH] Split isVisibleToUser and refreshing in Dock Widgets --- src/widgets/ConsoleWidget.h | 2 -- src/widgets/CutterDockWidget.cpp | 37 ++++++++++++++++--------------- src/widgets/CutterDockWidget.h | 13 +++++------ src/widgets/Dashboard.h | 2 -- src/widgets/DisassemblyWidget.cpp | 22 +++++++++++++----- src/widgets/DisassemblyWidget.h | 5 +++-- src/widgets/FunctionsWidget.h | 2 -- src/widgets/GraphWidget.cpp | 5 ----- src/widgets/GraphWidget.h | 3 --- src/widgets/HexdumpWidget.cpp | 17 +++++++++++--- src/widgets/HexdumpWidget.h | 3 ++- 11 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/widgets/ConsoleWidget.h b/src/widgets/ConsoleWidget.h index c87b5cce..dfc2a84c 100644 --- a/src/widgets/ConsoleWidget.h +++ b/src/widgets/ConsoleWidget.h @@ -57,8 +57,6 @@ private: void removeLastLine(); void executeCommand(const QString &command); - void refreshContent() override { } - QSharedPointer commandTask; std::unique_ptr ui; diff --git a/src/widgets/CutterDockWidget.cpp b/src/widgets/CutterDockWidget.cpp index b361a031..004cf7a7 100644 --- a/src/widgets/CutterDockWidget.cpp +++ b/src/widgets/CutterDockWidget.cpp @@ -12,6 +12,8 @@ CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) : connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget); } + isVisibleToUserCurrent = false; + // Install event filter to catch redraw widgets when needed installEventFilter(this); } @@ -20,9 +22,13 @@ CutterDockWidget::~CutterDockWidget() {} bool CutterDockWidget::eventFilter(QObject *object, QEvent *event) { - if (event->type() == QEvent::FocusIn || event->type() == QEvent::Paint) { - qDebug() << object << "is now focused in"; - refreshIfNeeded(); + if (event->type() == QEvent::FocusIn + || event->type() == QEvent::ZOrderChange + || event->type() == QEvent::Paint + || event->type() == QEvent::Close + || event->type() == QEvent::Show + || event->type() == QEvent::Hide) { + updateIsVisibleToUser(); } return QDockWidget::eventFilter(object, event); } @@ -34,15 +40,20 @@ void CutterDockWidget::toggleDockWidget(bool show) } else { this->show(); this->raise(); - this->refreshIfNeeded(); } } -void CutterDockWidget::refreshIfNeeded() +void CutterDockWidget::updateIsVisibleToUser() { - if (doRefresh) { - refreshContent(); - doRefresh = false; + // Check if the user can actually see the widget. + bool visibleToUser = isVisible() && !visibleRegion().isEmpty(); + if (visibleToUser == isVisibleToUserCurrent) { + return; + } + isVisibleToUserCurrent = visibleToUser; + qDebug() << this << "isVisibleToUser changed to" << isVisibleToUserCurrent; + if (isVisibleToUserCurrent) { + emit becameVisibleToUser(); } } @@ -54,13 +65,3 @@ void CutterDockWidget::closeEvent(QCloseEvent *event) QDockWidget::closeEvent(event); } -bool CutterDockWidget::isVisibleToUser() -{ - // Check if the user can actually see the widget. - bool visibleToUser = this->isVisible() && !this->visibleRegion().isEmpty(); - if (!visibleToUser) { - // If this is called and not visible, it must be refreshed later - doRefresh = true; - } - return visibleToUser; -} diff --git a/src/widgets/CutterDockWidget.h b/src/widgets/CutterDockWidget.h index 949199c9..8d4143ec 100644 --- a/src/widgets/CutterDockWidget.h +++ b/src/widgets/CutterDockWidget.h @@ -17,19 +17,18 @@ public: public slots: void toggleDockWidget(bool show); +signals: + void becameVisibleToUser(); + private: QAction *action; - /** - * @brief doRefresh tells if the widget must refresh its content. - */ - bool doRefresh = false; - void refreshIfNeeded(); + bool isVisibleToUserCurrent; + void updateIsVisibleToUser(); protected: void closeEvent(QCloseEvent *event) override; - bool isVisibleToUser(); - virtual void refreshContent() = 0; + bool isVisibleToUser() { return isVisibleToUserCurrent; } }; #endif // CUTTERWIDGET_H diff --git a/src/widgets/Dashboard.h b/src/widgets/Dashboard.h index 754e6da5..4018a5d0 100644 --- a/src/widgets/Dashboard.h +++ b/src/widgets/Dashboard.h @@ -25,8 +25,6 @@ private slots: private: std::unique_ptr ui; - - void refreshContent() override { }; }; #endif // DASHBOARD_H diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 2e9b3772..8670476b 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -175,6 +175,13 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) ADD_SHORTCUT(QKeySequence(Qt::CTRL + Qt::Key_Plus), &DisassemblyWidget::zoomIn) ADD_SHORTCUT(QKeySequence(Qt::CTRL + Qt::Key_Minus), &DisassemblyWidget::zoomOut) #undef ADD_SHORTCUT + + connect(this, &CutterDockWidget::becameVisibleToUser, this, [this]() { + printf("ooh! we became visible!\n"); + if (disasmDirty) { + refreshDisasm(disasmDirtyOffset); + } + }); } void DisassemblyWidget::toggleSync() @@ -195,6 +202,16 @@ QWidget *DisassemblyWidget::getTextWidget() void DisassemblyWidget::refreshDisasm(RVA offset) { + if (!isVisibleToUser()) { + printf("setting dirty\n"); + disasmDirty = true; + disasmDirtyOffset = offset; + return; + } else { + printf("now refreshing\n"); + disasmDirty = false; + } + if (offset != RVA_INVALID) { topOffset = offset; } @@ -268,11 +285,6 @@ void DisassemblyWidget::refreshDisasm(RVA offset) mDisasTextEdit->horizontalScrollBar()->setValue(horizontalScrollValue); } -void DisassemblyWidget::refreshContent() -{ - refreshDisasm(); -} - void DisassemblyWidget::scrollInstructions(int count) { diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 174efac9..d61a488a 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -57,14 +57,15 @@ private: int cursorLineOffset; bool seekFromCursor; + bool disasmDirty = false; + RVA disasmDirtyOffset = RVA_INVALID; + RVA readCurrentDisassemblyOffset(); RVA readDisassemblyOffset(QTextCursor tc); bool eventFilter(QObject *obj, QEvent *event) override; QList breakpoints; - void refreshContent() override; - void setupFonts(); void setupColors(); diff --git a/src/widgets/FunctionsWidget.h b/src/widgets/FunctionsWidget.h index b8f1279d..8d01a9b0 100644 --- a/src/widgets/FunctionsWidget.h +++ b/src/widgets/FunctionsWidget.h @@ -137,8 +137,6 @@ private: CutterTreeWidget *tree; void setScrollMode(); - - void refreshContent() override { } }; diff --git a/src/widgets/GraphWidget.cpp b/src/widgets/GraphWidget.cpp index ec26acf7..6c038daa 100644 --- a/src/widgets/GraphWidget.cpp +++ b/src/widgets/GraphWidget.cpp @@ -39,8 +39,3 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) : } GraphWidget::~GraphWidget() {} - -void GraphWidget::refreshContent() -{ - graphView->refreshView(); -} diff --git a/src/widgets/GraphWidget.h b/src/widgets/GraphWidget.h index 98c98d00..314c7a83 100644 --- a/src/widgets/GraphWidget.h +++ b/src/widgets/GraphWidget.h @@ -16,9 +16,6 @@ public: private: DisassemblerGraphView *graphView; - - void refreshContent() override; - }; #endif // GRAPHWIDGET_H diff --git a/src/widgets/HexdumpWidget.cpp b/src/widgets/HexdumpWidget.cpp index bbc8bed6..f872f1db 100644 --- a/src/widgets/HexdumpWidget.cpp +++ b/src/widgets/HexdumpWidget.cpp @@ -119,6 +119,12 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) : connect(seekable, &CutterSeekable::seekableSeekChanged, this, &HexdumpWidget::onSeekChanged); connect(&rangeDialog, &QDialog::accepted, this, &HexdumpWidget::on_rangeDialogAccepted); + connect(this, &CutterDockWidget::becameVisibleToUser, this, [this]() { + if (hexdumpDirty) { + refresh(); + } + }); + format = Format::Hex; initParsing(); selectHexPreview(); @@ -214,9 +220,7 @@ void HexdumpWidget::onSeekChanged(RVA addr) sent_seek = false; return; } - if (isVisibleToUser()) { - refreshContent(); - } + refresh(); } void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type) @@ -316,6 +320,13 @@ void HexdumpWidget::highlightHexWords(const QString &str) void HexdumpWidget::refresh(RVA addr) { + if (!isVisibleToUser()) { + hexdumpDirty = true; + return; + } else { + hexdumpDirty = false; + } + ut64 loadLines = 0; ut64 curAddrLineOffset = 0; connectScroll(true); diff --git a/src/widgets/HexdumpWidget.h b/src/widgets/HexdumpWidget.h index 84f97a2a..e9e32a54 100644 --- a/src/widgets/HexdumpWidget.h +++ b/src/widgets/HexdumpWidget.h @@ -71,8 +71,9 @@ private: RVA first_loaded_address = RVA_INVALID; RVA last_loaded_address = RVA_INVALID; + bool hexdumpDirty = false; + void refresh(RVA addr = RVA_INVALID); - void refreshContent() override { refresh(); } void selectHexPreview(); void updateHeaders();