cxx_qt_lib/core/qt.rs
1// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6use crate::{unsafe_impl_qflag, QFlags};
7
8#[cxx::bridge(namespace = "Qt")]
9mod ffi {
10 /// This enum type defines what happens to the aspect ratio when scaling an rectangle.
11 #[repr(i32)]
12 enum AspectRatioMode {
13 /// The size is scaled freely. The aspect ratio is not preserved.
14 IgnoreAspectRatio,
15 /// The size is scaled to a rectangle as large as possible inside a given rectangle, preserving the aspect ratio.
16 KeepAspectRatio,
17 /// The size is scaled to a rectangle as small as possible outside a given rectangle, preserving the aspect ratio.
18 KeepAspectRatioByExpanding,
19 }
20
21 #[repr(i32)]
22 enum CaseSensitivity {
23 CaseInsensitive,
24 CaseSensitive,
25 }
26
27 #[repr(i32)]
28 enum DateFormat {
29 /// The default Qt format, which includes the day and month name, the day number in the month, and the year in full. The day and month names will be short names in English (C locale). This effectively uses, for a date, format `ddd MMM d yyyy`, for a time `HH:mm:ss` and combines these as `ddd MMM d HH:mm:ss yyyy` for a date-time, with an optional zone-offset suffix, where relevant. When reading from a string, a fractional part is also recognized on the seconds of a time part, as `HH:mm:ss.zzz`, and some minor variants on the format may be recognized, for compatibility with earlier versions of Qt and with changes to the format planned for the future. In particular, the zone-offset suffix presently uses GMT\[±`tzoff`\] with a `tzoff` in `HH[[:]mm]` format (two-digit hour and optional two-digit minutes, with optional colon separator); this shall change to use UTC in place of GMT in a future release of Qt, so the planned UTC format is recognized.
30 TextDate = 0,
31 /// ISO 8601 extended format: uses `yyyy-MM-dd` for dates, `HH:mm:ss.zzz` for times or `yyyy-MM-ddTHH:mm:ss.zzz` (e.g. `2017-07-24T15:46:29.739`) for combined dates and times, optionally with a time-zone suffix (`Z` for UTC otherwise an offset as `±HH:mm`) where appropriate. When parsed, a single space, `' '`, may be used in place of the `'T'` separator between date and time; no other spacing characters are permitted. This format also accepts `HH:mm` and plain `HH` formats for the time part, either of which may include a fractional part, `HH:mm.zzz` or `HH.zzz`, applied to the last field present (hour or minute).
32 ISODateWithMs = 9,
33 /// ISO 8601 extended format, as for `ISODateWithMs`, but omitting the milliseconds (`.zzz`) part when converting to a string. There is no difference when reading from a string: if a fractional part is present on the last time field, either format will accept it.
34 ISODate = 1,
35 /// RFC 2822, RFC 850 and RFC 1036 format: when converting dates to string form, format `dd MMM yyyy` is used, for times the format is `HH:mm:ss`. For combined date and time, these are combined as `dd MMM yyyy HH:mm:ss ±tzoff` (omitting the optional leading day of the week from the first format recognized). When reading from a string either `[ddd,] dd MMM yyyy [HH:mm[:ss]][ ±tzoff]` or `ddd MMM dd[ HH:mm:ss] yyyy[ ±tzoff]` will be recognized for combined dates and times, where `tzoff` is a timezone offset in `HHmm` format. Arbitrary spacing may appear before or after the text and any non-empty spacing may replace the spaces in this format. For dates and times separately, the same formats are matched and the unwanted parts are ignored. In particular, note that a time is not recognized without an accompanying date.
36 RFC2822Date = 8,
37 }
38
39 /// This enum specifies how [`QString::split`](crate::QString::split) functions should behave with respect to empty strings.
40 #[repr(i32)]
41 enum SplitBehaviorFlags {
42 /// If a field is empty, keep it in the result.
43 KeepEmptyParts,
44 /// If a field is empty, don't include it in the result.
45 SkipEmptyParts,
46 }
47
48 #[repr(i32)]
49 enum TimeSpec {
50 /// Local time, controlled by a system time-zone setting.
51 LocalTime,
52 /// Coordinated Universal Time.
53 UTC,
54 /// An offset in seconds from Coordinated Universal Time.
55 OffsetFromUTC,
56 /// A named time zone.
57 TimeZone,
58 }
59
60 /// This enum type defines whether image transformations (e.g., scaling) should be smooth or not.
61 #[repr(i32)]
62 enum TransformationMode {
63 /// The transformation is performed quickly, with no smoothing.
64 FastTransformation,
65 /// The resulting image is transformed using bilinear filtering.
66 SmoothTransformation,
67 }
68
69 /// This enum type defines the pen styles that can be drawn using [`QPainter`](crate::QPainter).
70 #[repr(i32)]
71 enum PenStyle {
72 /// No line at all. For example, [`QPainter::draw_rect_f`](crate::QPainter::draw_rect_f) fills but does not draw any boundary line.
73 NoPen,
74 /// A plain line.
75 SolidLine,
76 /// Dashes separated by a few pixels.
77 DashLine,
78 /// Dots separated by a few pixels.
79 DotLine,
80 /// Alternate dots and dashes.
81 DashDotLine,
82 /// One dash, two dots, one dash, two dots.
83 DashDotDotLine,
84 /// A custom pattern defined using [QPainterPathStroker::setDashPattern](https://doc.qt.io/qt/qpainterpathstroker.html#setDashPattern)().
85 CustomDashLine,
86 }
87
88 /// This enum type defines the pen cap styles supported by Qt, i.e. the line end caps that can be drawn using [`QPainter`](crate::QPainter).
89 #[repr(i32)]
90 enum PenCapStyle {
91 /// A square line end that does not cover the end point of the line.
92 FlatCap = 0x00,
93 /// A square line end that covers the end point and extends beyond it by half the line width.
94 SquareCap = 0x10,
95 /// A rounded line end.
96 RoundCap = 0x20,
97 #[doc(hidden)]
98 MPenCapStyle = 0x30,
99 }
100
101 /// This enum type defines the pen join styles supported by Qt, i.e. which joins between two connected lines can be drawn using [`QPainter`](crate::QPainter).
102 #[repr(i32)]
103 enum PenJoinStyle {
104 /// The outer edges of the lines are extended to meet at an angle, and this area is filled.
105 MiterJoin = 0x00,
106 /// The triangular notch between the two lines is filled.
107 BevelJoin = 0x40,
108 /// A circular arc between the two lines is filled.
109 RoundJoin = 0x80,
110 /// A miter join corresponding to the definition of a miter join in the SVG 1.2 Tiny specification.
111 SvgMiterJoin = 0x100,
112 #[doc(hidden)]
113 MPenJoinStyle = 0x1c0,
114 }
115
116 /// Specifies which method should be used to fill the paths and polygons.
117 #[repr(i32)]
118 enum FillRule {
119 /// Specifies that the region is filled using the odd even fill rule.
120 /// With this rule, we determine whether a point is inside the shape by using
121 /// the following method. Draw a horizontal line from the point to a location
122 /// outside the shape, and count the number of intersections. If the number of
123 /// intersections is an odd number, the point is inside the shape. This mode is the default.
124 OddEvenFill,
125 /// Specifies that the region is filled using the non zero winding rule.
126 /// With this rule, we determine whether a point is inside the shape by using the following method.
127 /// Draw a horizontal line from the point to a location outside the shape. Determine whether
128 /// the direction of the line at each intersection point is up or down. The winding number is determined
129 /// by summing the direction of each intersection. If the number is non zero, the point is inside the shape.
130 /// This fill mode can also in most cases be considered as the intersection of closed shapes.
131 WindingFill,
132 }
133
134 /// This enum type specifies the direction of Qt's layouts and text handling.
135 #[repr(i32)]
136 enum LayoutDirection {
137 /// Left-to-right layout.
138 LeftToRight,
139 /// Right-to-left layout.
140 RightToLeft,
141 /// Automatic layout. Text directionality is determined from the content of the string to be layouted.
142 LayoutDirectionAuto,
143 }
144
145 /// This enum type specifies the background mode.
146 #[repr(i32)]
147 enum BGMode {
148 TransparentMode,
149 OpaqueMode,
150 }
151
152 #[repr(i32)]
153 enum ClipOperation {
154 /// This operation turns clipping off.
155 NoClip,
156 /// Replaces the current clip path/rect/region with the one supplied in the function call.
157 ReplaceClip,
158 /// Intersects the current clip path/rect/region with the one supplied in the function call.
159 IntersectClip,
160 }
161
162 /// This enum is used by [`QPainter::draw_rounded_rect`](crate::QPainter::draw_rounded_rect) and [`QPainterPath::add_rounded_rect`](crate::QPainterPath::add_rounded_rect)
163 /// functions to specify the radii of rectangle corners with respect to the dimensions
164 /// of the bounding rectangles specified.
165 #[repr(i32)]
166 enum SizeMode {
167 /// Specifies the size using absolute measurements.
168 AbsoluteSize,
169 /// Specifies the size relative to the bounding rectangle, typically using percentage measurements.
170 RelativeSize,
171 }
172
173 /// This enum describes the modifier keys.
174 #[derive(Debug)]
175 #[repr(u32)]
176 enum KeyboardModifier {
177 /// No modifier key is pressed.
178 NoModifier = 0x00000000,
179 /// A Shift key on the keyboard is pressed.
180 ShiftModifier = 0x02000000,
181 /// A Ctrl key on the keyboard is pressed.
182 ControlModifier = 0x04000000,
183 /// An Alt key on the keyboard is pressed.
184 AltModifier = 0x08000000,
185 /// A Meta key on the keyboard is pressed.
186 MetaModifier = 0x10000000,
187 /// A keypad button is pressed.
188 KeypadModifier = 0x20000000,
189 /// X11 only (unless activated on Windows by a command line argument).
190 /// A Mode_switch key on the keyboard is pressed.
191 GroupSwitchModifier = 0x40000000,
192 }
193
194 /// This enum type describes the different mouse buttons.
195 #[derive(Debug)]
196 #[repr(u32)]
197 enum MouseButton {
198 /// The button state does not refer to any button.
199 NoButton = 0x00000000,
200 /// This value corresponds to a mask of all possible mouse buttons. Use to set the
201 /// ['acceptedButtons'](https://doc.qt.io/qt/qml-qtquick-mousearea.html#acceptedButtons-prop) property of a [MouseArea](https://doc.qt.io/qt/qml-qtquick-mousearea.html) to accept ALL mouse buttons.
202 AllButtons = 0x07ffffff,
203 /// The left button is pressed, or an event refers to the left button. (The left button may
204 /// be the right button on left-handed mice.)
205 LeftButton = 0x00000001,
206 /// The right button.
207 RightButton = 0x00000002,
208 /// The middle button.
209 MiddleButton = 0x00000004,
210 /// The 'Back' button. (Typically present on the 'thumb' side of a mouse with extra buttons.
211 /// This is NOT the tilt wheel.)
212 BackButton = 0x00000008,
213 /// The 'Forward' button. (Typically present beside the 'Back' button, and also pressed by
214 /// the thumb.)
215 ForwardButton = 0x00000010,
216 /// The 'Task' button.
217 TaskButton = 0x00000020,
218 ExtraButton4 = 0x00000040,
219 ExtraButton5 = 0x00000080,
220 ExtraButton6 = 0x00000100,
221 ExtraButton7 = 0x00000200,
222 ExtraButton8 = 0x00000400,
223 ExtraButton9 = 0x00000800,
224 ExtraButton10 = 0x00001000,
225 ExtraButton11 = 0x00002000,
226 ExtraButton12 = 0x00004000,
227 ExtraButton13 = 0x00008000,
228 ExtraButton14 = 0x00010000,
229 ExtraButton15 = 0x00020000,
230 ExtraButton16 = 0x00040000,
231 ExtraButton17 = 0x00080000,
232 ExtraButton18 = 0x00100000,
233 ExtraButton19 = 0x00200000,
234 ExtraButton20 = 0x00400000,
235 ExtraButton21 = 0x00800000,
236 ExtraButton22 = 0x01000000,
237 ExtraButton23 = 0x02000000,
238 ExtraButton24 = 0x04000000,
239 }
240
241 #[derive(Debug)]
242 #[repr(u32)]
243 /// This type is used to signify an object's orientation.
244 enum Orientation {
245 /// Horizontal orientation
246 Horizontal = 0x1,
247 /// Vertical orientation
248 Vertical = 0x2,
249 }
250
251 unsafe extern "C++" {
252 include!("cxx-qt-lib/qt.h");
253 type AspectRatioMode;
254 type CaseSensitivity;
255 type DateFormat;
256 type SplitBehaviorFlags;
257 type TimeSpec;
258 type TransformationMode;
259 type PenStyle;
260 type PenCapStyle;
261 type PenJoinStyle;
262 type FillRule;
263 type LayoutDirection;
264 type BGMode;
265 type ClipOperation;
266 type SizeMode;
267 type MouseButton;
268 type KeyboardModifier;
269 type Orientation;
270 }
271}
272
273pub use ffi::{
274 AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, DateFormat, FillRule,
275 KeyboardModifier, LayoutDirection, MouseButton, Orientation, PenCapStyle, PenJoinStyle,
276 PenStyle, SizeMode, SplitBehaviorFlags, TimeSpec, TransformationMode,
277};
278
279// Reexport ConnectionType from cxx-qt
280pub use cxx_qt::ConnectionType;
281
282/// [`QFlags`] of [`MouseButton`].
283pub type MouseButtons = QFlags<MouseButton>;
284/// [`QFlags`] of [`KeyboardModifier`].
285pub type KeyboardModifiers = QFlags<KeyboardModifier>;
286/// [`QFlags`] of [`Orientation`].
287pub type Orientations = QFlags<Orientation>;
288
289unsafe_impl_qflag!(MouseButton, "Qt::MouseButtons", u32);
290unsafe_impl_qflag!(KeyboardModifier, "Qt::KeyboardModifiers", u32);
291unsafe_impl_qflag!(Orientation, "Qt::Orientations", u32);