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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
|
.. _events:
Events
======
Tui Widgets is an event driven framework. Events are deliviered primarily to instances of :cpp:class:`Tui::ZWidget` but
are also delivered to other classes derived from :cpp:class:`QObject`.
Classes either override virtual functions for specific events (like :cpp:func:`Tui::ZWidget::paintEvent()`) or
override :cpp:func:`QObject::event` and manually dispatching on the event type.
Tui Widgets defines its own event types and also reuses some event types from Qt.
.. rst-class:: tw-invisible
.. cpp:class:: Tui::ZEventType
Events are identified by :cpp:enum:`QEvent::Type` values.
Tui Widgets defines getter for the type values for its events. The Tui Widgets event types are:
.. cpp:function:: Tui::ZEventType::paint()
Requests a widget to paint itself (:cpp:class:`Tui::ZPaintEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::paintEvent(Tui::ZPaintEvent *event)` to handle this event.
The widgets can get the :cpp:class:`Tui::ZPainter` instance for painting by calling the
:cpp:func:`Tui::ZPainter *Tui::ZPaintEvent::painter() const` function.
.. cpp:function:: Tui::ZEventType::key()
Signals a key press that the widget may handle (:cpp:class:`Tui::ZKeyEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::keyEvent(Tui::ZKeyEvent *event)` to handle this event.
A key event is either a character or a non character key.
In case of a character the application can get the pressed character by reading
:cpp:func:`QString Tui::ZKeyEvent::text() const`.
The function might return multiple unicode code points in the future for languages with clusters of multiple
codepoints.
In case of a non character key the application can get the key by reading
:cpp:func:`int Tui::ZKeyEvent::key() const`.
Only on of these are meaningful at a given time. The other will be :cpp:enumerator:`Tui::Key_unknown` or
the empty string.
In both cases the application can get the modifier keys pressed when the key input happend by reading
:cpp:func:`Tui::KeyboardModifiers Tui::ZKeyEvent::modifiers() const`.
Tui Widgets sends the key events in the accepted state (see :cpp:func:`QEvent::isAccepted()`).
If the application passes the handling of the key event to the
default implementations of :cpp:func:`void Tui::ZWidget::keyEvent(Tui::ZKeyEvent *event)` and
``void Tui::ZWidget::event(QEvent *event)`` the accepted flag will be cleared.
If a key event, that is dispatched to the focused widget, is not in the accepted state after dispatching to a ZWidget,
it will bubble through all parents of the widget until reaching the root. It will be dispatched to each widget on
the way until a widget accepts it.
Widgets can also receive key events if they currently have the keyboard grab (see
:cpp:func:`void Tui::ZWidget::grabKeyboard()`), in this case the event will not bubble toward the root.
.. cpp:function:: Tui::ZEventType::paste()
Signals a clipboard paste that the widget may handle (:cpp:class:`Tui::ZPasteEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::pasteEvent(Tui::ZPasteEvent *event)` to handle this event.
The widget can get the pasted text by calling :cpp:func:`QString Tui::ZPasteEvent::text() const`.
Tui Widgets sends the paste events in the accepted state (see :cpp:func:`QEvent::isAccepted()`).
If the application passes the handling of the paste event to the
default implementations of :cpp:func:`void Tui::ZWidget::pasteEvent(Tui::ZPasteEvent *event)` and
``void Tui::ZWidget::event(QEvent *event)`` the accepted flag will be cleared.
If a paste event, that is dispatched to the focused widget, is not in the accepted state after dispatching to a ZWidget,
it will bubble through all parents of the widget until reaching the root. It will be dispatched to each widget on
the way until a widget accepts it.
Widgets can also receive paste events if they currently have the keyboard grab (see
:cpp:func:`void Tui::ZWidget::grabKeyboard()`), in this case the event will not bubble toward the root.
.. cpp:function:: Tui::ZEventType::queryAcceptsEnter()
Queries if a widget will handle the :kbd:`Enter` key (:cpp:class:`QEvent`).
If it will handle the key it should accept the event.
This is used to determine the visual state of default widgets (i.e. default buttons) that react to :kbd:`Enter`.
.. cpp:function:: Tui::ZEventType::focusIn()
Informs a widget that it gained keyboard focus (:cpp:class:`Tui::ZFocusEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::focusInEvent(Tui::ZFocusEvent *event)` to handle this event.
The widget can query the focus reason using :cpp:func:`Tui::FocusReason Tui::ZFocusEvent::reason() const`
.. cpp:function:: Tui::ZEventType::focusOut()
Informs a widget that it lost keyboard focus (:cpp:class:`Tui::ZFocusEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::focusOutEvent(Tui::ZFocusEvent *event)` to handle this event.
The widget can query the focus reason using :cpp:func:`Tui::FocusReason Tui::ZFocusEvent::reason() const`
.. cpp:function:: Tui::ZEventType::move()
Informs a widget that its position relative to its parents has changed (:cpp:class:`Tui::ZMoveEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::moveEvent(Tui::ZMoveEvent *event)` to handle this event.
The widget can query the previous position using :cpp:func:`QPoint Tui::ZMoveEvent::oldPos() const` and the
new position using :cpp:func:`QPoint Tui::ZMoveEvent::pos() const`.
.. cpp:function:: Tui::ZEventType::resize()
Informs a widget that its size has changed (:cpp:class:`Tui::ZResizeEvent`).
Widgets can override :cpp:func:`void Tui::ZWidget::resizeEvent(Tui::ZResizeEvent *event)` to handle this event.
The widget can query the previous size using :cpp:func:`QSize Tui::ZResizeEvent::oldSize() const` and the
new size using :cpp:func:`QSize Tui::ZResizeEvent::size() const`.
.. cpp:function:: Tui::ZEventType::otherChange()
This event is sent to every QObject in widget tree on some changes (:cpp:class:`Tui::ZOtherChangeEvent`).
The application can use :cpp:func:`bool Tui::ZOtherChangeEvent::match(const QEvent *event, Tui::ZSymbol changed)` to
match the event against a type of change.
.. cpp:function:: Tui::ZEventType::show()
Informs the widget that it has become visible (:cpp:class:`QEvent`).
See also :ref:`QEvent::ShowToParent <qevent_showtoparent>`.
.. cpp:function:: Tui::ZEventType::hide()
Informs the widget that it is no longer visible (:cpp:class:`QEvent`).
See also :ref:`QEvent::HideToParent <qevent_hidetoparent>`.
.. cpp:function:: Tui::ZEventType::terminalChange()
Informs the widget that its terminal attachment has changed (:cpp:class:`QEvent`).
The new terminal can be queried using :cpp:func:`Tui::ZWidget::terminal()`, which on terminal detach will return
:cpp:expr:`nullptr` and otherwise the newly attached terminal.
.. cpp:function:: Tui::ZEventType::close()
Used as query to decide if a window should be closed (:cpp:class:`Tui::ZCloseEvent`).
Classes derived from :cpp:class:`Tui::ZWindow` can override
:cpp:func:`void Tui::ZWindow::closeEvent(Tui::ZCloseEvent *event)` to handle this event.
See the section on the :ref:`close request protcol <ZWindow_close_requests>` for details.
.. cpp:function:: Tui::ZEventType::updateRequest()
This event is used internally to coordinate the emission of paint events (:cpp:class:`Tui::ZPaintEvent`).
.. cpp:function:: Tui::ZEventType::terminalNativeEvent()
This event is dispatched on :cpp:class:`ZTerminal` when processing native events from the low level terminal
abstraction library (:cpp:class:`Tui::ZTerminalNativeEvent`).
Applications that need to customize low level terminal handling can intercept it by subclassing ZTerminal or using
an event filter.
.. cpp:function:: Tui::ZEventType::rawSequence()
This event is dispatched on :cpp:class:`ZTerminal` while processing terminal input
sequences (:cpp:class:`Tui::ZRawSequenceEvent`).
Applications that need to customize low level terminal handling can intercept it by subclassing ZTerminal or using
an event filter.
.. cpp:function:: Tui::ZEventType::pendingRawSequence()
This event is dispatched on :cpp:class:`ZTerminal` while processing terminal input
sequences that are not completely received yet (:cpp:class:`Tui::ZRawSequenceEvent`).
Applications that need to customize low level terminal handling can intercept it by subclassing ZTerminal or using
an event filter.
The following Qt events are used by Tui Widgets:
.. rst-class:: tw-spaceafter
.. adhoc-def:: QEvent::LayoutRequest
Used in :cpp:class:`Tui::ZWidget` and :cpp:class:`Tui::ZTerminal` to trigger relayout (:cpp:class:`QEvent`).
.. rst-class:: tw-spaceafter
.. _qevent_showtoparent:
.. adhoc-def:: QEvent::ShowToParent
Informs a widget that is is now locally visible (:cpp:class:`QEvent`).
If the effective visibility changed the widget will have received a :cpp:func:`Tui::ZEventType::show()` event before
this event.
.. rst-class:: tw-spaceafter
.. _qevent_hidetoparent:
.. adhoc-def:: QEvent::HideToParent
Informs a widget that is is no longer locally visible (:cpp:class:`QEvent`).
If the effective visibility changed the widget will have received a :cpp:func:`Tui::ZEventType::hide()` event before
this event.
.. rst-class:: tw-spaceafter
.. _qevent_enablechanged:
.. adhoc-def:: QEvent::EnabledChange
Informs a widget that its enabled state has changed.
This event is sent whenever the the effective enabled state is changed.
..
TOOD
QEvent::ParentAboutToChange
ZEvent
------
.. cpp:class:: Tui::ZEvent : public QEvent
ZEvent is the base class of all event classes defined by Tui Widgets.
It is copyable and does not define comparison operators.
It has no user accessable constructors or functions.
ZPaintEvent
-----------
.. cpp:class:: Tui::ZPaintEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::paint()` for usage details.
.. cpp:function:: ZPaintEvent(Tui::ZPainter *painter)
Creates a :cpp:func:`Tui::ZEventType::paint()` event using the painter ``painter``.
.. cpp:function:: ZPaintEvent(Tui::ZPaintEvent::Update, Tui::ZPainter *painter)
Creates a :cpp:func:`Tui::ZEventType::updateRequest()` event using the painter ``painter``.
.. cpp:function:: Tui::ZPainter *painter() const
Returns the painter associated with the event.
.. cpp:class:: Update
.. cpp:var:: static constexpr Update update {}
Used as tag to select the constructor of this class.
ZKeyEvent
---------
.. cpp:class:: Tui::ZKeyEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::key()` for usage details.
.. cpp:function:: ZKeyEvent(int key, Tui::KeyboardModifiers modifiers, const QString &text)
Creates a :cpp:func:`Tui::ZEventType::key()` event using the key ``key``, text ``text`` and
modifiers ``modifiers``.
.. cpp:function:: int key() const
Returns the key associated with the event.
.. cpp:function:: QString text() const
Returns the text associated with the event.
.. cpp:function:: Tui::KeyboardModifiers modifiers() const
Returns the modifiers associated with the event.
ZPasteEvent
-----------
.. cpp:class:: Tui::ZPasteEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::paste()` for usage details.
.. cpp:function:: ZPasteEvent(const QString &text)
Creates a :cpp:func:`Tui::ZEventType::key()` event using text ``text``.
.. cpp:function:: QString text() const
Returns the text associated with the event.
ZFocusEvent
-----------
.. cpp:class:: Tui::ZFocusEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::focusIn()` and :cpp:func:`Tui::ZEventType::focusOut()` for usage details.
.. cpp:function:: ZFocusEvent(Tui::ZFocusEvent::FocusIn, Tui::FocusReason reason = Tui::OtherFocusReason)
Creates a :cpp:func:`Tui::ZEventType::focusIn()` event using reason ``reason``.
.. cpp:function:: ZFocusEvent(Tui::ZFocusEvent::FocusOut, Tui::FocusReason reason = Tui::OtherFocusReason)
Creates a :cpp:func:`Tui::ZEventType::focusOut()` event using reason ``reason``.
.. cpp:function:: Tui::FocusReason reason() const
Returns the focus reason associated with the event.
.. cpp:class:: FocusIn
.. cpp:var:: static constexpr FocusIn focusIn {}
.. cpp:class:: FocusOut
.. cpp:var:: static constexpr FocusOut focusOut {}
Used as tags to select the constructor of this class.
ZMoveEvent
----------
.. cpp:class:: Tui::ZMoveEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::move()` for usage details.
.. cpp:function:: ZMoveEvent(QPoint pos, QPoint oldPos)
Creates a :cpp:func:`Tui::ZEventType::move()` event using position ``pos`` and old position ``oldPos``.
.. cpp:function:: QPoint pos() const
Returns the position associated with the event.
.. cpp:function:: QPoint oldPos() const
Returns the old position associated with the event.
ZResizeEvent
------------
.. cpp:class:: Tui::ZResizeEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::resize()` for usage details.
.. cpp:function:: ZResizeEvent(QSize size, QSize oldSize)
Creates a :cpp:func:`Tui::ZEventType::resize()` event using size ``size`` and old size ``oldSize``.
.. cpp:function:: QSize size() const
Returns the size associated with the event.
.. cpp:function:: QSize oldSize() const
Returns the old size associated with the event.
ZOtherChangeEvent
-----------------
.. cpp:class:: Tui::ZOtherChangeEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::otherChange()` for usage details.
.. cpp:function:: ZOtherChangeEvent(QSet<Tui::ZSymbol> unchanged)
Creates a :cpp:func:`Tui::ZEventType::otherChange()` event using ``unchanged`` as set of unchanged symbols.
.. cpp:function:: QSet<Tui::ZSymbol> unchanged() const
Returns the set of unchanged symbols associated with the event.
.. cpp:function:: static QSet<Tui::ZSymbol> all()
Returns a list of all known change symbols.
.. rst-class:: tw-static
.. cpp:function:: bool match(const QEvent *event, Tui::ZSymbol changed)
Matches the event ``event`` against the change symbol ``changed``. It is safe to use this with any valid QEvent.
ZCloseEvent
-----------
.. cpp:class:: Tui::ZCloseEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::close()` for usage details.
.. cpp:function:: ZCloseEvent(QStringList skipChecks)
Creates a :cpp:func:`Tui::ZEventType::close()` event using ``skipChecks`` as list of checks to skip.
.. cpp:function:: QStringList skipChecks() const
Returns the list of checks to skip associated with the event.
ZRawSequenceEvent
-----------------
.. cpp:class:: Tui::ZRawSequenceEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::rawSequence()` and :cpp:func:`Tui::ZEventType::pendingRawSequence()` for usage details.
.. cpp:function:: ZRawSequenceEvent(QByteArray seq)
Creates a :cpp:func:`Tui::ZEventType::rawSequence()` event using ``seq`` as sequence.
.. cpp:function:: ZRawSequenceEvent(Pending, QByteArray seq)
Creates a :cpp:func:`Tui::ZEventType::pendingRawSequence()` event using ``seq`` as sequence.
.. cpp:function:: QByteArray sequence() const
Returns the sequence associated with the event.
.. cpp:class:: Pending
.. cpp:var:: static constexpr Pending pending {}
Used as tag to select the constructor of this class.
ZTerminalNativeEvent
--------------------
.. cpp:class:: Tui::ZTerminalNativeEvent : public Tui::ZEvent
See :cpp:func:`Tui::ZEventType::terminalNativeEvent()` for usage details.
.. cpp:function:: ZTerminalNativeEvent(void *native)
Initializes native pointer to ``native``.
.. cpp:function:: void *nativeEventPointer() const
Returns a pointer to the native terminal event.
Currently it returns a pointer to a :c:type:`termpaint_event`.
|