From 2ceae8ec9d855d998f84d35ca28fbaca3bce9bb9 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Thu, 13 Feb 2025 22:34:03 +0100 Subject: [PATCH] MethodIcon: added support for custom trigger function --- client/src/widget/methodicon.cpp | 17 +++++++++++++++-- client/src/widget/methodicon.hpp | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/widget/methodicon.cpp b/client/src/widget/methodicon.cpp index 8401028b..21b05f6f 100644 --- a/client/src/widget/methodicon.cpp +++ b/client/src/widget/methodicon.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2024 Reinder Feenstra + * Copyright (C) 2024-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -57,6 +57,12 @@ MethodIcon::MethodIcon(Method& method, QIcon icon, QWidget* parent) : }); } +MethodIcon::MethodIcon(Method& item, QIcon icon, std::function triggered, QWidget* parent) + : MethodIcon(item, icon, parent) +{ + m_triggered = std::move(triggered); +} + void MethodIcon::mousePressEvent(QMouseEvent* event) { if(event->button() == Qt::LeftButton) @@ -76,7 +82,14 @@ void MethodIcon::mouseReleaseEvent(QMouseEvent* event) if(rect().contains(event->position().toPoint())) // test if mouse release in widget #endif { - m_method.call(); + if(m_triggered) + { + m_triggered(); + } + else + { + m_method.call(); + } } } } diff --git a/client/src/widget/methodicon.hpp b/client/src/widget/methodicon.hpp index 92a9a742..d44344ca 100644 --- a/client/src/widget/methodicon.hpp +++ b/client/src/widget/methodicon.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2024 Reinder Feenstra + * Copyright (C) 2024-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,6 +31,7 @@ class MethodIcon : public QLabel { protected: Method& m_method; + std::function m_triggered; bool m_mouseLeftButtonPressed; void mousePressEvent(QMouseEvent* event) final; @@ -38,6 +39,7 @@ class MethodIcon : public QLabel public: MethodIcon(Method& item, QIcon icon, QWidget* parent = nullptr); + MethodIcon(Method& item, QIcon icon, std::function triggered, QWidget* parent = nullptr); }; #endif