Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
guiintegration.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <sonde/expected.h>
7#include <sonde/global.h>
8#include <sonde/sonde_gui_export.h>
9
10#include <QtCore/QJsonObject>
11#include <QtCore/QList>
12#include <QtCore/QMargins>
13#include <QtCore/QModelIndex>
14#include <QtCore/QObject>
15#include <QtCore/QRectF>
16#include <QtCore/QStringList>
17#include <QtGui/QImage>
18
19#include <memory>
20#include <optional>
21
22QT_BEGIN_NAMESPACE
23class QAbstractItemModel;
24class QWindow;
25QT_END_NAMESPACE
26
27namespace Sonde {
28
31{
32 QWindow *window = nullptr;
33 QRectF rect;
34};
35
37enum class ScrollToCell {
40};
41
44{
45 bool clips = false;
46 QObject *scrolledContent = nullptr;
47 QMarginsF allowed;
48 QStringList causes;
49 bool decoration = false;
50};
51
54{
55 QObject *popup = nullptr;
56 QObject *opener = nullptr;
57 QRectF rect;
58 QRectF bounds;
59 QString boundsName;
62 QWindow *window = nullptr;
63};
64
74class SONDE_GUI_EXPORT GuiIntegration
75{
76public:
78 virtual ~GuiIntegration();
79
81 virtual QString name() const = 0;
82
86 virtual Expected<QImage> grabWindow(QWindow *window)
87 {
88 Q_UNUSED(window);
89 return notHandled();
90 }
91
95 virtual Expected<ScreenRect> objectGeometry(QObject *object)
96 {
97 Q_UNUSED(object);
98 return notHandled();
99 }
100
103 virtual Expected<QObject *> objectForWindow(QWindow *window)
104 {
105 Q_UNUSED(window);
106 return notHandled();
107 }
108
111 virtual Expected<QObjectList> children(QObject *object)
112 {
113 Q_UNUSED(object);
114 return notHandled();
115 }
116
118 virtual Expected<QObject *> objectAt(QWindow *window, const QPointF &pos)
119 {
120 Q_UNUSED(window);
121 Q_UNUSED(pos);
122 return notHandled();
123 }
124
126 virtual Expected<QAbstractItemModel *> model(QObject *object)
127 {
128 Q_UNUSED(object);
129 return notHandled();
130 }
131
138 virtual Expected<ScreenRect> cellGeometry(QObject *view, const QModelIndex &index,
139 ScrollToCell scroll)
140 {
141 Q_UNUSED(view);
142 Q_UNUSED(index);
143 Q_UNUSED(scroll);
144 return notHandled();
145 }
146
149 virtual Expected<QJsonObject> layoutInfo(QObject *object)
150 {
151 Q_UNUSED(object);
152 return notHandled();
153 }
154
156 virtual Expected<OverflowFacts> overflowFacts(QObject *object)
157 {
158 Q_UNUSED(object);
159 return notHandled();
160 }
161
164 virtual QList<OpenPopup> openPopups(QObject *root)
165 {
166 Q_UNUSED(root);
167 return { };
168 }
169
174 virtual QObjectList movingViews(QWindow *window)
175 {
176 Q_UNUSED(window);
177 return { };
178 }
179
181 virtual QJsonObject appInfo() { return { }; }
182};
183
186namespace Gui {
187
189SONDE_GUI_EXPORT void registerIntegration(std::unique_ptr<GuiIntegration> integration);
190
198SONDE_GUI_EXPORT Expected<QWindow *> findWindow(const QString &spec);
199
201SONDE_GUI_EXPORT QList<QWindow *> visibleWindows();
202
206SONDE_GUI_EXPORT Expected<ScreenRect> objectGeometry(QObject *object);
207
210SONDE_GUI_EXPORT QObject *objectForWindow(QWindow *window);
211
213SONDE_GUI_EXPORT QObject *objectAt(QWindow *window, const QPointF &pos);
214
217SONDE_GUI_EXPORT Expected<QImage> grabWindow(QWindow *window);
218
220SONDE_GUI_EXPORT QString describeWindow(QWindow *window);
221
226SONDE_GUI_EXPORT QAbstractItemModel *modelFor(QObject *object);
227
230SONDE_GUI_EXPORT Expected<ScreenRect> cellGeometry(QObject *view, const QModelIndex &index,
231 ScrollToCell scroll);
232
235SONDE_GUI_EXPORT Expected<QJsonObject> layoutInfo(QObject *object);
236
239SONDE_GUI_EXPORT Expected<OverflowFacts> overflowFacts(QObject *object);
240
242SONDE_GUI_EXPORT QList<OpenPopup> openPopups(QObject *root);
245SONDE_GUI_EXPORT QObjectList movingViews(QWindow *window);
247SONDE_GUI_EXPORT QJsonObject appInfo();
248
249} // namespace Gui
250} // namespace Sonde
A value of type T, or an error of type E, as std::expected.
Definition expected.h:106
Hooks that let a UI toolkit built on QtGui (Qt Widgets, Qt Quick or your own) tell the GUI tools how ...
Definition guiintegration.h:75
virtual Expected< QObject * > objectForWindow(QWindow *window)
The object that represents a top-level window in the object tree (e.g.
Definition guiintegration.h:103
virtual QString name() const =0
Unique name; registering another integration with the same name replaces this one.
virtual QJsonObject appInfo()
Fields this integration adds to app_info's answer, such as the state of a feature it provides.
Definition guiintegration.h:181
virtual Expected< QObjectList > children(QObject *object)
Visual children of object if they differ from QObject::children(), or notHandled().
Definition guiintegration.h:111
virtual QList< OpenPopup > openPopups(QObject *root)
The open popups that belong to root or an object below it.
Definition guiintegration.h:164
virtual Expected< QObject * > objectAt(QWindow *window, const QPointF &pos)
The deepest object at pos (window coordinates), or notHandled().
Definition guiintegration.h:118
virtual Expected< ScreenRect > objectGeometry(QObject *object)
Where object is on screen.
Definition guiintegration.h:95
virtual Expected< ScreenRect > cellGeometry(QObject *view, const QModelIndex &index, ScrollToCell scroll)
Where cell index of view view is on screen.
Definition guiintegration.h:138
virtual QObjectList movingViews(QWindow *window)
The views in window still scrolling on their own: a flick, kinetic scrolling, or an animated wheel sc...
Definition guiintegration.h:174
virtual Expected< QAbstractItemModel * > model(QObject *object)
The item model object shows (it is a view, combo box, ...), or notHandled().
Definition guiintegration.h:126
virtual Expected< OverflowFacts > overflowFacts(QObject *object)
What this integration knows about how object may overflow, or notHandled().
Definition guiintegration.h:156
virtual Expected< QImage > grabWindow(QWindow *window)
Renders the window's contents.
Definition guiintegration.h:86
virtual ~GuiIntegration()
Destroys the integration.
virtual Expected< QJsonObject > layoutInfo(QObject *object)
Layout facts about object for layout_explain (size hints, policies, margins, clipping,...
Definition guiintegration.h:149
Sonde::Expected, Sonde::Unexpected and Sonde::Error: results that are a value or an error (design 003...
What every Sonde header includes: the version, and the deprecation macros (design 0031).
QObject * objectAt(QWindow *window, const QPointF &pos)
The deepest object at pos in window, or nullptr if there is none.
Definition guiintegration.cpp:129
Expected< ScreenRect > objectGeometry(QObject *object)
Where object is on screen (see GuiIntegration::objectGeometry()).
Definition guiintegration.cpp:117
QList< QWindow * > visibleWindows()
All visible top-level windows.
Definition guiintegration.cpp:98
QList< OpenPopup > openPopups(QObject *root)
The open popups below root, from every integration (see GuiIntegration::openPopups()).
Definition guiintegration.cpp:307
void registerIntegration(std::unique_ptr< GuiIntegration > integration)
Registers integration, replacing one with the same name().
Definition guiintegration.cpp:84
QJsonObject appInfo()
The fields every integration adds to app_info (see GuiIntegration::appInfo()).
Definition guiintegration.cpp:325
QAbstractItemModel * modelFor(QObject *object)
The item model object is or shows, or nullptr if none.
Definition guiintegration.cpp:263
QString describeWindow(QWindow *w)
One-line summary: @id Class "Title".
Definition guiintegration.cpp:160
Expected< QWindow * > findWindow(const QString &spec)
Finds a window.
Definition guiintegration.cpp:237
Expected< OverflowFacts > overflowFacts(QObject *object)
Overflow facts about object (see GuiIntegration::overflowFacts()), or a failure if no integration kno...
Definition guiintegration.cpp:297
Expected< QJsonObject > layoutInfo(QObject *object)
Layout facts about object (see GuiIntegration::layoutInfo()), or a failure if no integration knows it...
Definition guiintegration.cpp:287
Expected< ScreenRect > cellGeometry(QObject *view, const QModelIndex &index, ScrollToCell scroll)
Where cell index of view is (see GuiIntegration::cellGeometry()).
Definition guiintegration.cpp:275
Expected< QImage > grabWindow(QWindow *window)
Renders window (device pixels).
Definition guiintegration.cpp:136
QObjectList movingViews(QWindow *window)
The views in window still scrolling, from every integration (see GuiIntegration::movingViews()).
Definition guiintegration.cpp:316
QObject * objectForWindow(QWindow *window)
The object representing window in the object tree: what an integration reports (its QWidget,...
Definition guiintegration.cpp:110
Embeddable Model Context Protocol server for Qt applications.
Definition dispatch.cpp:10
ScrollToCell
Whether cellGeometry() may scroll the view to show the cell.
Definition guiintegration.h:37
@ Yes
Scroll the view first, if the cell is out of sight.
Definition guiintegration.h:39
@ No
Leave the view as it is; a cell scrolled out of sight isn't shown.
Definition guiintegration.h:38
Unexpected< Error > notHandled()
"Not handled, ask the next integration", for GuiIntegration hooks to return.
Definition expected.h:88
An open popup (menu, drop-down, tooltip) that belongs to an object, for layout_overflow.
Definition guiintegration.h:54
QWindow * window
The popup's own window, if it has one; nullptr if it is drawn in its opener's window (so a screenshot...
Definition guiintegration.h:62
QString boundsName
What the bounds are, e.g.
Definition guiintegration.h:59
QObject * popup
The popup.
Definition guiintegration.h:55
QObject * opener
The object it belongs to.
Definition guiintegration.h:56
QRectF rect
Where it is, in global coordinates.
Definition guiintegration.h:57
QRectF bounds
What it must stay inside, in global coordinates.
Definition guiintegration.h:58
What an integration knows about how one object may overflow, for layout_overflow.
Definition guiintegration.h:44
bool clips
Its children are cut off at its bounds.
Definition guiintegration.h:45
QMarginsF allowed
How far it may extend past its parent by design, per side.
Definition guiintegration.h:47
bool decoration
Looks like a decoration: no children, text or input.
Definition guiintegration.h:49
QStringList causes
What placed it, e.g. "anchors.bottomMargin: -12".
Definition guiintegration.h:48
QObject * scrolledContent
The child it scrolls, if it is a scrolling view.
Definition guiintegration.h:46
Where something is on screen: the window that shows it, and its rectangle there.
Definition guiintegration.h:31
QWindow * window
The window that shows it.
Definition guiintegration.h:32
QRectF rect
Its rectangle, in the window's (logical) coordinates.
Definition guiintegration.h:33