11#include <QtCore/QCoreApplication>
12#include <QtCore/QEvent>
13#include <QtCore/QJsonObject>
14#include <QtCore/QList>
15#include <QtCore/QObject>
16#include <QtCore/QString>
24namespace Sonde::Input {
33bool isWithin(
const QObject *o,
const QObject *ancestor);
58 QCoreApplication::instance()->installEventFilter(
this);
64 if (QCoreApplication *app = QCoreApplication::instance())
65 app->removeEventFilter(
this);
70 static
void mark(QEvent::Type type)
80 if (!c.label.isEmpty()) {
81 return c.label == QLatin1StringView(
"wheel") ? QStringLiteral(
"wheel event")
85 return QStringLiteral(
"press");
92 if (!c.receivers.isEmpty() || c.label == QLatin1StringView(
"press"))
93 return c.reachedTarget;
104 const QStringList *previous =
nullptr;
105 const auto flush = [&] {
108 const QString who = previous->isEmpty() ? QStringLiteral(
"no object (only the window)")
109 : previous->join(QStringLiteral(
" -> "));
110 lines << QStringLiteral(
" %1: %2").arg(
compactLabels(labels), who);
114 if (c.label.isEmpty())
116 if (previous && *previous != c.receivers)
118 previous = &c.receivers;
126 "\nDelivered to (in order; each object before the last ignored the event "
127 "and Qt passed it on):\n")
128 + lines.join(QLatin1Char(
'\n'));
130 text += QStringLiteral(
"\n (later deliveries not recorded)");
137 const QString label =
labelFor(event->type());
139 || receiver->isWindowType())
142 if (chain.
label.isEmpty())
145 if (label != chain.
label) {
146 who = QStringLiteral(
"(%1) ").arg(label)
169 case QEvent::MouseButtonPress:
170 return QStringLiteral(
"press");
171 case QEvent::MouseButtonDblClick:
172 return QStringLiteral(
"double-click");
174 return QStringLiteral(
"wheel");
175 case QEvent::KeyPress:
176 return QStringLiteral(
"key");
177 case QEvent::Shortcut:
178 return QStringLiteral(
"shortcut");
189 while (i < labels.size()) {
191 while (i + n < labels.size() && labels.at(i + n) == labels.at(i))
193 out << (n > 1 ? QStringLiteral(
"%1 x%2").arg(labels.at(i)).arg(n) : labels.at(i));
196 return out.join(QStringLiteral(
", "));
208 const QJsonObject &extra = { });
225void addTool(
Server &server,
const char *name,
const char *title,
const QString &description,
An embeddable Model Context Protocol server.
Definition server.h:92
QString describeBrief(const QObject *o)
Short summary that doesn't change with the object's state: @id Class#name.
Definition objecttree.cpp:363
std::function< void(const ToolCall &call)> AsyncToolHandler
Handler of an asynchronous tool; answer via ToolCall::finish().
Definition types.h:192
Sonde::ObjectTree: the application's object tree, object specs and QVariant/JSON conversion.
Sonde::Server, the embeddable MCP server.
int main(int argc, char **argv)
Connects to the local server and copies lines between it and stdin/stdout.
Definition main.cpp:20
Value types shared by the Sonde API: tool definitions and results, asynchronous tool-call handles,...