1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#include "UIHelper.h"
#include <qcoreevent.h>
#include <QDir>
#include <QMouseEvent>
HoverEventFilter::HoverEventFilter(const std::shared_ptr<PluginViewModel>& plugin, QObject* parent)
: QObject(parent), mPlugin(plugin) {}
bool HoverEventFilter::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::HoverEnter) {
emit hovered(mPlugin);
return true;
}
return QObject::eventFilter(obj, event);
}
CtrlClickEventFilter::CtrlClickEventFilter(const std::shared_ptr<PluginViewModel>& plugin,
const std::shared_ptr<GroupViewModel>& group, QObject* parent)
: QObject(parent), mPlugin(plugin), mGroup(group) {}
bool CtrlClickEventFilter::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress) {
const QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton &&
mouseEvent->modifiers() & Qt::ControlModifier) {
// TODO: Add Ctrl+click handler logic here
// For now, just fall through to default behavior
}
}
return QObject::eventFilter(obj, event);
}
QPushButton* UIHelper::createButton(const QString& text, QWidget* parent = nullptr)
{
const auto button = new QPushButton(text, parent);
return button;
}
QLabel* UIHelper::createLabel(const QString& text, QWidget* parent = nullptr)
{
const auto label = new QLabel(text, parent);
return label;
}
QLabel* UIHelper::createHyperlink(const QString& url, QWidget* parent = nullptr)
{
if (url.isEmpty() || !QUrl(url).isValid()) {
return createLabel(url, parent);
}
const auto label = new QLabel(url, parent);
const QString hyperlink = QString("<a href=\"%1\">%2</a>").arg(url, "Link");
label->setText(hyperlink);
label->setOpenExternalLinks(true);
label->setTextFormat(Qt::RichText);
return label;
}
QString UIHelper::getFullImagePath(const QString& fomodPath, const QString& imagePath)
{
// Fomod XMLs may use Windows backslashes in image paths (e.g. "fomod\MCM.png")
QString normalized = imagePath;
normalized.replace('\\', '/');
return QDir::tempPath() + "/" + fomodPath + "/" + normalized;
}
void UIHelper::setGlobalAlignment(QBoxLayout* layout, const Qt::Alignment alignment)
{
for (int i = 0; i < layout->count(); ++i) {
if (const QLayoutItem* item = layout->itemAt(i); item->widget()) {
layout->setAlignment(item->widget(), alignment);
}
}
}
void UIHelper::setDebugBorders(QWidget* widget)
{
widget->setStyleSheet("border: 1px solid red;");
for (auto* child : widget->findChildren<QWidget*>()) {
child->setStyleSheet("border: 1px solid red;");
}
}
void UIHelper::reduceLabelPadding(const QLayout* layout)
{
for (int i = 0; i < layout->count(); ++i) {
const QLayoutItem* item = layout->itemAt(i);
if (QWidget* widget = item->widget()) {
if (const auto label = qobject_cast<QLabel*>(widget)) {
label->setContentsMargins(0, 0, 0, 0);
label->setStyleSheet("padding: 0px; margin: 0px;");
}
}
}
}
|