Storing and restoring DetachedWindowState
This commit is contained in:
@@ -344,19 +344,24 @@ namespace Bloom
|
||||
|
||||
if (lastBottomPanelState.has_value()) {
|
||||
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);
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSize>
|
||||
#include <QPoint>
|
||||
#include <optional>
|
||||
|
||||
namespace Bloom::Widgets
|
||||
{
|
||||
struct DetachedWindowState
|
||||
{
|
||||
QSize size;
|
||||
QPoint position;
|
||||
|
||||
DetachedWindowState() = default;
|
||||
|
||||
DetachedWindowState(QSize size, QPoint position)
|
||||
: size(size)
|
||||
, position(position)
|
||||
{}
|
||||
};
|
||||
|
||||
struct PaneState
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
PaneState PaneWidget::getCurrentState() const {
|
||||
return PaneState(
|
||||
this->activated,
|
||||
this->attached,
|
||||
this->getDetachedWindowState()
|
||||
);
|
||||
}
|
||||
|
||||
void PaneWidget::activate() {
|
||||
if (this->activated) {
|
||||
return;
|
||||
@@ -36,18 +44,51 @@ namespace Bloom::Widgets
|
||||
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->activated) {
|
||||
this->show();
|
||||
}
|
||||
|
||||
this->attached = false;
|
||||
emit this->paneDetached();
|
||||
}
|
||||
|
||||
void PaneWidget::attach() {
|
||||
if (this->attached) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->lastDetachedWindowState = this->getDetachedWindowState();
|
||||
this->setWindowFlag(Qt::Window, false);
|
||||
this->hide();
|
||||
|
||||
if (this->activated) {
|
||||
this->show();
|
||||
}
|
||||
|
||||
this->attached = true;
|
||||
emit this->paneAttached();
|
||||
@@ -58,4 +99,11 @@ namespace Bloom::Widgets
|
||||
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 <optional>
|
||||
|
||||
#include "PanelWidget.hpp"
|
||||
#include "PaneState.hpp"
|
||||
@@ -18,15 +19,13 @@ namespace Bloom::Widgets
|
||||
|
||||
explicit PaneWidget(PanelWidget* parent);
|
||||
|
||||
[[nodiscard]] PaneState getCurrentState() const {
|
||||
return PaneState(
|
||||
this->activated
|
||||
);
|
||||
}
|
||||
[[nodiscard]] PaneState getCurrentState() const;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
void restoreLastPaneState(const PaneState& lastPaneState);
|
||||
|
||||
signals:
|
||||
void paneActivated();
|
||||
void paneDeactivated();
|
||||
@@ -38,5 +37,10 @@ namespace Bloom::Widgets
|
||||
void attach();
|
||||
|
||||
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 {
|
||||
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(
|
||||
(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 {
|
||||
return QJsonObject({
|
||||
auto json = QJsonObject({
|
||||
{"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