Fixed not switching Disassembly to not opened Graph view using <space> (#1370)

+ a bit refactor
This commit is contained in:
Anton Krasnokutskiy 2019-03-27 01:24:54 -07:00 committed by Florian Märkl
parent b3e27f713b
commit 5818998bb3
16 changed files with 164 additions and 110 deletions

View File

@ -312,7 +312,8 @@ SOURCES += \
plugins/PluginManager.cpp \ plugins/PluginManager.cpp \
common/BasicBlockHighlighter.cpp \ common/BasicBlockHighlighter.cpp \
dialogs/LinkTypeDialog.cpp \ dialogs/LinkTypeDialog.cpp \
common/UpdateWorker.cpp common/UpdateWorker.cpp \
widgets/MemoryDockWidget.cpp
HEADERS += \ HEADERS += \
core/Cutter.h \ core/Cutter.h \
@ -428,7 +429,8 @@ HEADERS += \
plugins/PluginManager.h \ plugins/PluginManager.h \
common/BasicBlockHighlighter.h \ common/BasicBlockHighlighter.h \
common/UpdateWorker.h \ common/UpdateWorker.h \
dialogs/LinkTypeDialog.h dialogs/LinkTypeDialog.h \
widgets/MemoryDockWidget.h
FORMS += \ FORMS += \
dialogs/AboutDialog.ui \ dialogs/AboutDialog.ui \

View File

@ -239,7 +239,7 @@ void MainWindow::initDocks()
graphDock = new GraphWidget(this, ui->actionGraph); graphDock = new GraphWidget(this, ui->actionGraph);
connect(ui->actionOverview, &QAction::toggled, [this](bool checked) { connect(ui->actionOverview, &QAction::toggled, [this](bool checked) {
if (checked) { if (checked) {
overviewDock->userClosed = false; overviewDock->setUserClosed(false);
forceUpdateOverview(); forceUpdateOverview();
if (targetGraphDock) { if (targetGraphDock) {
toggleOverview(true, targetGraphDock); toggleOverview(true, targetGraphDock);
@ -292,25 +292,25 @@ void MainWindow::toggleOverview(bool visibility, GraphWidget *targetGraph)
return; return;
} }
ui->actionOverview->setEnabled(visibility); ui->actionOverview->setEnabled(visibility);
if (overviewDock->userClosed || !visibility) { if (overviewDock->getUserClosed() || !visibility) {
return; return;
} }
targetGraphDock = targetGraph; targetGraphDock = targetGraph;
connect(targetGraphDock->graphView, SIGNAL(refreshBlock()), this, SLOT(updateOverview())); connect(targetGraphDock->getGraphView(), SIGNAL(refreshBlock()), this, SLOT(updateOverview()));
connect(targetGraphDock->graphView, SIGNAL(viewRefreshed()), this, SLOT(forceUpdateOverview())); connect(targetGraphDock->getGraphView(), SIGNAL(viewRefreshed()), this, SLOT(forceUpdateOverview()));
connect(targetGraphDock->graphView, SIGNAL(viewZoomed()), this, SLOT(updateOverview())); connect(targetGraphDock->getGraphView(), SIGNAL(viewZoomed()), this, SLOT(updateOverview()));
connect(targetGraphDock, &GraphWidget::graphClose, [this]() { connect(targetGraphDock, &GraphWidget::graphClose, [this]() {
disconnectOverview(); disconnectOverview();
enableOverviewMenu(false); enableOverviewMenu(false);
overviewDock->hide(); overviewDock->hide();
}); });
connect(overviewDock->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph())); connect(overviewDock->getGraphView(), SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
connect(overviewDock->graphView, SIGNAL(refreshBlock()), this, SLOT(updateOverviewAddr())); connect(overviewDock->getGraphView(), SIGNAL(refreshBlock()), this, SLOT(updateOverviewAddr()));
connect(overviewDock, &QDockWidget::dockLocationChanged, this, &MainWindow::forceUpdateOverview); connect(overviewDock, &QDockWidget::dockLocationChanged, this, &MainWindow::forceUpdateOverview);
connect(overviewDock, &OverviewWidget::graphClose, [this]() { connect(overviewDock, &OverviewWidget::graphClose, [this]() {
ui->actionOverview->setChecked(false); ui->actionOverview->setChecked(false);
if (!core->isGraphEmpty()) { if (!core->isGraphEmpty()) {
overviewDock->userClosed = true; overviewDock->setUserClosed(true);
} }
}); });
connect(overviewDock, SIGNAL(resized()), this, SLOT(forceUpdateOverview())); connect(overviewDock, SIGNAL(resized()), this, SLOT(forceUpdateOverview()));
@ -319,13 +319,13 @@ void MainWindow::toggleOverview(bool visibility, GraphWidget *targetGraph)
void MainWindow::disconnectOverview() void MainWindow::disconnectOverview()
{ {
if (targetGraphDock) { if (targetGraphDock) {
disconnect(targetGraphDock->graphView, SIGNAL(refreshBlock()), this, SLOT(updateOverview())); disconnect(targetGraphDock->getGraphView(), SIGNAL(refreshBlock()), this, SLOT(updateOverview()));
disconnect(targetGraphDock->graphView, SIGNAL(viewRefreshed()), this, SLOT(updateOverview())); disconnect(targetGraphDock->getGraphView(), SIGNAL(viewRefreshed()), this, SLOT(updateOverview()));
disconnect(targetGraphDock->graphView, SIGNAL(viewZoomed()), this, SLOT(updateOverview())); disconnect(targetGraphDock->getGraphView(), SIGNAL(viewZoomed()), this, SLOT(updateOverview()));
} }
if (overviewDock) { if (overviewDock) {
disconnect(overviewDock->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph())); disconnect(overviewDock->getGraphView(), SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
disconnect(overviewDock->graphView, SIGNAL(refreshBlock()), this, SLOT(updateOverviewAddr())); disconnect(overviewDock->getGraphView(), SIGNAL(refreshBlock()), this, SLOT(updateOverviewAddr()));
disconnect(overviewDock, &QDockWidget::dockLocationChanged, this, &MainWindow::forceUpdateOverview); disconnect(overviewDock, &QDockWidget::dockLocationChanged, this, &MainWindow::forceUpdateOverview);
disconnect(overviewDock, SIGNAL(resized()), this, SLOT(forceUpdateOverview())); disconnect(overviewDock, SIGNAL(resized()), this, SLOT(forceUpdateOverview()));
} }
@ -333,13 +333,13 @@ void MainWindow::disconnectOverview()
void MainWindow::setOverviewData() void MainWindow::setOverviewData()
{ {
overviewDock->graphView->setData(targetGraphDock->graphView->getWidth(), overviewDock->getGraphView()->setData(targetGraphDock->getGraphView()->getWidth(),
targetGraphDock->graphView->getHeight(), targetGraphDock->graphView->getBlocks()); targetGraphDock->getGraphView()->getHeight(), targetGraphDock->getGraphView()->getBlocks());
} }
bool MainWindow::isOverviewActive() bool MainWindow::isOverviewActive()
{ {
if (!overviewDock || overviewDock->userClosed) { if (!overviewDock || overviewDock->getUserClosed()) {
return false; return false;
} }
if (core->isGraphEmpty()) { if (core->isGraphEmpty()) {
@ -352,7 +352,7 @@ bool MainWindow::isOverviewActive()
void MainWindow::updateOverviewAddr() void MainWindow::updateOverviewAddr()
{ {
overviewDock->graphView->currentFcnAddr = targetGraphDock->graphView->currentFcnAddr; overviewDock->getGraphView()->currentFcnAddr = targetGraphDock->getGraphView()->currentFcnAddr;
} }
void MainWindow::forceUpdateOverview() void MainWindow::forceUpdateOverview()
@ -360,7 +360,7 @@ void MainWindow::forceUpdateOverview()
if (!isOverviewActive()) { if (!isOverviewActive()) {
return; return;
} }
overviewDock->graphView->useCache = false; overviewDock->getGraphView()->useCache = false;
setOverviewData(); setOverviewData();
drawOverview(); drawOverview();
} }
@ -370,30 +370,30 @@ void MainWindow::updateOverview()
if (!isOverviewActive()) { if (!isOverviewActive()) {
return; return;
} }
if (overviewDock->graphView->currentFcnAddr != targetGraphDock->graphView->currentFcnAddr) { if (overviewDock->getGraphView()->currentFcnAddr != targetGraphDock->getGraphView()->currentFcnAddr) {
overviewDock->graphView->useCache = false; overviewDock->getGraphView()->useCache = false;
setOverviewData(); setOverviewData();
} else { } else {
overviewDock->graphView->useCache = true; overviewDock->getGraphView()->useCache = true;
} }
drawOverview(); drawOverview();
} }
void MainWindow::drawOverview() void MainWindow::drawOverview()
{ {
qreal curScale = overviewDock->graphView->current_scale; qreal curScale = overviewDock->getGraphView()->current_scale;
qreal baseScale = targetGraphDock->graphView->current_scale; qreal baseScale = targetGraphDock->getGraphView()->current_scale;
qreal w = targetGraphDock->graphView->viewport()->width() * curScale / baseScale; qreal w = targetGraphDock->getGraphView()->viewport()->width() * curScale / baseScale;
qreal h = targetGraphDock->graphView->viewport()->height() * curScale / baseScale; qreal h = targetGraphDock->getGraphView()->viewport()->height() * curScale / baseScale;
int graph_offset_x = targetGraphDock->graphView->offset.x(); int graph_offset_x = targetGraphDock->getGraphView()->offset.x();
int graph_offset_y = targetGraphDock->graphView->offset.y(); int graph_offset_y = targetGraphDock->getGraphView()->offset.y();
int overview_offset_x = overviewDock->graphView->offset.x(); int overview_offset_x = overviewDock->getGraphView()->offset.x();
int overview_offset_y = overviewDock->graphView->offset.y(); int overview_offset_y = overviewDock->getGraphView()->offset.y();
int rangeRectX = graph_offset_x * curScale - overview_offset_x * curScale; int rangeRectX = graph_offset_x * curScale - overview_offset_x * curScale;
int rangeRectY = graph_offset_y * curScale - overview_offset_y * curScale; int rangeRectY = graph_offset_y * curScale - overview_offset_y * curScale;
overviewDock->graphView->rangeRect = QRectF(rangeRectX, rangeRectY, w, h); overviewDock->getGraphView()->rangeRect = QRectF(rangeRectX, rangeRectY, w, h);
overviewDock->graphView->viewport()->update(); overviewDock->getGraphView()->viewport()->update();
enableOverviewMenu(true); enableOverviewMenu(true);
overviewDock->show(); overviewDock->show();
} }
@ -403,14 +403,15 @@ void MainWindow::adjustGraph()
if (!overviewDock) { if (!overviewDock) {
return; return;
} }
qreal curScale = overviewDock->graphView->current_scale;
int rectx = overviewDock->graphView->rangeRect.x(); qreal curScale = overviewDock->getGraphView()->current_scale;
int recty = overviewDock->graphView->rangeRect.y(); int rectx = overviewDock->getGraphView()->rangeRect.x();
int overview_offset_x = overviewDock->graphView->offset.x(); int recty = overviewDock->getGraphView()->rangeRect.y();
int overview_offset_y = overviewDock->graphView->offset.y(); int overview_offset_x = overviewDock->getGraphView()->offset.x();
targetGraphDock->graphView->offset.rx() = rectx /curScale + overview_offset_x; int overview_offset_y = overviewDock->getGraphView()->offset.y();
targetGraphDock->graphView->offset.ry() = recty /curScale + overview_offset_y; targetGraphDock->getGraphView()->offset.rx() = rectx /curScale + overview_offset_x;
targetGraphDock->graphView->viewport()->update(); targetGraphDock->getGraphView()->offset.ry() = recty /curScale + overview_offset_y;
targetGraphDock->getGraphView()->viewport()->update();
} }
void MainWindow::updateTasksIndicator() void MainWindow::updateTasksIndicator()

View File

@ -44,6 +44,11 @@ void CutterDockWidget::toggleDockWidget(bool show)
} }
} }
QWidget *CutterDockWidget::widgetToFocusOnRaise()
{
return this;
}
void CutterDockWidget::updateIsVisibleToUser() void CutterDockWidget::updateIsVisibleToUser()
{ {
// Check if the user can actually see the widget. // Check if the user can actually see the widget.
@ -65,3 +70,8 @@ void CutterDockWidget::closeEvent(QCloseEvent *event)
QDockWidget::closeEvent(event); QDockWidget::closeEvent(event);
} }
QAction *CutterDockWidget::getBoundAction() const
{
return action;
}

View File

@ -49,20 +49,23 @@ public:
return deferrer; return deferrer;
} }
signals:
void becameVisibleToUser();
public slots: public slots:
void toggleDockWidget(bool show); void toggleDockWidget(bool show);
signals: protected:
void becameVisibleToUser(); virtual QWidget* widgetToFocusOnRaise();
void closeEvent(QCloseEvent *event) override;
QAction *getBoundAction() const;
private: private:
QAction *action; QAction *action;
bool isVisibleToUserCurrent = false; bool isVisibleToUserCurrent = false;
void updateIsVisibleToUser(); void updateIsVisibleToUser();
protected:
void closeEvent(QCloseEvent *event) override;
}; };
#endif // CUTTERWIDGET_H #endif // CUTTERWIDGET_H

View File

@ -36,7 +36,7 @@ static DisassemblyTextBlockUserData *getUserData(const QTextBlock &block)
} }
DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
: CutterDockWidget(main, action) : MemoryDockWidget(CutterCore::MemoryWidgetType::Disassembly, main, action)
, mCtxMenu(new DisassemblyContextMenu(this)) , mCtxMenu(new DisassemblyContextMenu(this))
, mDisasScrollArea(new DisassemblyScrollArea(this)) , mDisasScrollArea(new DisassemblyScrollArea(this))
, mDisasTextEdit(new DisassemblyTextEdit(this)) , mDisasTextEdit(new DisassemblyTextEdit(this))
@ -119,8 +119,6 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
} }
}); });
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshDisasm()));
@ -645,15 +643,6 @@ void DisassemblyWidget::on_seekChanged(RVA offset)
mCtxMenu->setOffset(offset); mCtxMenu->setOffset(offset);
} }
void DisassemblyWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
{
bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (type == CutterCore::MemoryWidgetType::Disassembly || emptyGraph) {
raise();
setFocus();
}
}
void DisassemblyWidget::fontsUpdatedSlot() void DisassemblyWidget::fontsUpdatedSlot()
{ {
setupFonts(); setupFonts();

View File

@ -2,7 +2,7 @@
#define DISASSEMBLYWIDGET_H #define DISASSEMBLYWIDGET_H
#include "core/Cutter.h" #include "core/Cutter.h"
#include "CutterDockWidget.h" #include "MemoryDockWidget.h"
#include "common/CutterSeekable.h" #include "common/CutterSeekable.h"
#include "common/RefreshDeferrer.h" #include "common/RefreshDeferrer.h"
@ -16,7 +16,7 @@ class DisassemblyTextEdit;
class DisassemblyScrollArea; class DisassemblyScrollArea;
class DisassemblyContextMenu; class DisassemblyContextMenu;
class DisassemblyWidget : public CutterDockWidget class DisassemblyWidget : public MemoryDockWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -34,7 +34,6 @@ public slots:
private slots: private slots:
void on_seekChanged(RVA offset); void on_seekChanged(RVA offset);
void refreshDisasm(RVA offset = RVA_INVALID); void refreshDisasm(RVA offset = RVA_INVALID);
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
void scrollInstructions(int count); void scrollInstructions(int count);
bool updateMaxLines(); bool updateMaxLines();

View File

@ -4,7 +4,7 @@
#include "WidgetShortcuts.h" #include "WidgetShortcuts.h"
GraphWidget::GraphWidget(MainWindow *main, QAction *action) : GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
CutterDockWidget(main, action) MemoryDockWidget(CutterCore::MemoryWidgetType::Graph, main, action)
{ {
/* /*
* Ugly hack just for the layout issue * Ugly hack just for the layout issue
@ -34,7 +34,6 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
main->toggleOverview(visibility, this); main->toggleOverview(visibility, this);
if (visibility) { if (visibility) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Graph); Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Graph);
graphView->refreshView();
graphView->onSeekChanged(Core()->getOffset()); graphView->onSeekChanged(Core()->getOffset());
} }
}); });
@ -42,21 +41,20 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
connect(graphView, &DisassemblerGraphView::graphMoved, this, [ = ]() { connect(graphView, &DisassemblerGraphView::graphMoved, this, [ = ]() {
main->toggleOverview(true, this); main->toggleOverview(true, this);
}); });
connect(Core(), &CutterCore::raisePrioritizedMemoryWidget,
this, [ = ](CutterCore::MemoryWidgetType type) {
bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (type == CutterCore::MemoryWidgetType::Graph && !emptyGraph) {
raise();
graphView->setFocus();
}
});
} }
GraphWidget::~GraphWidget() {} QWidget *GraphWidget::widgetToFocusOnRaise()
{
return graphView;
}
void GraphWidget::closeEvent(QCloseEvent *event) void GraphWidget::closeEvent(QCloseEvent *event)
{ {
CutterDockWidget::closeEvent(event); CutterDockWidget::closeEvent(event);
emit graphClose(); emit graphClose();
} }
DisassemblerGraphView *GraphWidget::getGraphView() const
{
return graphView;
}

View File

@ -1,25 +1,31 @@
#ifndef GRAPHWIDGET_H #ifndef GRAPHWIDGET_H
#define GRAPHWIDGET_H #define GRAPHWIDGET_H
#include "CutterDockWidget.h" #include "MemoryDockWidget.h"
class MainWindow; class MainWindow;
class DisassemblerGraphView; class DisassemblerGraphView;
class GraphWidget : public CutterDockWidget class GraphWidget : public MemoryDockWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GraphWidget(MainWindow *main, QAction *action = nullptr); explicit GraphWidget(MainWindow *main, QAction *action = nullptr);
~GraphWidget(); ~GraphWidget() {}
DisassemblerGraphView *graphView;
DisassemblerGraphView *getGraphView() const;
signals:
void graphClose();
protected:
QWidget *widgetToFocusOnRaise() override;
private: private:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
signals: DisassemblerGraphView *graphView;
void graphClose();
}; };
#endif // GRAPHWIDGET_H #endif // GRAPHWIDGET_H

View File

@ -15,7 +15,7 @@
#include <QInputDialog> #include <QInputDialog>
HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) : HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
CutterDockWidget(main, action), MemoryDockWidget(CutterCore::MemoryWidgetType::Hexdump, main, action),
ui(new Ui::HexdumpWidget), ui(new Ui::HexdumpWidget),
seekable(new CutterSeekable(this)) seekable(new CutterSeekable(this))
{ {
@ -115,9 +115,6 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated())); connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) { connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
if (visibility) { if (visibility) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Hexdump); Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Hexdump);
@ -234,13 +231,6 @@ void HexdumpWidget::onSeekChanged(RVA)
refresh(); refresh();
} }
void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
{
if (type == CutterCore::MemoryWidgetType::Hexdump) {
raise();
}
}
void HexdumpWidget::connectScroll(bool disconnect_) void HexdumpWidget::connectScroll(bool disconnect_)
{ {
scroll_disabled = disconnect_; scroll_disabled = disconnect_;

View File

@ -10,7 +10,7 @@
#include <memory> #include <memory>
#include "core/Cutter.h" #include "core/Cutter.h"
#include "CutterDockWidget.h" #include "MemoryDockWidget.h"
#include "common/CutterSeekable.h" #include "common/CutterSeekable.h"
#include "dialogs/HexdumpRangeDialog.h" #include "dialogs/HexdumpRangeDialog.h"
#include "common/Highlighter.h" #include "common/Highlighter.h"
@ -26,11 +26,9 @@ namespace Ui {
class RefreshDeferrer; class RefreshDeferrer;
class HexdumpWidget : public CutterDockWidget class HexdumpWidget : public MemoryDockWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit HexdumpWidget(MainWindow *main, QAction *action = nullptr); explicit HexdumpWidget(MainWindow *main, QAction *action = nullptr);
~HexdumpWidget(); ~HexdumpWidget();
@ -118,7 +116,6 @@ private:
private slots: private slots:
void onSeekChanged(RVA addr); void onSeekChanged(RVA addr);
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
// Currently unused/untested // Currently unused/untested
// void highlightHexCurrentLine(); // void highlightHexCurrentLine();

View File

@ -0,0 +1,26 @@
#include "MemoryDockWidget.h"
#include <QAction>
MemoryDockWidget::MemoryDockWidget(CutterCore::MemoryWidgetType type, MainWindow *parent, QAction *action)
: CutterDockWidget(parent, action)
, mType(type)
{
connect(Core(), &CutterCore::raisePrioritizedMemoryWidget, this, &MemoryDockWidget::handleRaiseMemoryWidget);
}
void MemoryDockWidget::handleRaiseMemoryWidget(CutterCore::MemoryWidgetType raiseType)
{
bool raisingEmptyGraph = (raiseType == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (raisingEmptyGraph) {
raiseType = CutterCore::MemoryWidgetType::Disassembly;
}
if (raiseType == mType) {
getBoundAction()->setChecked(true);
show();
raise();
widgetToFocusOnRaise()->setFocus(Qt::FocusReason::TabFocusReason);
}
}

View File

@ -0,0 +1,20 @@
#ifndef MEMORYDOCKWIDGET_H
#define MEMORYDOCKWIDGET_H
#include "CutterDockWidget.h"
#include "core/Cutter.h"
class MemoryDockWidget : public CutterDockWidget
{
Q_OBJECT
public:
MemoryDockWidget(CutterCore::MemoryWidgetType type, MainWindow *parent, QAction *action = nullptr);
~MemoryDockWidget() {}
private:
void handleRaiseMemoryWidget(CutterCore::MemoryWidgetType raiseType);
CutterCore::MemoryWidgetType mType;
};
#endif // MEMORYDOCKWIDGET_H

View File

@ -43,3 +43,18 @@ void OverviewWidget::closeEvent(QCloseEvent *event)
CutterDockWidget::closeEvent(event); CutterDockWidget::closeEvent(event);
emit graphClose(); emit graphClose();
} }
void OverviewWidget::setUserClosed(bool value)
{
userClosed = value;
}
bool OverviewWidget::getUserClosed() const
{
return userClosed;
}
OverviewView *OverviewWidget::getGraphView() const
{
return graphView;
}

View File

@ -13,12 +13,15 @@ class OverviewWidget : public CutterDockWidget
public: public:
explicit OverviewWidget(MainWindow *main, QAction *action = nullptr); explicit OverviewWidget(MainWindow *main, QAction *action = nullptr);
~OverviewWidget(); ~OverviewWidget();
OverviewView *graphView;
OverviewView *getGraphView() const;
/* /*
* @brief if user closed this widget explicitly * @brief if user closed this widget explicitly
*/ */
bool userClosed = false; bool getUserClosed() const;
void setUserClosed(bool value);
private: private:
RefreshDeferrer *refreshDeferrer; RefreshDeferrer *refreshDeferrer;
/** /**
@ -45,6 +48,11 @@ signals:
* @brief emit signal to notify when this widget is closed * @brief emit signal to notify when this widget is closed
*/ */
void graphClose(); void graphClose();
private:
OverviewView *graphView;
bool userClosed = false;
}; };
#endif // OverviewWIDGET_H #endif // OverviewWIDGET_H

View File

@ -9,7 +9,7 @@
#include "common/TempConfig.h" #include "common/TempConfig.h"
PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) : PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
CutterDockWidget(main, action), MemoryDockWidget(CutterCore::MemoryWidgetType::Pseudocode, main, action),
ui(new Ui::PseudocodeWidget) ui(new Ui::PseudocodeWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -22,8 +22,6 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated())); connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) { connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
if (visibility) { if (visibility) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Pseudocode); Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Pseudocode);
@ -82,13 +80,6 @@ void PseudocodeWidget::refreshPseudocode()
doRefresh(Core()->getOffset()); doRefresh(Core()->getOffset());
} }
void PseudocodeWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
{
if (type == CutterCore::MemoryWidgetType::Pseudocode) {
raise();
}
}
void PseudocodeWidget::setupFonts() void PseudocodeWidget::setupFonts()
{ {
QFont font = Config()->getFont(); QFont font = Config()->getFont();

View File

@ -4,7 +4,7 @@
#include <memory> #include <memory>
#include "core/Cutter.h" #include "core/Cutter.h"
#include "CutterDockWidget.h" #include "MemoryDockWidget.h"
namespace Ui { namespace Ui {
class PseudocodeWidget; class PseudocodeWidget;
@ -13,7 +13,7 @@ class PseudocodeWidget;
class QTextEdit; class QTextEdit;
class SyntaxHighlighter; class SyntaxHighlighter;
class PseudocodeWidget : public CutterDockWidget class PseudocodeWidget : public MemoryDockWidget
{ {
Q_OBJECT Q_OBJECT
@ -22,7 +22,6 @@ public:
~PseudocodeWidget(); ~PseudocodeWidget();
private slots: private slots:
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
void fontsUpdated(); void fontsUpdated();
void colorsUpdatedSlot(); void colorsUpdatedSlot();
void refreshPseudocode(); void refreshPseudocode();