From 342384a91cea8c80c7e805d45e3877079e630f5b Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 22 Aug 2021 20:43:43 +0100 Subject: [PATCH] New clickable widget --- CMakeLists.txt | 1 + .../InsightWindow/Widgets/ClickableWidget.cpp | 19 ++++++++++++++ .../InsightWindow/Widgets/ClickableWidget.hpp | 26 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ca68a8e8..7b09a92b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ add_executable(Bloom src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp + src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingWidget.hpp src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp new file mode 100644 index 00000000..b1afec9e --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp @@ -0,0 +1,19 @@ +#include "ClickableWidget.hpp" + +using namespace Bloom::Widgets; + +void ClickableWidget::mouseReleaseEvent(QMouseEvent* event) { + if (event->button() == Qt::MouseButton::LeftButton) { + emit this->clicked(); + } + + QWidget::mouseReleaseEvent(event); +} + +void ClickableWidget::mouseDoubleClickEvent(QMouseEvent* event) { + if (event->button() == Qt::MouseButton::LeftButton) { + emit this->doubleClicked(); + } + + QWidget::mouseDoubleClickEvent(event); +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp new file mode 100644 index 00000000..3c94eb4b --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +#include "src/Logger/Logger.hpp" + +namespace Bloom::Widgets +{ + class Q_WIDGETS_EXPORT ClickableWidget: public QFrame + { + Q_OBJECT + protected: + void mouseReleaseEvent(QMouseEvent* event) override; + void mouseDoubleClickEvent(QMouseEvent* event) override; + + public: + explicit ClickableWidget(QWidget* parent): QFrame(parent) {}; + + signals: + void clicked(); + void doubleClicked(); + + }; +}