Storing and restoring DetachedWindowState
This commit is contained in:
@@ -344,19 +344,24 @@ namespace Bloom
|
|||||||
|
|
||||||
if (lastBottomPanelState.has_value()) {
|
if (lastBottomPanelState.has_value()) {
|
||||||
this->bottomPanel->setSize(lastBottomPanelState->size);
|
this->bottomPanel->setSize(lastBottomPanelState->size);
|
||||||
|
|
||||||
if (this->ramInspectionPane != nullptr
|
|
||||||
&& this->insightProjectSettings.previousRamInspectionPaneState.has_value()
|
|
||||||
&& this->insightProjectSettings.previousRamInspectionPaneState->activated
|
|
||||||
) {
|
|
||||||
this->toggleRamInspectionPane();
|
|
||||||
|
|
||||||
} else if (this->eepromInspectionPane != nullptr
|
|
||||||
&& this->insightProjectSettings.previousEepromInspectionPaneState.has_value()
|
|
||||||
&& this->insightProjectSettings.previousEepromInspectionPaneState->activated
|
|
||||||
) {
|
|
||||||
this->toggleEepromInspectionPane();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this->ramInspectionPane != nullptr
|
||||||
|
&& this->insightProjectSettings.previousRamInspectionPaneState.has_value()
|
||||||
|
) {
|
||||||
|
this->ramInspectionPane->restoreLastPaneState(
|
||||||
|
this->insightProjectSettings.previousRamInspectionPaneState.value()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this->eepromInspectionPane != nullptr
|
||||||
|
&& this->insightProjectSettings.previousEepromInspectionPaneState.has_value()
|
||||||
|
) {
|
||||||
|
this->eepromInspectionPane->restoreLastPaneState(
|
||||||
|
this->insightProjectSettings.previousEepromInspectionPaneState.value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setUiDisabled(this->targetState != TargetState::STOPPED);
|
this->setUiDisabled(this->targetState != TargetState::STOPPED);
|
||||||
|
|||||||
@@ -1,11 +1,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QSize>
|
||||||
|
#include <QPoint>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Bloom::Widgets
|
namespace Bloom::Widgets
|
||||||
{
|
{
|
||||||
|
struct DetachedWindowState
|
||||||
|
{
|
||||||
|
QSize size;
|
||||||
|
QPoint position;
|
||||||
|
|
||||||
|
DetachedWindowState() = default;
|
||||||
|
|
||||||
|
DetachedWindowState(QSize size, QPoint position)
|
||||||
|
: size(size)
|
||||||
|
, position(position)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
struct PaneState
|
struct PaneState
|
||||||
{
|
{
|
||||||
bool activated = false;
|
bool activated = false;
|
||||||
|
bool attached = true;
|
||||||
|
|
||||||
explicit PaneState(bool activated): activated(activated) {};
|
std::optional<DetachedWindowState> detachedWindowState;
|
||||||
|
|
||||||
|
PaneState(
|
||||||
|
bool activated,
|
||||||
|
bool attached,
|
||||||
|
std::optional<DetachedWindowState> detachedWindowState
|
||||||
|
)
|
||||||
|
: activated(activated)
|
||||||
|
, attached(attached)
|
||||||
|
, detachedWindowState(detachedWindowState)
|
||||||
|
{};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ namespace Bloom::Widgets
|
|||||||
QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility);
|
QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PaneState PaneWidget::getCurrentState() const {
|
||||||
|
return PaneState(
|
||||||
|
this->activated,
|
||||||
|
this->attached,
|
||||||
|
this->getDetachedWindowState()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void PaneWidget::activate() {
|
void PaneWidget::activate() {
|
||||||
if (this->activated) {
|
if (this->activated) {
|
||||||
return;
|
return;
|
||||||
@@ -36,18 +44,51 @@ namespace Bloom::Widgets
|
|||||||
emit this->paneDeactivated();
|
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() {
|
void PaneWidget::detach() {
|
||||||
|
if (!this->attached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->setWindowFlag(Qt::Window);
|
this->setWindowFlag(Qt::Window);
|
||||||
|
|
||||||
|
if (this->lastDetachedWindowState.has_value()) {
|
||||||
|
this->resize(this->lastDetachedWindowState->size);
|
||||||
|
this->move(this->lastDetachedWindowState->position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->activated) {
|
||||||
this->show();
|
this->show();
|
||||||
|
}
|
||||||
|
|
||||||
this->attached = false;
|
this->attached = false;
|
||||||
emit this->paneDetached();
|
emit this->paneDetached();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaneWidget::attach() {
|
void PaneWidget::attach() {
|
||||||
|
if (this->attached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->lastDetachedWindowState = this->getDetachedWindowState();
|
||||||
this->setWindowFlag(Qt::Window, false);
|
this->setWindowFlag(Qt::Window, false);
|
||||||
this->hide();
|
|
||||||
|
if (this->activated) {
|
||||||
this->show();
|
this->show();
|
||||||
|
}
|
||||||
|
|
||||||
this->attached = true;
|
this->attached = true;
|
||||||
emit this->paneAttached();
|
emit this->paneAttached();
|
||||||
@@ -58,4 +99,11 @@ namespace Bloom::Widgets
|
|||||||
QWidget::closeEvent(event);
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "PanelWidget.hpp"
|
#include "PanelWidget.hpp"
|
||||||
#include "PaneState.hpp"
|
#include "PaneState.hpp"
|
||||||
@@ -18,15 +19,13 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
explicit PaneWidget(PanelWidget* parent);
|
explicit PaneWidget(PanelWidget* parent);
|
||||||
|
|
||||||
[[nodiscard]] PaneState getCurrentState() const {
|
[[nodiscard]] PaneState getCurrentState() const;
|
||||||
return PaneState(
|
|
||||||
this->activated
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void activate();
|
void activate();
|
||||||
void deactivate();
|
void deactivate();
|
||||||
|
|
||||||
|
void restoreLastPaneState(const PaneState& lastPaneState);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void paneActivated();
|
void paneActivated();
|
||||||
void paneDeactivated();
|
void paneDeactivated();
|
||||||
@@ -38,5 +37,10 @@ namespace Bloom::Widgets
|
|||||||
void attach();
|
void attach();
|
||||||
|
|
||||||
void closeEvent(QCloseEvent* event) override;
|
void closeEvent(QCloseEvent* event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::optional<DetachedWindowState> lastDetachedWindowState;
|
||||||
|
|
||||||
|
std::optional<DetachedWindowState> getDetachedWindowState() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,8 +292,34 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widgets::PaneState InsightProjectSettings::paneStateFromJson(const QJsonObject& jsonObject) const {
|
Widgets::PaneState InsightProjectSettings::paneStateFromJson(const QJsonObject& jsonObject) const {
|
||||||
|
auto detachedWindowState = std::optional<Widgets::DetachedWindowState>(std::nullopt);
|
||||||
|
|
||||||
|
if (jsonObject.contains("detachedWindowState")) {
|
||||||
|
detachedWindowState = Widgets::DetachedWindowState();
|
||||||
|
|
||||||
|
const auto detachedWindowStateObject = jsonObject.value("detachedWindowState").toObject();
|
||||||
|
|
||||||
|
if (detachedWindowStateObject.contains("size")) {
|
||||||
|
const auto sizeObject = detachedWindowStateObject.value("size").toObject();
|
||||||
|
detachedWindowState->size = QSize(
|
||||||
|
sizeObject.value("width").toInt(0),
|
||||||
|
sizeObject.value("height").toInt(0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detachedWindowStateObject.contains("position")) {
|
||||||
|
const auto positionObject = detachedWindowStateObject.value("position").toObject();
|
||||||
|
detachedWindowState->position = QPoint(
|
||||||
|
positionObject.value("x").toInt(0),
|
||||||
|
positionObject.value("y").toInt(0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Widgets::PaneState(
|
return Widgets::PaneState(
|
||||||
(jsonObject.contains("activated") ? jsonObject.value("activated").toBool() : false)
|
(jsonObject.contains("activated") ? jsonObject.value("activated").toBool() : false),
|
||||||
|
(jsonObject.contains("attached") ? jsonObject.value("attached").toBool() : true),
|
||||||
|
detachedWindowState
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,8 +402,30 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject InsightProjectSettings::paneStateToJson(const Widgets::PaneState& paneState) const {
|
QJsonObject InsightProjectSettings::paneStateToJson(const Widgets::PaneState& paneState) const {
|
||||||
return QJsonObject({
|
auto json = QJsonObject({
|
||||||
{"activated", paneState.activated},
|
{"activated", paneState.activated},
|
||||||
|
{"attached", paneState.attached},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (paneState.detachedWindowState.has_value()) {
|
||||||
|
json.insert("detachedWindowState", QJsonObject({
|
||||||
|
{
|
||||||
|
"size",
|
||||||
|
QJsonObject({
|
||||||
|
{"width", paneState.detachedWindowState->size.width()},
|
||||||
|
{"height", paneState.detachedWindowState->size.height()},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"position",
|
||||||
|
QJsonObject({
|
||||||
|
{"x", paneState.detachedWindowState->position.x()},
|
||||||
|
{"y", paneState.detachedWindowState->position.y()},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user