From b3694823cacddef22f514f70194572f49334559b Mon Sep 17 00:00:00 2001
From: Peter Albrecht <albrecpe@gmail.com>
Date: Mon, 22 Jan 2024 11:25:38 +0100
Subject: [PATCH] Added icon finder utility

---
 .../libraries/skills_gui/gui_utils.cpp        | 26 +++++++++++++++++++
 .../RobotAPI/libraries/skills_gui/gui_utils.h | 11 ++++++++
 2 files changed, 37 insertions(+)

diff --git a/source/RobotAPI/libraries/skills_gui/gui_utils.cpp b/source/RobotAPI/libraries/skills_gui/gui_utils.cpp
index 666228c76..4c6a1590e 100644
--- a/source/RobotAPI/libraries/skills_gui/gui_utils.cpp
+++ b/source/RobotAPI/libraries/skills_gui/gui_utils.cpp
@@ -1,5 +1,7 @@
 #include "gui_utils.h"
 
+#include <mutex>
+
 #include <QLayout>
 #include <QLayoutItem>
 #include <QSplitter>
@@ -7,6 +9,7 @@
 #include <QWidget>
 
 #include <ArmarXCore/core/exceptions/local/ExpressionException.h>
+#include <ArmarXCore/core/system/ArmarXDataPath.h>
 
 void
 armarx::gui::clearLayout(QLayout* layout)
@@ -107,3 +110,26 @@ armarx::gui::clearSplitter(QSplitter* splitter)
         splitter->widget(i)->deleteLater();
     }
 }
+
+QIcon
+armarx::gui::getIcon(std::string name)
+{
+    // is the path already found?
+    if (armarXGuiPath.empty())
+    {
+        std::scoped_lock l(m_armarXGuiPath);
+        armarXGuiPath = "ArmarXGui";
+        ArmarXDataPath::getAbsolutePath(armarXGuiPath, armarXGuiPath);
+    }
+
+    std::cout << armarXGuiPath;
+
+    // now we can use the path!
+
+    // what in god's good name is "armarx/ArmarXGui/data/ArmarXGui"? And why does the util
+    // say ArmarXGui is in there???????
+    // anyways. workaround until I figure out what the hell happens here.
+    QPixmap pix(QString::fromStdString(
+        armarXGuiPath + "/../../source/ArmarXGui/libraries/ArmarXGuiBase/icons/" + name));
+    return QIcon(pix);
+}
diff --git a/source/RobotAPI/libraries/skills_gui/gui_utils.h b/source/RobotAPI/libraries/skills_gui/gui_utils.h
index 80855718d..c958cbe20 100644
--- a/source/RobotAPI/libraries/skills_gui/gui_utils.h
+++ b/source/RobotAPI/libraries/skills_gui/gui_utils.h
@@ -13,6 +13,17 @@
 
 namespace armarx::gui
 {
+    // we only need to fetch the path once => fetch once, use many times
+    static std::string armarXGuiPath = "";
+    static std::mutex m_armarXGuiPath;
+
+    /**
+     * @brief Get an icon in ArmarXGuiBase.
+     * @param name The name of the icon.
+     * @return The icon.
+     */
+    QIcon getIcon(std::string name);
+
     /**
      * @brief Clear a layout.
      *
-- 
GitLab