Download tasks/t24-friction-pong/environment/friction-gui-only.cpp from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.44 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t24-friction-pong/environment/friction-gui-only.cpp
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t24-friction-pong/environment/friction-gui-only.cpp
-
curl -L -o friction-gui-only.cpp https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t24-friction-pong/environment/friction-gui-only.cpp
4.44 kB
| // Task image policy: Friction animation tools remain available; its expression | |
| // code editor and ECMAScript execution are disabled. No agent text is logged. | |
| static bool codeWindow(const QWidget *widget) { | |
| for (auto current = widget; current; current = current->parentWidget()) { | |
| const QString title = current->windowTitle(); | |
| const QString type = current->metaObject()->className(); | |
| if (title.startsWith("Expression", Qt::CaseInsensitive) | |
| || type.contains("ExpressionEditor") || type.contains("JSEditor")) | |
| return true; | |
| } | |
| return false; | |
| } | |
| static void blocked() { | |
| std::fputs("GUI-only task: expression scripting is disabled.\n", stderr); | |
| } | |
| class CodeEditorFilter : public QObject { | |
| public: | |
| using QObject::QObject; | |
| bool eventFilter(QObject *object, QEvent *event) override { | |
| if (event->type() == QEvent::Show) { | |
| if (auto menu = qobject_cast<QMenu *>(object)) { | |
| for (auto action : menu->actions()) { | |
| if (action->text().contains("Expression", Qt::CaseInsensitive)) { | |
| action->setEnabled(false); | |
| action->setToolTip("Expression scripting is disabled; use keyframes."); | |
| } | |
| } | |
| } | |
| } | |
| auto widget = qobject_cast<QWidget *>(object); | |
| if (!widget || !codeWindow(widget)) return false; | |
| switch (event->type()) { | |
| case QEvent::Show: { | |
| widget->setEnabled(false); | |
| auto window = widget->window(); | |
| window->setAttribute(Qt::WA_DontShowOnScreen, true); | |
| QPointer<QWidget> safeWindow(window); | |
| QTimer::singleShot(0, this, [safeWindow] { | |
| if (safeWindow) safeWindow->close(); | |
| }); | |
| blocked(); | |
| return true; | |
| } | |
| case QEvent::KeyPress: | |
| case QEvent::KeyRelease: | |
| case QEvent::InputMethod: | |
| case QEvent::MouseButtonPress: | |
| case QEvent::MouseButtonRelease: | |
| case QEvent::Shortcut: | |
| case QEvent::ShortcutOverride: | |
| return true; | |
| default: | |
| return false; | |
| } | |
| } | |
| }; | |
| static void installFilter() { | |
| static QPointer<CodeEditorFilter> filter; | |
| auto app = QCoreApplication::instance(); | |
| if (app && !filter) { | |
| filter = new CodeEditorFilter(app); | |
| app->installEventFilter(filter); | |
| } | |
| } | |
| int QCoreApplication::exec() { | |
| installFilter(); | |
| using Function = int (*)(); | |
| static auto original = reinterpret_cast<Function>(dlsym(RTLD_NEXT, "_ZN16QCoreApplication4execEv")); | |
| if (!original) std::abort(); | |
| return original(); | |
| } | |
| int QDialog::exec() { | |
| if (codeWindow(this)) { | |
| setEnabled(false); | |
| blocked(); | |
| return QDialog::Rejected; | |
| } | |
| using Function = int (*)(QDialog *); | |
| static auto original = reinterpret_cast<Function>(dlsym(RTLD_NEXT, "_ZN7QDialog4execEv")); | |
| if (!original) std::abort(); | |
| return original(this); | |
| } | |
| QJSValue QJSEngine::evaluate(const QString &program, const QString &, int) { | |
| installFilter(); | |
| // Friction's ordinary numeric sliders also call evaluate(text()). Parse | |
| // literal numbers directly, without executing ECMAScript, so normal GUI | |
| // coordinate/keyframe entry remains available. | |
| static const QRegularExpression number( | |
| QStringLiteral(R"(^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$)")); | |
| const QString text = program.trimmed(); | |
| if (number.match(text).hasMatch()) { | |
| bool ok = false; | |
| const double value = text.toDouble(&ok); | |
| if (ok && std::isfinite(value)) return QJSValue(value); | |
| } | |
| blocked(); | |
| return QJSValue(QJSValue::UndefinedValue); | |
| } | |
| QJSValue QJSValue::call(const QJSValueList &) { | |
| blocked(); | |
| return QJSValue(QJSValue::UndefinedValue); | |
| } | |
| QJSValue QJSValue::callWithInstance(const QJSValue &, const QJSValueList &) { | |
| blocked(); | |
| return QJSValue(QJSValue::UndefinedValue); | |
| } | |
| QJSValue QJSValue::callAsConstructor(const QJSValueList &) { | |
| blocked(); | |
| return QJSValue(QJSValue::UndefinedValue); | |
| } | |