Refactored PaneState management across the PaneWidget
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
PaneWidget::PaneWidget(PanelWidget* parent)
|
||||
: QWidget(parent)
|
||||
PaneWidget::PaneWidget(PaneState& state, PanelWidget* parent)
|
||||
: state(state)
|
||||
, parentPanel(parent)
|
||||
, QWidget(parent)
|
||||
{
|
||||
this->setMouseTracking(false);
|
||||
this->setAttribute(Qt::WA_Hover, true);
|
||||
@@ -16,94 +17,57 @@ namespace Bloom::Widgets
|
||||
QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility);
|
||||
}
|
||||
|
||||
PaneState PaneWidget::getCurrentState() const {
|
||||
return PaneState(
|
||||
this->activated,
|
||||
this->attached,
|
||||
this->getDetachedWindowState()
|
||||
);
|
||||
}
|
||||
|
||||
void PaneWidget::activate() {
|
||||
if (this->activated) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->show();
|
||||
this->activated = true;
|
||||
this->state.activated = true;
|
||||
emit this->paneActivated();
|
||||
}
|
||||
|
||||
void PaneWidget::deactivate() {
|
||||
if (!this->activated) {
|
||||
return;
|
||||
if (this->isVisible()) {
|
||||
this->hide();
|
||||
}
|
||||
|
||||
this->hide();
|
||||
this->activated = false;
|
||||
this->state.activated = false;
|
||||
emit this->paneDeactivated();
|
||||
}
|
||||
|
||||
void PaneWidget::restoreLastPaneState(const PaneState& lastPaneState) {
|
||||
if (lastPaneState.detachedWindowState.has_value()) {
|
||||
this->lastDetachedWindowState = lastPaneState.detachedWindowState;
|
||||
}
|
||||
|
||||
if (!lastPaneState.attached && lastPaneState.detachedWindowState.has_value()) {
|
||||
this->detach();
|
||||
}
|
||||
|
||||
if (lastPaneState.activated) {
|
||||
this->activate();
|
||||
}
|
||||
}
|
||||
|
||||
void PaneWidget::detach() {
|
||||
if (!this->attached) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->setWindowFlag(Qt::Window);
|
||||
|
||||
if (this->lastDetachedWindowState.has_value()) {
|
||||
this->resize(this->lastDetachedWindowState->size);
|
||||
this->move(this->lastDetachedWindowState->position);
|
||||
if (this->state.detachedWindowState.has_value()) {
|
||||
this->resize(this->state.detachedWindowState->size);
|
||||
this->move(this->state.detachedWindowState->position);
|
||||
|
||||
} else {
|
||||
this->state.detachedWindowState = DetachedWindowState(this->size(), this->pos());
|
||||
}
|
||||
|
||||
if (this->activated) {
|
||||
this->show();
|
||||
}
|
||||
|
||||
this->attached = false;
|
||||
this->state.attached = false;
|
||||
emit this->paneDetached();
|
||||
}
|
||||
|
||||
void PaneWidget::attach() {
|
||||
if (this->attached) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->lastDetachedWindowState = this->getDetachedWindowState();
|
||||
this->setWindowFlag(Qt::Window, false);
|
||||
|
||||
if (this->activated) {
|
||||
this->show();
|
||||
}
|
||||
|
||||
this->attached = true;
|
||||
this->state.attached = true;
|
||||
emit this->paneAttached();
|
||||
}
|
||||
|
||||
void PaneWidget::resizeEvent(QResizeEvent* event) {
|
||||
if (!this->state.attached && this->state.detachedWindowState.has_value()) {
|
||||
this->state.detachedWindowState->size = this->size();
|
||||
}
|
||||
}
|
||||
|
||||
void PaneWidget::moveEvent(QMoveEvent* event) {
|
||||
if (!this->state.attached && this->state.detachedWindowState.has_value()) {
|
||||
this->state.detachedWindowState->position = this->pos();
|
||||
}
|
||||
}
|
||||
|
||||
void PaneWidget::closeEvent(QCloseEvent* event) {
|
||||
this->deactivate();
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
std::optional<DetachedWindowState> PaneWidget::getDetachedWindowState() const {
|
||||
if (!this->attached) {
|
||||
return DetachedWindowState(this->size(), this->pos());
|
||||
}
|
||||
|
||||
return this->lastDetachedWindowState;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QEvent>
|
||||
#include <optional>
|
||||
|
||||
#include "PanelWidget.hpp"
|
||||
@@ -13,19 +14,14 @@ namespace Bloom::Widgets
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
bool activated = true;
|
||||
bool attached = true;
|
||||
PaneState& state;
|
||||
PanelWidget* parentPanel = nullptr;
|
||||
|
||||
explicit PaneWidget(PanelWidget* parent);
|
||||
|
||||
[[nodiscard]] PaneState getCurrentState() const;
|
||||
explicit PaneWidget(PaneState& state, PanelWidget* parent);
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
void restoreLastPaneState(const PaneState& lastPaneState);
|
||||
|
||||
signals:
|
||||
void paneActivated();
|
||||
void paneDeactivated();
|
||||
@@ -36,11 +32,8 @@ namespace Bloom::Widgets
|
||||
void detach();
|
||||
void attach();
|
||||
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void moveEvent(QMoveEvent* event) override;
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
private:
|
||||
std::optional<DetachedWindowState> lastDetachedWindowState;
|
||||
|
||||
std::optional<DetachedWindowState> getDetachedWindowState() const;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Bloom::Widgets
|
||||
|
||||
auto visible = false;
|
||||
for (const auto& paneWidget : paneWidgets) {
|
||||
if (paneWidget->activated && paneWidget->attached) {
|
||||
if (paneWidget->state.activated && paneWidget->state.attached) {
|
||||
visible = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,10 @@ namespace Bloom::Widgets
|
||||
const TargetMemoryDescriptor& targetMemoryDescriptor,
|
||||
TargetMemoryInspectionPaneSettings& settings,
|
||||
InsightWorker& insightWorker,
|
||||
PaneState& paneState,
|
||||
PanelWidget* parent
|
||||
)
|
||||
: PaneWidget(parent)
|
||||
: PaneWidget(paneState, parent)
|
||||
, targetMemoryDescriptor(targetMemoryDescriptor)
|
||||
, settings(settings)
|
||||
, insightWorker(insightWorker)
|
||||
@@ -185,6 +186,15 @@ namespace Bloom::Widgets
|
||||
this,
|
||||
&TargetMemoryInspectionPane::onProgrammingModeDisabled
|
||||
);
|
||||
|
||||
// Restore the state
|
||||
if (!this->state.attached) {
|
||||
this->detach();
|
||||
}
|
||||
|
||||
if (this->state.activated) {
|
||||
this->activate();
|
||||
}
|
||||
}
|
||||
|
||||
void TargetMemoryInspectionPane::refreshMemoryValues(std::optional<std::function<void(void)>> callback) {
|
||||
@@ -368,7 +378,7 @@ namespace Bloom::Widgets
|
||||
using Targets::TargetState;
|
||||
this->targetState = newState;
|
||||
|
||||
if (newState == TargetState::STOPPED && this->activated) {
|
||||
if (newState == TargetState::STOPPED && this->state.activated) {
|
||||
if (this->settings.refreshOnTargetStop || !this->data.has_value()) {
|
||||
this->refreshMemoryValues([this] {
|
||||
this->hexViewerWidget->setDisabled(false);
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Bloom::Widgets
|
||||
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor,
|
||||
TargetMemoryInspectionPaneSettings& settings,
|
||||
InsightWorker& insightWorker,
|
||||
PaneState& paneState,
|
||||
PanelWidget* parent
|
||||
);
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ namespace Bloom::Widgets
|
||||
TargetRegistersPaneWidget::TargetRegistersPaneWidget(
|
||||
const TargetDescriptor& targetDescriptor,
|
||||
InsightWorker& insightWorker,
|
||||
PaneState& paneState,
|
||||
PanelWidget* parent
|
||||
)
|
||||
: PaneWidget(parent)
|
||||
: PaneWidget(paneState, parent)
|
||||
, targetDescriptor(targetDescriptor)
|
||||
, insightWorker(insightWorker)
|
||||
{
|
||||
@@ -141,6 +142,16 @@ namespace Bloom::Widgets
|
||||
this,
|
||||
&TargetRegistersPaneWidget::onRegistersRead
|
||||
);
|
||||
|
||||
// Restore the state
|
||||
if (!this->state.attached) {
|
||||
// The register pane cannot be detached.
|
||||
this->state.attached = true;
|
||||
}
|
||||
|
||||
if (this->state.activated) {
|
||||
this->activate();
|
||||
}
|
||||
}
|
||||
|
||||
void TargetRegistersPaneWidget::filterRegisters(const QString& keyword) {
|
||||
@@ -244,7 +255,7 @@ namespace Bloom::Widgets
|
||||
using Targets::TargetState;
|
||||
this->targetState = newState;
|
||||
|
||||
if (newState == TargetState::STOPPED && this->activated) {
|
||||
if (newState == TargetState::STOPPED && this->state.activated) {
|
||||
this->refreshRegisterValues();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Bloom::Widgets
|
||||
TargetRegistersPaneWidget(
|
||||
const Targets::TargetDescriptor& targetDescriptor,
|
||||
InsightWorker& insightWorker,
|
||||
PaneState& paneState,
|
||||
PanelWidget *parent
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user