39 #ifndef __OPENFLUID_UICOMMON_UIHELPERS_HPP__ 40 #define __OPENFLUID_UICOMMON_UIHELPERS_HPP__ 47 #include <QApplication> 51 namespace openfluid {
namespace ui {
namespace common {
56 return QColor(qrand() % 256,qrand() % 256,qrand() % 256);
64 inline void fixLineEdit(QLineEdit* LineEdit,QRegExp SearchRegExp = QRegExp(
"[^\\w]"),QString NewStr =
"_")
66 int CPos = LineEdit->cursorPosition();
67 LineEdit->setText(LineEdit->text().replace(SearchRegExp,NewStr));
68 LineEdit->setCursorPosition(CPos);
78 return (qApp->devicePixelRatio() >= 2.0);
86 inline QIcon
getIcon(
const QString& IconName,
const QString& ResourcePath,
87 bool IsLight =
false,
bool AutoHiDPI =
true)
89 QString IconSuffix =
"dark";
96 QString TmpPath = QString(
":%1/icons/%2_%3.png").arg(ResourcePath).arg(IconName).arg(IconSuffix);
100 QString TmpHiDPIPath = QString(
":%1/icons/%2_%3@2x.png").arg(ResourcePath).arg(IconName).arg(IconSuffix);
102 if (QFile::exists(TmpHiDPIPath))
104 TmpPath = TmpHiDPIPath;
108 QIcon TmpIcon(TmpPath);
112 QString TmpLightPath = QString(
":%1/icons/%2_grayed.png").arg(ResourcePath).arg(IconName);
116 QString TmpLightHiDPIPath = QString(
":%1/icons/%2_grayed@2x.png").arg(ResourcePath).arg(IconName);
118 if (QFile::exists(TmpLightHiDPIPath))
120 TmpLightPath = TmpLightHiDPIPath;
123 TmpIcon.addPixmap(QPixmap(TmpLightPath),QIcon::Disabled);
134 inline QPixmap
getImage(
const QString& ImageName,
const QString& ResourcePath,
bool AutoHiDPI =
true)
136 QString TmpPath = QString(
":%1/images/%2.png").arg(ResourcePath).arg(ImageName);
140 QString TmpHiDPIPath = QString(
":%1/images/%2@2x.png").arg(ResourcePath).arg(ImageName);
142 if (QFile::exists(TmpHiDPIPath))
144 TmpPath = TmpHiDPIPath;
148 return QPixmap(TmpPath);
QColor getRandomColor()
Definition: UIHelpers.hpp:54
void fixLineEdit(QLineEdit *LineEdit, QRegExp SearchRegExp=QRegExp("[^\]"), QString NewStr="_")
Definition: UIHelpers.hpp:64
QIcon getIcon(const QString &IconName, const QString &ResourcePath, bool IsLight=false, bool AutoHiDPI=true)
Definition: UIHelpers.hpp:86
bool isHiDPIDevice()
Definition: UIHelpers.hpp:76
QPixmap getImage(const QString &ImageName, const QString &ResourcePath, bool AutoHiDPI=true)
Definition: UIHelpers.hpp:134
Definition: ApplicationException.hpp:47