Made managing of PanelState object consistent with the managing of other state objects

This commit is contained in:
Nav
2022-08-13 18:41:52 +01:00
parent d646e06efe
commit b0b167453d
7 changed files with 74 additions and 122 deletions

View File

@@ -97,6 +97,9 @@ namespace Bloom
);
this->ioUnavailableWidget = this->windowContainer->findChild<Label*>("io-inspection-unavailable");
auto* horizontalContentLayout = this->container->findChild<QHBoxLayout*>("horizontal-content-layout");
auto* verticalContentLayout = this->container->findChild<QVBoxLayout*>("vertical-content-layout");
auto* fileMenu = this->mainMenuBar->findChild<QMenu*>("file-menu");
auto* helpMenu = this->mainMenuBar->findChild<QMenu*>("help-menu");
auto* quitAction = fileMenu->findChild<QAction*>("close-insight");
@@ -107,8 +110,25 @@ namespace Bloom
this->header = this->windowContainer->findChild<QWidget*>("header");
this->refreshIoInspectionButton = this->header->findChild<SvgToolButton*>("refresh-io-inspection-btn");
// Create panel states
if (!this->insightProjectSettings.previousLeftPanelState.has_value()) {
this->insightProjectSettings.previousLeftPanelState = PanelState();
}
if (!this->insightProjectSettings.previousBottomPanelState.has_value()) {
this->insightProjectSettings.previousBottomPanelState = PanelState();
}
this->leftMenuBar = this->container->findChild<QWidget*>("left-side-menu-bar");
this->leftPanel = this->container->findChild<PanelWidget*>("left-panel");
this->leftPanel = new PanelWidget(
PanelWidgetType::LEFT,
this->insightProjectSettings.previousLeftPanelState.value(),
this->container
);
this->leftPanel->setObjectName("left-panel");
this->leftPanel->setHandleSize(6);
this->leftPanel->setMinimumResize(300);
horizontalContentLayout->insertWidget(0, this->leftPanel);
this->targetRegistersButton = this->container->findChild<QToolButton*>("target-registers-btn");
auto* targetRegisterButtonLayout = this->targetRegistersButton->findChild<QVBoxLayout*>();
@@ -118,7 +138,14 @@ namespace Bloom
targetRegisterButtonLayout->insertWidget(0, registersBtnLabel, 0, Qt::AlignTop);
this->bottomMenuBar = this->container->findChild<QWidget*>("bottom-menu-bar");
this->bottomPanel = this->container->findChild<PanelWidget*>("bottom-panel");
this->bottomPanel = new PanelWidget(
PanelWidgetType::BOTTOM,
this->insightProjectSettings.previousBottomPanelState.value(),
this->container
);
this->bottomPanel->setObjectName("bottom-panel");
this->bottomPanel->setHandleSize(10);
verticalContentLayout->insertWidget(1, this->bottomPanel);
this->ramInspectionButton = this->container->findChild<QToolButton*>("ram-inspection-btn");
this->eepromInspectionButton = this->container->findChild<QToolButton*>("eeprom-inspection-btn");
@@ -276,7 +303,6 @@ namespace Bloom
}
void InsightWindow::closeEvent(QCloseEvent* event) {
this->recordInsightSettings();
return QMainWindow::closeEvent(event);
}
@@ -997,16 +1023,4 @@ namespace Bloom
void InsightWindow::onProgrammingModeDisabled() {
this->onTargetStateUpdate(this->targetState);
}
void InsightWindow::recordInsightSettings() {
if (this->activated) {
if (this->leftPanel != nullptr) {
this->insightProjectSettings.previousLeftPanelState = this->leftPanel->getCurrentState();
}
if (this->bottomPanel != nullptr) {
this->insightProjectSettings.previousBottomPanelState = this->bottomPanel->getCurrentState();
}
}
}
}

View File

@@ -144,7 +144,5 @@ namespace Bloom
void onEepromInspectionPaneStateChanged();
void onProgrammingModeEnabled();
void onProgrammingModeDisabled();
void recordInsightSettings();
};
}

View File

@@ -183,7 +183,7 @@
</widget>
</item>
<item>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="vertical-content-layout">
<property name="spacing">
<number>0</number>
</property>
@@ -191,37 +191,14 @@
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout">
<layout class="QHBoxLayout" name="horizontal-content-layout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="PanelWidget" name="left-panel">
<property name="visible">
<bool>false</bool>
</property>
<property name="maximumWidth">
<number>300</number>
</property>
<property name="minimumResize">
<number>300</number>
</property>
<property name="handleSize">
<number>6</number>
</property>
<layout class="QVBoxLayout" name="left-panel-layout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<!-- The left panel is inserted here. See InsightWindow::InsightWindow() for more -->
<item>
<widget class="TargetPackageWidgetContainer" name="io-container">
<property name="sizePolicy">
@@ -244,27 +221,7 @@
</item>
</layout>
</item>
<item>
<widget class="PanelWidget" name="bottom-panel">
<property name="visible">
<bool>false</bool>
</property>
<property name="panelType">
<enum>PanelWidgetType::BOTTOM</enum>
</property>
<property name="handleSize">
<number>10</number>
</property>
<layout class="QHBoxLayout" name="bottom-panel-layout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<!-- The bottom panel is inserted here. See InsightWindow::InsightWindow() for more -->
</layout>
</item>
</layout>

View File

@@ -3,7 +3,6 @@
#include <QtUiTools>
// Custom widgets
#include "Widgets/PanelWidget.hpp"
#include "Widgets/Label.hpp"
#include "Widgets/RotatableLabel.hpp"
#include "Widgets/LabeledSeparator.hpp"
@@ -19,15 +18,6 @@ namespace Bloom
UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
this->customWidgetConstructorsByWidgetName = decltype(this->customWidgetConstructorsByWidgetName) {
{
"PanelWidget",
[this] (QWidget* parent, const QString& name) {
auto* widget = new PanelWidget(parent);
widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet());
return widget;
}
},
{
"Label",
[this] (QWidget* parent, const QString& name) {

View File

@@ -6,7 +6,5 @@ namespace Bloom::Widgets
{
int size = 0;
bool open = false;
PanelState(int size, bool open): size(size), open(open) {};
};
}

View File

@@ -1,61 +1,66 @@
#include "PanelWidget.hpp"
#include <QLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "PaneWidget.hpp"
namespace Bloom::Widgets
{
PanelWidget::PanelWidget(QWidget* parent): QFrame(parent) {
PanelWidget::PanelWidget(PanelWidgetType type, PanelState& state, QWidget* parent)
: panelType(type)
, state(state)
, QFrame(parent)
{
this->setMouseTracking(false);
this->setAttribute(Qt::WA_Hover, true);
if (this->panelType == PanelWidgetType::LEFT) {
this->resizeCursor = Qt::SplitHCursor;
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
auto* layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
this->setLayout(layout);
} else {
this->resizeCursor = Qt::SplitVCursor;
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
auto* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
this->setLayout(layout);
}
}
void PanelWidget::setMinimumResize(int minimumResize) {
this->minimumResize = minimumResize;
const auto currentSize = this->size();
if (this->panelType == PanelWidgetType::LEFT && currentSize.width() < this->minimumResize) {
this->setFixedWidth(this->minimumResize);
} else if (this->panelType == PanelWidgetType::BOTTOM && currentSize.height() < this->minimumResize) {
this->setFixedHeight(this->minimumResize);
if (this->state.size < this->minimumResize) {
this->setSize(this->minimumResize);
}
}
void PanelWidget::setMaximumResize(int maximumResize) {
this->maximumResize = maximumResize;
const auto currentSize = this->size();
if (this->panelType == PanelWidgetType::LEFT && currentSize.width() > this->maximumResize) {
this->setFixedWidth(this->maximumResize);
} else if (this->panelType == PanelWidgetType::BOTTOM && currentSize.height() > this->maximumResize) {
this->setFixedHeight(this->maximumResize);
}
}
void PanelWidget::setPanelType(PanelWidgetType panelType) {
this->panelType = panelType;
if (this->panelType == PanelWidgetType::LEFT) {
this->resizeCursor = Qt::SplitHCursor;
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
} else {
this->resizeCursor = Qt::SplitVCursor;
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
if (this->state.size > this->maximumResize) {
this->setSize(this->maximumResize);
}
}
void PanelWidget::setSize(int size) {
if (this->panelType == PanelWidgetType::LEFT) {
this->setFixedWidth(std::min(std::max(size, this->minimumResize), this->maximumResize));
const auto width = std::min(std::max(size, this->minimumResize), this->maximumResize);
this->setFixedWidth(width);
this->state.size = width;
} else if (this->panelType == PanelWidgetType::BOTTOM) {
this->setFixedHeight(std::min(std::max(size, this->minimumResize), this->maximumResize));
const auto height = std::min(std::max(size, this->minimumResize), this->maximumResize);
this->setFixedHeight(height);
this->state.size = height;
}
}
@@ -85,9 +90,11 @@ namespace Bloom::Widgets
}
if (event->type() == QEvent::Type::Close || event->type() == QEvent::Type::Hide) {
this->state.open = false;
emit this->closed();
} else if (event->type() == QEvent::Type::Show) {
this->state.open = true;
emit this->opened();
}

View File

@@ -24,10 +24,11 @@ namespace Bloom::Widgets
Q_OBJECT
Q_PROPERTY(int handleSize READ getHandleSize WRITE setHandleSize DESIGNABLE true)
Q_PROPERTY(int minimumResize READ getMinimumResize WRITE setMinimumResize DESIGNABLE true)
Q_PROPERTY(Bloom::Widgets::PanelWidgetType panelType READ getPanelType WRITE setPanelType DESIGNABLE true)
public:
explicit PanelWidget(QWidget* parent);
PanelState& state;
explicit PanelWidget(PanelWidgetType type, PanelState& state, QWidget* parent);
void setHandleSize(int handleSize) {
this->handleSize = handleSize;
@@ -37,8 +38,6 @@ namespace Bloom::Widgets
void setMaximumResize(int maximumResize);
void setPanelType(PanelWidgetType panelType);
void setSize(int size);
[[nodiscard]] int getHandleSize() const {
@@ -53,17 +52,6 @@ namespace Bloom::Widgets
return this->maximumResize;
}
PanelWidgetType getPanelType() {
return this->panelType;
}
PanelState getCurrentState() {
return PanelState(
this->panelType == PanelWidgetType::LEFT ? this->width() : this->height(),
this->isVisible()
);
}
/**
* Will evaluate whether the panel should still be visible or not (depending on whether there are any
* visible and attached child panes).