57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#ifndef UTILS_HPP
|
|
#define UTILS_HPP
|
|
|
|
#include "tierrow.hpp"
|
|
|
|
#include <QWidget>
|
|
#include <QString>
|
|
|
|
//change this stupid name
|
|
inline void callOnMeAndChildren(QObject* obj, void (*func)(QObject*))
|
|
{
|
|
func(obj);
|
|
for (auto w : obj->children())
|
|
{
|
|
callOnMeAndChildren(w, func);
|
|
}
|
|
}
|
|
template <typename T>
|
|
void callOnMeAndChildren(QObject* obj, void (*func)(T*))
|
|
{
|
|
if (auto casted = dynamic_cast<T*>(obj))
|
|
{
|
|
func(casted);
|
|
}
|
|
for (auto w : obj->children())
|
|
{
|
|
callOnMeAndChildren(w, func);
|
|
}
|
|
}
|
|
|
|
inline QString makeBgColorString(QColor color)
|
|
{
|
|
return QString("background-color: rgba(%1,%2,%3,%4)")
|
|
.arg(QString::number(color.red()),
|
|
QString::number(color.green()),
|
|
QString::number(color.blue()),
|
|
QString::number(color.alphaF()));
|
|
}
|
|
|
|
template <typename T>
|
|
T* findParentOfType(QObject* obj)
|
|
{
|
|
auto parent = obj->parent();
|
|
if (!parent)
|
|
return nullptr;
|
|
else if (auto asT = dynamic_cast<T*>(parent))
|
|
{
|
|
return asT;
|
|
}
|
|
else
|
|
{
|
|
return findParentOfType<T>(parent);
|
|
}
|
|
}
|
|
|
|
#endif // UTILS_HPP
|