From 34993f173312b7891d6b838220d0072c5faaf1e1 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 16 Jul 2022 19:12:12 +0100 Subject: [PATCH] Added support for attaching and detaching memory inspection panes from the main insight window --- .../InsightWindow/InsightWindow.cpp | 122 +++++++++++++++--- .../InsightWindow/InsightWindow.hpp | 2 + .../TargetMemoryInspectionPane.cpp | 89 ++++++++++--- .../TargetMemoryInspectionPane.hpp | 3 + .../UiFiles/TargetMemoryInspectionPane.ui | 3 + 5 files changed, 183 insertions(+), 36 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 5541af0c..e5b05675 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -553,8 +553,27 @@ namespace Bloom ); bottomPanelLayout->addWidget(this->ramInspectionPane); + + QObject::connect( + this->ramInspectionPane, + &PaneWidget::paneActivated, + this, + &InsightWindow::onRamInspectionPaneStateChanged + ); + QObject::connect( + this->ramInspectionPane, + &PaneWidget::paneDeactivated, + this, + &InsightWindow::onRamInspectionPaneStateChanged + ); + QObject::connect( + this->ramInspectionPane, + &PaneWidget::paneAttached, + this, + &InsightWindow::onRamInspectionPaneStateChanged + ); + this->ramInspectionPane->deactivate(); - this->ramInspectionButton->setChecked(false); this->ramInspectionButton->setDisabled(false); } @@ -573,8 +592,27 @@ namespace Bloom ); bottomPanelLayout->addWidget(this->eepromInspectionPane); + + QObject::connect( + this->eepromInspectionPane, + &PaneWidget::paneActivated, + this, + &InsightWindow::onEepromInspectionPaneStateChanged + ); + QObject::connect( + this->eepromInspectionPane, + &PaneWidget::paneDeactivated, + this, + &InsightWindow::onEepromInspectionPaneStateChanged + ); + QObject::connect( + this->eepromInspectionPane, + &PaneWidget::paneAttached, + this, + &InsightWindow::onEepromInspectionPaneStateChanged + ); + this->eepromInspectionPane->deactivate(); - this->eepromInspectionButton->setChecked(false); this->eepromInspectionButton->setDisabled(false); } } @@ -837,33 +875,83 @@ namespace Bloom void InsightWindow::toggleRamInspectionPane() { if (this->ramInspectionPane->activated) { + if (!this->ramInspectionPane->attached) { + this->ramInspectionPane->activateWindow(); + this->ramInspectionButton->setChecked(true); + + return; + } + this->ramInspectionPane->deactivate(); - this->ramInspectionButton->setChecked(false); } else { - if (this->eepromInspectionPane != nullptr && this->eepromInspectionPane->activated) { - this->toggleEepromInspectionPane(); + if ( + this->ramInspectionPane->attached + && this->eepromInspectionPane != nullptr + && this->eepromInspectionPane->activated + && this->eepromInspectionPane->attached + ) { + this->eepromInspectionPane->deactivate(); } this->ramInspectionPane->activate(); - this->ramInspectionButton->setChecked(true); + } + } + + void InsightWindow::toggleEepromInspectionPane() { + if (this->eepromInspectionPane->activated) { + if (!this->eepromInspectionPane->attached) { + this->eepromInspectionPane->activateWindow(); + this->eepromInspectionButton->setChecked(true); + + return; + } + + this->eepromInspectionPane->deactivate(); + + } else { + if ( + this->eepromInspectionPane->attached + && this->ramInspectionPane != nullptr + && this->ramInspectionPane->activated + && this->ramInspectionPane->attached + ) { + this->ramInspectionPane->deactivate(); + } + + this->eepromInspectionPane->activate(); + } + } + + void InsightWindow::onRamInspectionPaneStateChanged() { + this->ramInspectionButton->setChecked(this->ramInspectionPane->activated); + + if ( + this->ramInspectionPane->activated + && this->ramInspectionPane->attached + && this->eepromInspectionPane != nullptr + && this->eepromInspectionPane->activated + && this->eepromInspectionPane->attached + ) { + // Both panes cannot be attached and activated at the same time. + this->eepromInspectionPane->deactivate(); } this->adjustMinimumSize(); } - void InsightWindow::toggleEepromInspectionPane() { - if (this->eepromInspectionPane->activated) { - this->eepromInspectionPane->deactivate(); - this->eepromInspectionButton->setChecked(false); + void InsightWindow::onEepromInspectionPaneStateChanged() { + this->eepromInspectionButton->setChecked(this->eepromInspectionPane->activated); - } else { - if (this->ramInspectionPane != nullptr && this->ramInspectionPane->activated) { - this->toggleRamInspectionPane(); - } - - this->eepromInspectionPane->activate(); - this->eepromInspectionButton->setChecked(true); + if ( + this->eepromInspectionPane->activated + && this->eepromInspectionPane->attached + && this->ramInspectionPane != nullptr + && this->ramInspectionPane->activated + && this->ramInspectionPane->attached + ) { + // Both panes cannot be attached and activated at the same time. + this->ramInspectionPane->deactivate(); } this->adjustMinimumSize(); diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index 0049cb58..eeb3cf13 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -139,6 +139,8 @@ namespace Bloom void toggleTargetRegistersPane(); void toggleRamInspectionPane(); void toggleEepromInspectionPane(); + void onRamInspectionPaneStateChanged(); + void onEepromInspectionPaneStateChanged(); void onProgrammingModeEnabled(); void onProgrammingModeDisabled(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index 3500a7bb..e9c313bb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -32,6 +32,15 @@ namespace Bloom::Widgets { this->setObjectName("target-memory-inspection-pane"); + const auto memoryName = QString( + this->targetMemoryDescriptor.type == TargetMemoryType::EEPROM + ? "Internal EEPROM" + : "Internal RAM" + ); + + this->setWindowTitle("Memory Inspection - " + memoryName); + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + auto memoryInspectionPaneUiFile = QFile( QString::fromStdString(Paths::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui" @@ -44,15 +53,13 @@ namespace Bloom::Widgets auto uiLoader = UiLoader(this); this->container = uiLoader.load(&memoryInspectionPaneUiFile, this); - this->container->setFixedSize(parent->width(), parent->maximumHeight()); + this->container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); this->titleBar = this->container->findChild("title-bar"); this->titleBar->layout()->setContentsMargins(7, 0, 7, 0); auto* titleLabel = this->titleBar->findChild("title"); - titleLabel->setText( - this->targetMemoryDescriptor.type == TargetMemoryType::EEPROM ? "Internal EEPROM" : "Internal RAM" - ); + titleLabel->setText(memoryName); // Quick sanity check to ensure the validity of persisted settings. this->sanitiseSettings(); @@ -73,6 +80,34 @@ namespace Bloom::Widgets subContainerLayout->insertWidget(1, this->hexViewerWidget); + QObject::connect( + this, + &PaneWidget::paneActivated, + this, + &TargetMemoryInspectionPane::postActivate + ); + + QObject::connect( + this, + &PaneWidget::paneDeactivated, + this, + &TargetMemoryInspectionPane::postDeactivate + ); + + QObject::connect( + this, + &PaneWidget::paneAttached, + this, + &TargetMemoryInspectionPane::postAttach + ); + + QObject::connect( + this, + &PaneWidget::paneDetached, + this, + &TargetMemoryInspectionPane::postDetach + ); + QObject::connect( this->manageMemoryRegionsButton, &QToolButton::clicked, @@ -80,6 +115,20 @@ namespace Bloom::Widgets &TargetMemoryInspectionPane::openMemoryRegionManagerWindow ); + QObject::connect( + this->detachPaneButton, + &QToolButton::clicked, + this, + &TargetMemoryInspectionPane::detach + ); + + QObject::connect( + this->attachPaneButton, + &QToolButton::clicked, + this, + &TargetMemoryInspectionPane::attach + ); + QObject::connect( &insightWorker, &InsightWorker::targetStateUpdated, @@ -181,22 +230,14 @@ namespace Bloom::Widgets this->insightWorker.queueTask(readMemoryTask); } - void TargetMemoryInspectionPane::activate() { - this->show(); - this->activated = true; - this->postActivate(); - } - - void TargetMemoryInspectionPane::deactivate() { - this->hide(); - this->activated = false; - this->postDeactivate(); - } - void TargetMemoryInspectionPane::resizeEvent(QResizeEvent* event) { - const auto parentSize = this->parentPanel->size(); - const auto width = parentSize.width() - 1; - this->container->setFixedSize(width, parentSize.height()); + const auto size = this->size(); + this->container->setFixedSize(size.width() - 1, size.height()); + } + + void TargetMemoryInspectionPane::closeEvent(QCloseEvent* event) { + this->deactivate(); + QWidget::closeEvent(event); } void TargetMemoryInspectionPane::postActivate() { @@ -211,6 +252,16 @@ namespace Bloom::Widgets } + void TargetMemoryInspectionPane::postAttach() { + this->attachPaneButton->hide(); + this->detachPaneButton->show(); + } + + void TargetMemoryInspectionPane::postDetach() { + this->detachPaneButton->hide(); + this->attachPaneButton->show(); + } + void TargetMemoryInspectionPane::sanitiseSettings() { // Remove any invalid memory regions. It's very unlikely that there will be any, but not impossible. auto processedFocusedMemoryRegions = std::vector(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp index 519bae28..7bd47d0f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp @@ -38,9 +38,12 @@ namespace Bloom::Widgets protected: void resizeEvent(QResizeEvent* event) override; + void closeEvent(QCloseEvent* event) override; void postActivate(); void postDeactivate(); + void postAttach(); + void postDetach(); private: const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui index 9bfe000b..563e86bb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui @@ -1,6 +1,9 @@ + + + 0