mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 14:16:08 +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 removeLastLine();
|
||||||
void executeCommand(const QString &command);
|
void executeCommand(const QString &command);
|
||||||
|
|
||||||
void refreshContent() override { }
|
|
||||||
|
|
||||||
QSharedPointer<CommandTask> commandTask;
|
QSharedPointer<CommandTask> commandTask;
|
||||||
|
|
||||||
std::unique_ptr<Ui::ConsoleWidget> ui;
|
std::unique_ptr<Ui::ConsoleWidget> ui;
|
||||||
|
@ -12,6 +12,8 @@ CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) :
|
|||||||
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
|
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isVisibleToUserCurrent = false;
|
||||||
|
|
||||||
// Install event filter to catch redraw widgets when needed
|
// Install event filter to catch redraw widgets when needed
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
}
|
}
|
||||||
@ -20,9 +22,13 @@ CutterDockWidget::~CutterDockWidget() {}
|
|||||||
|
|
||||||
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
|
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::FocusIn || event->type() == QEvent::Paint) {
|
if (event->type() == QEvent::FocusIn
|
||||||
qDebug() << object << "is now focused in";
|
|| event->type() == QEvent::ZOrderChange
|
||||||
refreshIfNeeded();
|
|| event->type() == QEvent::Paint
|
||||||
|
|| event->type() == QEvent::Close
|
||||||
|
|| event->type() == QEvent::Show
|
||||||
|
|| event->type() == QEvent::Hide) {
|
||||||
|
updateIsVisibleToUser();
|
||||||
}
|
}
|
||||||
return QDockWidget::eventFilter(object, event);
|
return QDockWidget::eventFilter(object, event);
|
||||||
}
|
}
|
||||||
@ -34,15 +40,20 @@ void CutterDockWidget::toggleDockWidget(bool show)
|
|||||||
} else {
|
} else {
|
||||||
this->show();
|
this->show();
|
||||||
this->raise();
|
this->raise();
|
||||||
this->refreshIfNeeded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterDockWidget::refreshIfNeeded()
|
void CutterDockWidget::updateIsVisibleToUser()
|
||||||
{
|
{
|
||||||
if (doRefresh) {
|
// Check if the user can actually see the widget.
|
||||||
refreshContent();
|
bool visibleToUser = isVisible() && !visibleRegion().isEmpty();
|
||||||
doRefresh = false;
|
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);
|
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:
|
public slots:
|
||||||
void toggleDockWidget(bool show);
|
void toggleDockWidget(bool show);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void becameVisibleToUser();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAction *action;
|
QAction *action;
|
||||||
|
|
||||||
/**
|
bool isVisibleToUserCurrent;
|
||||||
* @brief doRefresh tells if the widget must refresh its content.
|
void updateIsVisibleToUser();
|
||||||
*/
|
|
||||||
bool doRefresh = false;
|
|
||||||
void refreshIfNeeded();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
bool isVisibleToUser();
|
bool isVisibleToUser() { return isVisibleToUserCurrent; }
|
||||||
virtual void refreshContent() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUTTERWIDGET_H
|
#endif // CUTTERWIDGET_H
|
||||||
|
@ -25,8 +25,6 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::Dashboard> ui;
|
std::unique_ptr<Ui::Dashboard> ui;
|
||||||
|
|
||||||
void refreshContent() override { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DASHBOARD_H
|
#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_Plus), &DisassemblyWidget::zoomIn)
|
||||||
ADD_SHORTCUT(QKeySequence(Qt::CTRL + Qt::Key_Minus), &DisassemblyWidget::zoomOut)
|
ADD_SHORTCUT(QKeySequence(Qt::CTRL + Qt::Key_Minus), &DisassemblyWidget::zoomOut)
|
||||||
#undef ADD_SHORTCUT
|
#undef ADD_SHORTCUT
|
||||||
|
|
||||||
|
connect(this, &CutterDockWidget::becameVisibleToUser, this, [this]() {
|
||||||
|
printf("ooh! we became visible!\n");
|
||||||
|
if (disasmDirty) {
|
||||||
|
refreshDisasm(disasmDirtyOffset);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblyWidget::toggleSync()
|
void DisassemblyWidget::toggleSync()
|
||||||
@ -195,6 +202,16 @@ QWidget *DisassemblyWidget::getTextWidget()
|
|||||||
|
|
||||||
void DisassemblyWidget::refreshDisasm(RVA offset)
|
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) {
|
if (offset != RVA_INVALID) {
|
||||||
topOffset = offset;
|
topOffset = offset;
|
||||||
}
|
}
|
||||||
@ -268,11 +285,6 @@ void DisassemblyWidget::refreshDisasm(RVA offset)
|
|||||||
mDisasTextEdit->horizontalScrollBar()->setValue(horizontalScrollValue);
|
mDisasTextEdit->horizontalScrollBar()->setValue(horizontalScrollValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblyWidget::refreshContent()
|
|
||||||
{
|
|
||||||
refreshDisasm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DisassemblyWidget::scrollInstructions(int count)
|
void DisassemblyWidget::scrollInstructions(int count)
|
||||||
{
|
{
|
||||||
|
@ -57,14 +57,15 @@ private:
|
|||||||
int cursorLineOffset;
|
int cursorLineOffset;
|
||||||
bool seekFromCursor;
|
bool seekFromCursor;
|
||||||
|
|
||||||
|
bool disasmDirty = false;
|
||||||
|
RVA disasmDirtyOffset = RVA_INVALID;
|
||||||
|
|
||||||
RVA readCurrentDisassemblyOffset();
|
RVA readCurrentDisassemblyOffset();
|
||||||
RVA readDisassemblyOffset(QTextCursor tc);
|
RVA readDisassemblyOffset(QTextCursor tc);
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
QList<RVA> breakpoints;
|
QList<RVA> breakpoints;
|
||||||
|
|
||||||
void refreshContent() override;
|
|
||||||
|
|
||||||
void setupFonts();
|
void setupFonts();
|
||||||
void setupColors();
|
void setupColors();
|
||||||
|
|
||||||
|
@ -137,8 +137,6 @@ private:
|
|||||||
CutterTreeWidget *tree;
|
CutterTreeWidget *tree;
|
||||||
|
|
||||||
void setScrollMode();
|
void setScrollMode();
|
||||||
|
|
||||||
void refreshContent() override { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +39,3 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
GraphWidget::~GraphWidget() {}
|
GraphWidget::~GraphWidget() {}
|
||||||
|
|
||||||
void GraphWidget::refreshContent()
|
|
||||||
{
|
|
||||||
graphView->refreshView();
|
|
||||||
}
|
|
||||||
|
@ -16,9 +16,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DisassemblerGraphView *graphView;
|
DisassemblerGraphView *graphView;
|
||||||
|
|
||||||
void refreshContent() override;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHWIDGET_H
|
#endif // GRAPHWIDGET_H
|
||||||
|
@ -119,6 +119,12 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
|
|||||||
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &HexdumpWidget::onSeekChanged);
|
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &HexdumpWidget::onSeekChanged);
|
||||||
connect(&rangeDialog, &QDialog::accepted, this, &HexdumpWidget::on_rangeDialogAccepted);
|
connect(&rangeDialog, &QDialog::accepted, this, &HexdumpWidget::on_rangeDialogAccepted);
|
||||||
|
|
||||||
|
connect(this, &CutterDockWidget::becameVisibleToUser, this, [this]() {
|
||||||
|
if (hexdumpDirty) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
format = Format::Hex;
|
format = Format::Hex;
|
||||||
initParsing();
|
initParsing();
|
||||||
selectHexPreview();
|
selectHexPreview();
|
||||||
@ -214,9 +220,7 @@ void HexdumpWidget::onSeekChanged(RVA addr)
|
|||||||
sent_seek = false;
|
sent_seek = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isVisibleToUser()) {
|
refresh();
|
||||||
refreshContent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
||||||
@ -316,6 +320,13 @@ void HexdumpWidget::highlightHexWords(const QString &str)
|
|||||||
|
|
||||||
void HexdumpWidget::refresh(RVA addr)
|
void HexdumpWidget::refresh(RVA addr)
|
||||||
{
|
{
|
||||||
|
if (!isVisibleToUser()) {
|
||||||
|
hexdumpDirty = true;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
hexdumpDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
ut64 loadLines = 0;
|
ut64 loadLines = 0;
|
||||||
ut64 curAddrLineOffset = 0;
|
ut64 curAddrLineOffset = 0;
|
||||||
connectScroll(true);
|
connectScroll(true);
|
||||||
|
@ -71,8 +71,9 @@ private:
|
|||||||
RVA first_loaded_address = RVA_INVALID;
|
RVA first_loaded_address = RVA_INVALID;
|
||||||
RVA last_loaded_address = RVA_INVALID;
|
RVA last_loaded_address = RVA_INVALID;
|
||||||
|
|
||||||
|
bool hexdumpDirty = false;
|
||||||
|
|
||||||
void refresh(RVA addr = RVA_INVALID);
|
void refresh(RVA addr = RVA_INVALID);
|
||||||
void refreshContent() override { refresh(); }
|
|
||||||
void selectHexPreview();
|
void selectHexPreview();
|
||||||
void updateHeaders();
|
void updateHeaders();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user