diff --git a/src/Insight/CMakeLists.txt b/src/Insight/CMakeLists.txt index d43f4ae6..1fe05de1 100755 --- a/src/Insight/CMakeLists.txt +++ b/src/Insight/CMakeLists.txt @@ -7,7 +7,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/BloomProxyStyle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/InsightWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/AboutWindow.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/Label.hpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 1e2f4c70..5541af0c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -827,16 +827,9 @@ namespace Bloom this->targetRegistersSidePane->deactivate(); this->targetRegistersButton->setChecked(false); - /* - * Given that the target registers side pane is currently the only pane in the left panel, the panel - * will be empty so no need to leave it visible. - */ - this->leftPanel->setVisible(false); - } else { this->targetRegistersSidePane->activate(); this->targetRegistersButton->setChecked(true); - this->leftPanel->setVisible(true); } this->adjustMinimumSize(); @@ -845,7 +838,6 @@ namespace Bloom void InsightWindow::toggleRamInspectionPane() { if (this->ramInspectionPane->activated) { this->ramInspectionPane->deactivate(); - this->bottomPanel->hide(); this->ramInspectionButton->setChecked(false); } else { @@ -854,7 +846,6 @@ namespace Bloom } this->ramInspectionPane->activate(); - this->bottomPanel->show(); this->ramInspectionButton->setChecked(true); } @@ -864,7 +855,6 @@ namespace Bloom void InsightWindow::toggleEepromInspectionPane() { if (this->eepromInspectionPane->activated) { this->eepromInspectionPane->deactivate(); - this->bottomPanel->hide(); this->eepromInspectionButton->setChecked(false); } else { @@ -873,7 +863,6 @@ namespace Bloom } this->eepromInspectionPane->activate(); - this->bottomPanel->show(); this->eepromInspectionButton->setChecked(true); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp new file mode 100644 index 00000000..27e94538 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp @@ -0,0 +1,55 @@ +#include "PaneWidget.hpp" + +namespace Bloom::Widgets +{ + PaneWidget::PaneWidget(PanelWidget* parent) + : QWidget(parent) + , parentPanel(parent) + { + this->setMouseTracking(false); + this->setAttribute(Qt::WA_Hover, true); + + QObject::connect(this, &PaneWidget::paneActivated, parent, &PanelWidget::updateVisibility); + QObject::connect(this, &PaneWidget::paneDeactivated, parent, &PanelWidget::updateVisibility); + + QObject::connect(this, &PaneWidget::paneAttached, parent, &PanelWidget::updateVisibility); + QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility); + } + + void PaneWidget::activate() { + if (this->activated) { + return; + } + + this->show(); + this->activated = true; + emit this->paneActivated(); + } + + void PaneWidget::deactivate() { + if (!this->activated) { + return; + } + + this->hide(); + this->activated = false; + emit this->paneDeactivated(); + } + + void PaneWidget::detach() { + this->setWindowFlag(Qt::Window); + this->show(); + + this->attached = false; + emit this->paneDetached(); + } + + void PaneWidget::attach() { + this->setWindowFlag(Qt::Window, false); + this->hide(); + this->show(); + + this->attached = true; + emit this->paneAttached(); + } +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp index dfd74c10..f4e59056 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp @@ -12,15 +12,29 @@ namespace Bloom::Widgets Q_OBJECT public: - bool activated = false; + bool activated = true; + bool attached = true; PanelWidget* parentPanel = nullptr; - explicit PaneWidget(PanelWidget* parent): QWidget(parent), parentPanel(parent) {}; + explicit PaneWidget(PanelWidget* parent); [[nodiscard]] PaneState getCurrentState() const { return PaneState( this->activated ); } + + void activate(); + void deactivate(); + + signals: + void paneActivated(); + void paneDeactivated(); + void paneAttached(); + void paneDetached(); + + protected: + void detach(); + void attach(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp index 22ef7a6f..5b069ee1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp @@ -2,6 +2,8 @@ #include +#include "PaneWidget.hpp" + namespace Bloom::Widgets { PanelWidget::PanelWidget(QWidget* parent): QFrame(parent) { @@ -57,6 +59,20 @@ namespace Bloom::Widgets } } + void PanelWidget::updateVisibility() { + const auto paneWidgets = this->findChildren(); + + auto visible = false; + for (const auto& paneWidget : paneWidgets) { + if (paneWidget->activated && paneWidget->attached) { + visible = true; + break; + } + } + + this->setVisible(visible); + } + bool PanelWidget::event(QEvent* event) { if (event->type() == QEvent::Type::HoverMove) { auto* hoverEvent = dynamic_cast(event); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp index 20268808..8deb288f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp @@ -64,6 +64,15 @@ namespace Bloom::Widgets ); } + /** + * Will evaluate whether the panel should still be visible or not (depending on whether there are any + * visible and attached child panes). + * + * This function is called whenever a child pane is activated/deactivate/attached/detached. + * See PaneWidget::PaneWidget() for more. + */ + void updateVisibility(); + protected: int handleSize = 10; int minimumResize = 10; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp index 5932cf7f..4f80fc4e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp @@ -35,14 +35,12 @@ namespace Bloom::Widgets ); void refreshMemoryValues(std::optional> callback = std::nullopt); - void activate(); - void deactivate(); protected: void resizeEvent(QResizeEvent* event) override; - virtual void postActivate(); - virtual void postDeactivate(); + void postActivate(); + void postDeactivate(); private: const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index 5ce79633..8dc4ce98 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -114,6 +114,20 @@ namespace Bloom::Widgets itemLayout->addStretch(1); + QObject::connect( + this, + &PaneWidget::paneActivated, + this, + &TargetRegistersPaneWidget::postActivate + ); + + QObject::connect( + this, + &PaneWidget::paneDeactivated, + this, + &TargetRegistersPaneWidget::postDeactivate + ); + QObject::connect( &insightWorker, &InsightWorker::targetStateUpdated, @@ -188,18 +202,6 @@ namespace Bloom::Widgets this->insightWorker.queueTask(readRegisterTask); } - void TargetRegistersPaneWidget::activate() { - this->show(); - this->activated = true; - this->postActivate(); - } - - void TargetRegistersPaneWidget::deactivate() { - this->hide(); - this->activated = false; - this->postDeactivate(); - } - void TargetRegistersPaneWidget::onItemSelectionChange(ItemWidget* newlySelectedWidget) { // Only one item in the target registers pane can be selected at any given time. if (this->selectedItemWidget != newlySelectedWidget) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp index 486ea617..404e85d2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp @@ -38,16 +38,13 @@ namespace Bloom::Widgets void refreshRegisterValues(std::optional> callback = std::nullopt); - void activate(); - void deactivate(); - void onItemSelectionChange(Bloom::Widgets::ItemWidget* newlySelectedWidget); protected: void resizeEvent(QResizeEvent* event) override; - virtual void postActivate(); - virtual void postDeactivate(); + void postActivate(); + void postDeactivate(); private: const Targets::TargetDescriptor& targetDescriptor;