Implemented event filter in PanelWidget to enforce the receiving of mouse events (for the panel resize handle)

This commit is contained in:
Nav
2023-03-23 19:23:39 +00:00
parent 400a735760
commit 5b90c6280e
4 changed files with 25 additions and 2 deletions

View File

@@ -82,10 +82,31 @@ namespace Bloom::Widgets
this->setVisible(visible); this->setVisible(visible);
} }
bool PanelWidget::eventFilter(QObject* object, QEvent* event) {
const auto eventType = event->type();
if (event->isSinglePointEvent()) {
auto* pointerEvent = dynamic_cast<QSinglePointEvent*>(event);
if (
this->initialResizePoint.has_value()
|| this->isPositionWithinHandleArea(pointerEvent->position().toPoint())
) {
this->event(event);
return true;
}
}
return false;
}
bool PanelWidget::event(QEvent* event) { bool PanelWidget::event(QEvent* event) {
if (event->type() == QEvent::Type::HoverMove) { if (event->type() == QEvent::Type::HoverMove) {
auto* hoverEvent = dynamic_cast<QHoverEvent*>(event); auto* hoverEvent = dynamic_cast<QHoverEvent*>(event);
if (this->initialResizePoint.has_value() || this->isPositionWithinHandleArea(hoverEvent->position().toPoint())) { if (
this->initialResizePoint.has_value()
|| this->isPositionWithinHandleArea(hoverEvent->position().toPoint())
) {
this->setCursor(this->resizeCursor); this->setCursor(this->resizeCursor);
} else { } else {

View File

@@ -78,6 +78,7 @@ namespace Bloom::Widgets
std::optional<QPoint> initialResizePoint = std::nullopt; std::optional<QPoint> initialResizePoint = std::nullopt;
int initialResizeSize = 0; int initialResizeSize = 0;
bool eventFilter(QObject *object, QEvent *event) override;
bool event(QEvent* event) override; bool event(QEvent* event) override;
void mousePressEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override;

View File

@@ -56,6 +56,7 @@ namespace Bloom::Widgets
auto* containerLayout = this->container->findChild<QVBoxLayout*>(); auto* containerLayout = this->container->findChild<QVBoxLayout*>();
this->snapshotListView = new ListView({}, this); this->snapshotListView = new ListView({}, this);
this->snapshotListView->viewport()->installEventFilter(parent);
this->snapshotListView->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); this->snapshotListView->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
this->snapshotListScene = this->snapshotListView->listScene(); this->snapshotListScene = this->snapshotListView->listScene();

View File

@@ -117,7 +117,7 @@ namespace Bloom::Widgets
this->rightPanel = new PanelWidget(PanelWidgetType::RIGHT, this->settings.rightPanelState, this); this->rightPanel = new PanelWidget(PanelWidgetType::RIGHT, this->settings.rightPanelState, this);
this->rightPanel->setObjectName("right-panel"); this->rightPanel->setObjectName("right-panel");
this->rightPanel->setMinimumResize(200); this->rightPanel->setMinimumResize(200);
this->rightPanel->setHandleSize(5); this->rightPanel->setHandleSize(6);
this->subContainerLayout->insertWidget(2, this->rightPanel); this->subContainerLayout->insertWidget(2, this->rightPanel);
this->snapshotManager = new SnapshotManager( this->snapshotManager = new SnapshotManager(