mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-20 13:46:06 +00:00
Split isVisibleToUser and refreshing in Dock Widgets
This commit is contained in:
parent
f4c720cffa
commit
3728f977a2
@ -57,8 +57,6 @@ private:
|
||||
void removeLastLine();
|
||||
void executeCommand(const QString &command);
|
||||
|
||||
void refreshContent() override { }
|
||||
|
||||
QSharedPointer<CommandTask> commandTask;
|
||||
|
||||
std::unique_ptr<Ui::ConsoleWidget> ui;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -25,8 +25,6 @@ private slots:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::Dashboard> ui;
|
||||
|
||||
void refreshContent() override { };
|
||||
};
|
||||
|
||||
#endif // DASHBOARD_H
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<RVA> breakpoints;
|
||||
|
||||
void refreshContent() override;
|
||||
|
||||
void setupFonts();
|
||||
void setupColors();
|
||||
|
||||
|
@ -137,8 +137,6 @@ private:
|
||||
CutterTreeWidget *tree;
|
||||
|
||||
void setScrollMode();
|
||||
|
||||
void refreshContent() override { }
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,8 +39,3 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
||||
}
|
||||
|
||||
GraphWidget::~GraphWidget() {}
|
||||
|
||||
void GraphWidget::refreshContent()
|
||||
{
|
||||
graphView->refreshView();
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ public:
|
||||
|
||||
private:
|
||||
DisassemblerGraphView *graphView;
|
||||
|
||||
void refreshContent() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // GRAPHWIDGET_H
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user