* @brief Constructs the painter widget bound to a dashboard slot. */
| 125 | * @brief Constructs the painter widget bound to a dashboard slot. |
| 126 | */ |
| 127 | Widgets::Painter::Painter(int index, QQuickItem* parent) |
| 128 | : QQuickPaintedItem(parent) |
| 129 | , m_index(index) |
| 130 | , m_compileDirty(true) |
| 131 | , m_runtimeOk(false) |
| 132 | , m_bootstrapOk(false) |
| 133 | , m_hasOnFrame(false) |
| 134 | , m_previewMode(false) |
| 135 | , m_slowPaintWarned(false) |
| 136 | , m_pointerDown(false) |
| 137 | , m_rendering(false) |
| 138 | , m_slowPaintStreak(0) |
| 139 | , m_lastPointerX(0.0) |
| 140 | , m_lastPointerY(0.0) |
| 141 | , m_frameSeq(0) |
| 142 | , m_watchdog(&m_engine, kPainterWatchdogMs, QStringLiteral("Painter")) |
| 143 | , m_ctx(new PainterContext(this)) |
| 144 | , m_bridge(new PainterDataBridge(this)) |
| 145 | { |
| 146 | setOpaquePainting(false); |
| 147 | setFlag(ItemHasContents, true); |
| 148 | setAcceptedMouseButtons(Qt::AllButtons); |
| 149 | setAcceptHoverEvents(true); |
| 150 | setAcceptTouchEvents(false); |
| 151 | |
| 152 | m_engine.installExtensions(QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); |
| 153 | DataModel::NotificationCenter::installScriptApi(&m_engine); |
| 154 | DataModel::FrameBuilder::instance().injectTableApiJS(&m_engine); |
| 155 | |
| 156 | DataModel::DeviceWriteApi::installJS(&m_engine, 0); |
| 157 | DataModel::ActionFireApi::installJS(&m_engine); |
| 158 | |
| 159 | DataModel::DashboardApi::installJS(&m_engine); |
| 160 | |
| 161 | DataModel::ScriptApiCall::installJS(&m_engine, 0); |
| 162 | |
| 163 | const auto projectPath = AppState::instance().projectFilePath(); |
| 164 | if (!projectPath.isEmpty()) |
| 165 | m_ctx->setProjectDirectory(QFileInfo(projectPath).absolutePath()); |
| 166 | |
| 167 | auto bridgeJsValue = m_engine.newQObject(m_bridge); |
| 168 | m_engine.globalObject().setProperty(QStringLiteral("__pp"), bridgeJsValue); |
| 169 | |
| 170 | auto ctxJsValue = m_engine.newQObject(m_ctx); |
| 171 | m_engine.globalObject().setProperty(QStringLiteral("__ctx"), ctxJsValue); |
| 172 | m_ctxValue = ctxJsValue; |
| 173 | |
| 174 | installBootstrap(); |
| 175 | installTheme(); |
| 176 | |
| 177 | connect(m_bridge, &PainterDataBridge::consoleLine, this, &Painter::consoleLine); |
| 178 | |
| 179 | connect(&Misc::ThemeManager::instance(), &Misc::ThemeManager::themeChanged, this, [this]() { |
| 180 | installTheme(); |
| 181 | m_compileDirty = true; |
| 182 | }); |
| 183 | |
| 184 | connect(&UI::Dashboard::instance(), &UI::Dashboard::updated, this, &Painter::updateData); |
nothing calls this directly
no test coverage detected