Refactored Panel & Pane widgets

This commit is contained in:
Nav
2022-07-16 19:07:09 +01:00
parent ead867eb3e
commit e35fc3e8f2
9 changed files with 115 additions and 35 deletions

View File

@@ -7,7 +7,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/BloomProxyStyle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/InsightWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/AboutWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/Label.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp

View File

@@ -827,16 +827,9 @@ namespace Bloom
this->targetRegistersSidePane->deactivate();
this->targetRegistersButton->setChecked(false);
/*
* Given that the target registers side pane is currently the only pane in the left panel, the panel
* will be empty so no need to leave it visible.
*/
this->leftPanel->setVisible(false);
} else {
this->targetRegistersSidePane->activate();
this->targetRegistersButton->setChecked(true);
this->leftPanel->setVisible(true);
}
this->adjustMinimumSize();
@@ -845,7 +838,6 @@ namespace Bloom
void InsightWindow::toggleRamInspectionPane() {
if (this->ramInspectionPane->activated) {
this->ramInspectionPane->deactivate();
this->bottomPanel->hide();
this->ramInspectionButton->setChecked(false);
} else {
@@ -854,7 +846,6 @@ namespace Bloom
}
this->ramInspectionPane->activate();
this->bottomPanel->show();
this->ramInspectionButton->setChecked(true);
}
@@ -864,7 +855,6 @@ namespace Bloom
void InsightWindow::toggleEepromInspectionPane() {
if (this->eepromInspectionPane->activated) {
this->eepromInspectionPane->deactivate();
this->bottomPanel->hide();
this->eepromInspectionButton->setChecked(false);
} else {
@@ -873,7 +863,6 @@ namespace Bloom
}
this->eepromInspectionPane->activate();
this->bottomPanel->show();
this->eepromInspectionButton->setChecked(true);
}

View File

@@ -0,0 +1,55 @@
#include "PaneWidget.hpp"
namespace Bloom::Widgets
{
PaneWidget::PaneWidget(PanelWidget* parent)
: QWidget(parent)
, parentPanel(parent)
{
this->setMouseTracking(false);
this->setAttribute(Qt::WA_Hover, true);
QObject::connect(this, &PaneWidget::paneActivated, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneDeactivated, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneAttached, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility);
}
void PaneWidget::activate() {
if (this->activated) {
return;
}
this->show();
this->activated = true;
emit this->paneActivated();
}
void PaneWidget::deactivate() {
if (!this->activated) {
return;
}
this->hide();
this->activated = false;
emit this->paneDeactivated();
}
void PaneWidget::detach() {
this->setWindowFlag(Qt::Window);
this->show();
this->attached = false;
emit this->paneDetached();
}
void PaneWidget::attach() {
this->setWindowFlag(Qt::Window, false);
this->hide();
this->show();
this->attached = true;
emit this->paneAttached();
}
}

View File

@@ -12,15 +12,29 @@ namespace Bloom::Widgets
Q_OBJECT
public:
bool activated = false;
bool activated = true;
bool attached = true;
PanelWidget* parentPanel = nullptr;
explicit PaneWidget(PanelWidget* parent): QWidget(parent), parentPanel(parent) {};
explicit PaneWidget(PanelWidget* parent);
[[nodiscard]] PaneState getCurrentState() const {
return PaneState(
this->activated
);
}
void activate();
void deactivate();
signals:
void paneActivated();
void paneDeactivated();
void paneAttached();
void paneDetached();
protected:
void detach();
void attach();
};
}

View File

@@ -2,6 +2,8 @@
#include <QLayout>
#include "PaneWidget.hpp"
namespace Bloom::Widgets
{
PanelWidget::PanelWidget(QWidget* parent): QFrame(parent) {
@@ -57,6 +59,20 @@ namespace Bloom::Widgets
}
}
void PanelWidget::updateVisibility() {
const auto paneWidgets = this->findChildren<PaneWidget*>();
auto visible = false;
for (const auto& paneWidget : paneWidgets) {
if (paneWidget->activated && paneWidget->attached) {
visible = true;
break;
}
}
this->setVisible(visible);
}
bool PanelWidget::event(QEvent* event) {
if (event->type() == QEvent::Type::HoverMove) {
auto* hoverEvent = dynamic_cast<QHoverEvent*>(event);

View File

@@ -64,6 +64,15 @@ namespace Bloom::Widgets
);
}
/**
* Will evaluate whether the panel should still be visible or not (depending on whether there are any
* visible and attached child panes).
*
* This function is called whenever a child pane is activated/deactivate/attached/detached.
* See PaneWidget::PaneWidget() for more.
*/
void updateVisibility();
protected:
int handleSize = 10;
int minimumResize = 10;

View File

@@ -35,14 +35,12 @@ namespace Bloom::Widgets
);
void refreshMemoryValues(std::optional<std::function<void(void)>> callback = std::nullopt);
void activate();
void deactivate();
protected:
void resizeEvent(QResizeEvent* event) override;
virtual void postActivate();
virtual void postDeactivate();
void postActivate();
void postDeactivate();
private:
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor;

View File

@@ -114,6 +114,20 @@ namespace Bloom::Widgets
itemLayout->addStretch(1);
QObject::connect(
this,
&PaneWidget::paneActivated,
this,
&TargetRegistersPaneWidget::postActivate
);
QObject::connect(
this,
&PaneWidget::paneDeactivated,
this,
&TargetRegistersPaneWidget::postDeactivate
);
QObject::connect(
&insightWorker,
&InsightWorker::targetStateUpdated,
@@ -188,18 +202,6 @@ namespace Bloom::Widgets
this->insightWorker.queueTask(readRegisterTask);
}
void TargetRegistersPaneWidget::activate() {
this->show();
this->activated = true;
this->postActivate();
}
void TargetRegistersPaneWidget::deactivate() {
this->hide();
this->activated = false;
this->postDeactivate();
}
void TargetRegistersPaneWidget::onItemSelectionChange(ItemWidget* newlySelectedWidget) {
// Only one item in the target registers pane can be selected at any given time.
if (this->selectedItemWidget != newlySelectedWidget) {

View File

@@ -38,16 +38,13 @@ namespace Bloom::Widgets
void refreshRegisterValues(std::optional<std::function<void(void)>> callback = std::nullopt);
void activate();
void deactivate();
void onItemSelectionChange(Bloom::Widgets::ItemWidget* newlySelectedWidget);
protected:
void resizeEvent(QResizeEvent* event) override;
virtual void postActivate();
virtual void postDeactivate();
void postActivate();
void postDeactivate();
private:
const Targets::TargetDescriptor& targetDescriptor;