From b0b167453d75bc06cbd32de3f9fbddb0c7615281 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 13 Aug 2022 18:41:52 +0100 Subject: [PATCH] Made managing of PanelState object consistent with the managing of other state objects --- .../InsightWindow/InsightWindow.cpp | 44 ++++++++---- .../InsightWindow/InsightWindow.hpp | 2 - .../InsightWindow/UiFiles/InsightWindow.ui | 51 ++------------ .../UserInterfaces/InsightWindow/UiLoader.cpp | 10 --- .../InsightWindow/Widgets/PanelState.hpp | 2 - .../InsightWindow/Widgets/PanelWidget.cpp | 69 ++++++++++--------- .../InsightWindow/Widgets/PanelWidget.hpp | 18 +---- 7 files changed, 74 insertions(+), 122 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 7be678fc..912e29cb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -97,6 +97,9 @@ namespace Bloom ); this->ioUnavailableWidget = this->windowContainer->findChild("io-inspection-unavailable"); + auto* horizontalContentLayout = this->container->findChild("horizontal-content-layout"); + auto* verticalContentLayout = this->container->findChild("vertical-content-layout"); + auto* fileMenu = this->mainMenuBar->findChild("file-menu"); auto* helpMenu = this->mainMenuBar->findChild("help-menu"); auto* quitAction = fileMenu->findChild("close-insight"); @@ -107,8 +110,25 @@ namespace Bloom this->header = this->windowContainer->findChild("header"); this->refreshIoInspectionButton = this->header->findChild("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("left-side-menu-bar"); - this->leftPanel = this->container->findChild("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("target-registers-btn"); auto* targetRegisterButtonLayout = this->targetRegistersButton->findChild(); @@ -118,7 +138,14 @@ namespace Bloom targetRegisterButtonLayout->insertWidget(0, registersBtnLabel, 0, Qt::AlignTop); this->bottomMenuBar = this->container->findChild("bottom-menu-bar"); - this->bottomPanel = this->container->findChild("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("ram-inspection-btn"); this->eepromInspectionButton = this->container->findChild("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(); - } - } - } } diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index f51bead9..f94d0929 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -144,7 +144,5 @@ namespace Bloom void onEepromInspectionPaneStateChanged(); void onProgrammingModeEnabled(); void onProgrammingModeDisabled(); - - void recordInsightSettings(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui b/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui index 8c636419..0489892d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui +++ b/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui @@ -183,7 +183,7 @@ - + 0 @@ -191,37 +191,14 @@ 0 - + 0 0 - - - - false - - - 300 - - - 300 - - - 6 - - - - 0 - - - 0 - - - - + @@ -244,27 +221,7 @@ - - - - false - - - PanelWidgetType::BOTTOM - - - 10 - - - - 0 - - - 0 - - - - + diff --git a/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp index 79e9d5fb..9a0e42af 100644 --- a/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp @@ -3,7 +3,6 @@ #include // 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) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp index bc47dc2c..cc710ff8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp @@ -6,7 +6,5 @@ namespace Bloom::Widgets { int size = 0; bool open = false; - - PanelState(int size, bool open): size(size), open(open) {}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp index 41d85a96..9922ec86 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp @@ -1,61 +1,66 @@ #include "PanelWidget.hpp" -#include +#include +#include #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(); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp index 2cde460e..66bd9761 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp @@ -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).