Skip to content

Commit

Permalink
Reinstate **View > Scanner** top-bar menu action.
Browse files Browse the repository at this point in the history
This checkable menu action was removed in dd7a5ad, as it was
deemed redundant after the main vertical splitter was added in
76e3b2e. However, it turned out that this convenience action
was quite popular, and users have requested it back.

An effort has been made to preserve the splitter's position when the
scanner's visibility is toggled.

Bonus: The action has been assigned the `S` keyboard shortcut.

Fixes #102.
  • Loading branch information
cristian64 committed Mar 5, 2024
1 parent 7a158dd commit 4de85e3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Source/GUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void MainWindow::makeMenus()

m_actMemoryViewer = new QAction(tr("&Memory Viewer"), this);
m_actCopyMemory = new QAction(tr("&Copy Memory Range"), this);
m_actScanner = new QAction(tr("&Scanner"), this);
m_actScanner->setShortcut(QKeySequence("S"));
m_actScanner->setCheckable(true);
m_actScanner->setChecked(m_splitter->sizes()[0] > 0);

m_actQuit = new QAction(tr("&Quit"), this);
m_actAbout = new QAction(tr("&About"), this);
Expand All @@ -91,6 +95,7 @@ void MainWindow::makeMenus()

connect(m_actMemoryViewer, &QAction::triggered, this, &MainWindow::onOpenMenViewer);
connect(m_actCopyMemory, &QAction::triggered, this, &MainWindow::onCopyMemory);
connect(m_actScanner, &QAction::toggled, this, &MainWindow::onScannerActionToggled);

connect(m_actQuit, &QAction::triggered, this, &MainWindow::onQuit);
connect(m_actAbout, &QAction::triggered, this, &MainWindow::onAbout);
Expand All @@ -116,6 +121,7 @@ void MainWindow::makeMenus()
m_menuView = menuBar()->addMenu(tr("&View"));
m_menuView->addAction(m_actMemoryViewer);
m_menuView->addAction(m_actCopyMemory);
m_menuView->addAction(m_actScanner);

m_menuHelp = menuBar()->addMenu(tr("&Help"));
m_menuHelp->addAction(m_actAbout);
Expand Down Expand Up @@ -358,6 +364,21 @@ void MainWindow::onHookIfNotHooked()
void MainWindow::onSplitterMoved(const int pos, const int index)
{
SConfig::getInstance().setSplitterState(m_splitter->saveState());

const QList<int> currentSizes{m_splitter->sizes()};
const int totalSize{std::accumulate(currentSizes.begin(), currentSizes.end(), 0)};
const double scannerSize{static_cast<double>(currentSizes[0])};
const bool scannerVisible{scannerSize > 0};
if (scannerVisible)
{
const double scannerFactor{scannerSize / static_cast<double>(totalSize)};
m_splitter->setProperty("previous_scanner_factor", scannerFactor);
}

{
QSignalBlocker signalBlocker(m_actScanner);
m_actScanner->setChecked(scannerVisible);
}
}

void MainWindow::onOpenWatchFile()
Expand Down Expand Up @@ -397,6 +418,33 @@ void MainWindow::onCopyMemory()
m_copier->raise();
}

void MainWindow::onScannerActionToggled(const bool checked)
{
const QList<int> currentSizes{m_splitter->sizes()};
const int totalSize{std::accumulate(currentSizes.begin(), currentSizes.end(), 0)};

QList<int> sizes;
if (!checked)
{
const double scannerSize{static_cast<double>(currentSizes[0])};
const double scannerFactor{scannerSize / static_cast<double>(totalSize)};
m_splitter->setProperty("previous_scanner_factor", scannerFactor);

sizes << 0 << totalSize;
}
else
{
const QVariant scannerFactorVariant{m_splitter->property("previous_scanner_factor")};
const double scannerFactor{scannerFactorVariant.isValid() ? scannerFactorVariant.toDouble() :
0.5};
const double scannerSize{std::round(scannerFactor * totalSize)};

sizes << scannerSize << totalSize - scannerSize;
}

m_splitter->setSizes(sizes);
}

void MainWindow::onOpenSettings()
{
DlgSettings* dlg = new DlgSettings(this);
Expand Down
2 changes: 2 additions & 0 deletions Source/GUI/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MainWindow : public QMainWindow
void onImportFromCT();
void onExportAsCSV();
void onCopyMemory();
void onScannerActionToggled(bool checked);
void onAbout();
void onQuit();

Expand Down Expand Up @@ -84,6 +85,7 @@ class MainWindow : public QMainWindow
QAction* m_actUnhook;
QAction* m_actMemoryViewer;
QAction* m_actCopyMemory;
QAction* m_actScanner{};
QAction* m_actQuit;
QAction* m_actAbout;
};

0 comments on commit 4de85e3

Please sign in to comment.