Persisted panel and pane states

This commit is contained in:
Nav
2022-02-06 20:28:46 +00:00
parent 7e992f781e
commit 3dcdc4b90b
14 changed files with 434 additions and 253 deletions

View File

@@ -0,0 +1,11 @@
#pragma once
namespace Bloom::Widgets
{
struct PaneState
{
bool activated = false;
explicit PaneState(bool activated): activated(activated) {};
};
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <QWidget>
#include "PanelWidget.hpp"
#include "PaneState.hpp"
namespace Bloom::Widgets
{
class PaneWidget: public QWidget
{
Q_OBJECT
public:
bool activated = false;
PanelWidget* parentPanel = nullptr;
explicit PaneWidget(PanelWidget* parent): QWidget(parent), parentPanel(parent) {};
[[nodiscard]] PaneState getCurrentState() const {
return PaneState(
this->activated
);
}
};
}

View File

@@ -0,0 +1,12 @@
#pragma once
namespace Bloom::Widgets
{
struct PanelState
{
int size = 0;
bool open = false;
PanelState(int size, bool open): size(size), open(open) {};
};
}

View File

@@ -48,9 +48,18 @@ namespace Bloom::Widgets
}
}
void PanelWidget::setSize(int size) {
if (this->panelType == PanelWidgetType::LEFT) {
this->setFixedWidth(std::min(std::max(size, this->minimumResize), this->maximumResize));
} else if (this->panelType == PanelWidgetType::BOTTOM) {
this->setFixedHeight(std::min(std::max(size, this->minimumResize), this->maximumResize));
}
}
bool PanelWidget::event(QEvent* event) {
if (event->type() == QEvent::Type::HoverMove) {
auto hoverEvent = static_cast<QHoverEvent*>(event);
auto* hoverEvent = dynamic_cast<QHoverEvent*>(event);
if (this->resizingActive || this->isPositionWithinHandleArea(hoverEvent->position().toPoint())) {
this->setCursor(this->resizeCursor);
@@ -91,24 +100,10 @@ namespace Bloom::Widgets
void PanelWidget::mouseMoveEvent(QMouseEvent* event) {
if (this->resizingActive) {
const auto position = event->pos();
if (this->panelType == PanelWidgetType::LEFT) {
this->setFixedWidth(
std::max(
this->minimumResize,
std::min(this->maximumResize, position.x() + this->resizingOffset)
)
);
} else if (this->panelType == PanelWidgetType::BOTTOM) {
this->setFixedHeight(
std::max(
this->minimumResize,
std::min(this->maximumResize, this->height() + (-position.y()) + this->resizingOffset)
)
);
}
this->setSize(this->panelType == PanelWidgetType::LEFT
? event->pos().x() + this->resizingOffset
: this->height() + (-event->pos().y()) + this->resizingOffset
);
}
}
@@ -120,13 +115,12 @@ namespace Bloom::Widgets
QPoint(currentSize.width() - this->handleSize, 0),
QPoint(currentSize.width(), currentSize.height())
);
} else {
return std::pair(
QPoint(0, 0),
QPoint(currentSize.width(), this->handleSize)
);
}
return std::pair(
QPoint(0, 0),
QPoint(currentSize.width(), this->handleSize)
);
}
bool PanelWidget::isPositionWithinHandleArea(const QPoint& position) const {

View File

@@ -6,6 +6,8 @@
#include <QMouseEvent>
#include <QEnterEvent>
#include "PanelState.hpp"
namespace Bloom::Widgets
{
Q_NAMESPACE
@@ -37,6 +39,8 @@ namespace Bloom::Widgets
void setPanelType(PanelWidgetType panelType);
void setSize(int size);
[[nodiscard]] int getHandleSize() const {
return this->handleSize;
}
@@ -53,6 +57,13 @@ namespace Bloom::Widgets
return this->panelType;
}
PanelState getCurrentState() {
return PanelState(
this->panelType == PanelWidgetType::LEFT ? this->width() : this->height(),
this->isVisible()
);
}
protected:
int handleSize = 10;
int minimumResize = 10;

View File

@@ -23,12 +23,11 @@ TargetMemoryInspectionPane::TargetMemoryInspectionPane(
TargetMemoryInspectionPaneSettings& settings,
InsightWorker& insightWorker,
PanelWidget* parent
):
QWidget(parent),
targetMemoryDescriptor(targetMemoryDescriptor),
settings(settings),
insightWorker(insightWorker),
parent(parent)
)
: PaneWidget(parent)
, targetMemoryDescriptor(targetMemoryDescriptor)
, settings(settings)
, insightWorker(insightWorker)
{
this->setObjectName("target-memory-inspection-pane");
@@ -175,7 +174,7 @@ void TargetMemoryInspectionPane::deactivate() {
}
void TargetMemoryInspectionPane::resizeEvent(QResizeEvent* event) {
const auto parentSize = this->parent->size();
const auto parentSize = this->parentPanel->size();
const auto width = parentSize.width() - 1;
this->container->setFixedSize(width, parentSize.height());
}

View File

@@ -4,11 +4,12 @@
#include <QResizeEvent>
#include <vector>
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp"
#include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp"
@@ -19,13 +20,12 @@
namespace Bloom::Widgets
{
class TargetMemoryInspectionPane: public QWidget
class TargetMemoryInspectionPane: public PaneWidget
{
Q_OBJECT
public:
TargetMemoryInspectionPaneSettings& settings;
bool activated = false;
TargetMemoryInspectionPane(
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor,
@@ -48,7 +48,6 @@ namespace Bloom::Widgets
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor;
InsightWorker& insightWorker;
PanelWidget* parent = nullptr;
QWidget* container = nullptr;
QWidget* titleBar = nullptr;

View File

@@ -11,9 +11,10 @@ namespace Bloom::Widgets
{
struct TargetMemoryInspectionPaneSettings
{
bool activated = false;
HexViewerWidgetSettings hexViewerWidgetSettings;
std::vector<FocusedMemoryRegion> focusedMemoryRegions;
std::vector<ExcludedMemoryRegion> excludedMemoryRegions;
HexViewerWidgetSettings hexViewerWidgetSettings;
};
}

View File

@@ -25,7 +25,7 @@ namespace Bloom::Widgets
const TargetDescriptor& targetDescriptor,
InsightWorker& insightWorker,
PanelWidget* parent
): QWidget(parent), parent(parent), targetDescriptor(targetDescriptor), insightWorker(insightWorker) {
): PaneWidget(parent), targetDescriptor(targetDescriptor), insightWorker(insightWorker) {
this->setObjectName("target-registers-side-pane");
auto targetRegistersPaneUiFile = QFile(
@@ -208,7 +208,7 @@ namespace Bloom::Widgets
}
void TargetRegistersPaneWidget::resizeEvent(QResizeEvent* event) {
const auto parentSize = this->parent->size();
const auto parentSize = this->parentPanel->size();
const auto width = parentSize.width() - 1;
this->container->setFixedWidth(width);
this->searchInput->setFixedWidth(width - 20);
@@ -217,7 +217,7 @@ namespace Bloom::Widgets
* In order to avoid the panel resize handle overlapping the scroll bar handle, we reduce the size of
* the scroll area.
*/
this->itemScrollArea->setFixedWidth(width - this->parent->getHandleSize());
this->itemScrollArea->setFixedWidth(width - this->parentPanel->getHandleSize());
}
void TargetRegistersPaneWidget::postActivate() {

View File

@@ -9,8 +9,10 @@
#include <QEvent>
#include <optional>
#include "ItemWidget.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp"
#include "ItemWidget.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp"
#include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Targets/TargetState.hpp"
@@ -19,13 +21,11 @@
namespace Bloom::Widgets
{
class RegisterGroupWidget;
class TargetRegistersPaneWidget: public QWidget
class TargetRegistersPaneWidget: public PaneWidget
{
Q_OBJECT
public:
bool activated = false;
TargetRegistersPaneWidget(
const Targets::TargetDescriptor& targetDescriptor,
InsightWorker& insightWorker,
@@ -54,7 +54,6 @@ namespace Bloom::Widgets
const Targets::TargetDescriptor& targetDescriptor;
InsightWorker& insightWorker;
PanelWidget* parent = nullptr;
QWidget* container = nullptr;
QWidget* toolBar = nullptr;