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 /// Qt's predefined `QColor` objects.
40 #[repr(i32)]
41 enum GlobalColor {
42 /// 0 pixel value (for bitmaps)
43 color0,
44 /// 1 pixel value (for bitmaps)
45 color1,
46 /// Black (#000000)
47 black,
48 /// White (#ffffff)
49 white,
50 /// Dark gray (#808080)
51 darkGray,
52 /// Gray (#a0a0a4)
53 gray,
54 /// Light gray (#c0c0c0)
55 lightGray,
56 /// Red (#ff0000)
57 red,
58 /// Green (#00ff00)
59 green,
60 /// Blue (#0000ff)
61 blue,
62 /// Cyan (#00ffff)
63 cyan,
64 /// Magenta (#ff00ff)
65 magenta,
66 /// Yellow (#ffff00)
67 yellow,
68 /// Dark red (#800000)
69 darkRed,
70 /// Dark green (#008000)
71 darkGreen,
72 /// Dark blue (#000080)
73 darkBlue,
74 /// Dark cyan (#008080)
75 darkCyan,
76 /// Dark magenta (#ff00ff)
77 darkMagenta,
78 /// Dark yellow (#808000)
79 darkYellow,
80 /// a transparent black value (i.e., `QColor(0, 0, 0,0)`)
81 transparent,
82 }
83
84 /// This enum specifies how [`QString::split`](crate::QString::split) functions should behave with respect to empty strings.
85 #[repr(i32)]
86 enum SplitBehaviorFlags {
87 /// If a field is empty, keep it in the result.
88 KeepEmptyParts,
89 /// If a field is empty, don't include it in the result.
90 SkipEmptyParts,
91 }
92
93 #[repr(i32)]
94 enum TimeSpec {
95 /// Local time, controlled by a system time-zone setting.
96 LocalTime,
97 /// Coordinated Universal Time.
98 UTC,
99 /// An offset in seconds from Coordinated Universal Time.
100 OffsetFromUTC,
101 /// A named time zone.
102 TimeZone,
103 }
104
105 /// This enum type defines whether image transformations (e.g., scaling) should be smooth or not.
106 #[repr(i32)]
107 enum TransformationMode {
108 /// The transformation is performed quickly, with no smoothing.
109 FastTransformation,
110 /// The resulting image is transformed using bilinear filtering.
111 SmoothTransformation,
112 }
113
114 /// This enum type defines the pen styles that can be drawn using [`QPainter`](crate::QPainter).
115 #[repr(i32)]
116 enum PenStyle {
117 /// No line at all. For example, [`QPainter::draw_rect_f`](crate::QPainter::draw_rect_f) fills but does not draw any boundary line.
118 NoPen,
119 /// A plain line.
120 SolidLine,
121 /// Dashes separated by a few pixels.
122 DashLine,
123 /// Dots separated by a few pixels.
124 DotLine,
125 /// Alternate dots and dashes.
126 DashDotLine,
127 /// One dash, two dots, one dash, two dots.
128 DashDotDotLine,
129 /// A custom pattern defined using [QPainterPathStroker::setDashPattern](https://doc.qt.io/qt/qpainterpathstroker.html#setDashPattern)().
130 CustomDashLine,
131 }
132
133 /// 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).
134 #[repr(i32)]
135 enum PenCapStyle {
136 /// A square line end that does not cover the end point of the line.
137 FlatCap = 0x00,
138 /// A square line end that covers the end point and extends beyond it by half the line width.
139 SquareCap = 0x10,
140 /// A rounded line end.
141 RoundCap = 0x20,
142 #[doc(hidden)]
143 MPenCapStyle = 0x30,
144 }
145
146 /// 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).
147 #[repr(i32)]
148 enum PenJoinStyle {
149 /// The outer edges of the lines are extended to meet at an angle, and this area is filled.
150 MiterJoin = 0x00,
151 /// The triangular notch between the two lines is filled.
152 BevelJoin = 0x40,
153 /// A circular arc between the two lines is filled.
154 RoundJoin = 0x80,
155 /// A miter join corresponding to the definition of a miter join in the SVG 1.2 Tiny specification.
156 SvgMiterJoin = 0x100,
157 #[doc(hidden)]
158 MPenJoinStyle = 0x1c0,
159 }
160
161 /// Specifies which method should be used to fill the paths and polygons.
162 #[repr(i32)]
163 enum FillRule {
164 /// Specifies that the region is filled using the odd even fill rule.
165 /// With this rule, we determine whether a point is inside the shape by using
166 /// the following method. Draw a horizontal line from the point to a location
167 /// outside the shape, and count the number of intersections. If the number of
168 /// intersections is an odd number, the point is inside the shape. This mode is the default.
169 OddEvenFill,
170 /// Specifies that the region is filled using the non zero winding rule.
171 /// With this rule, we determine whether a point is inside the shape by using the following method.
172 /// Draw a horizontal line from the point to a location outside the shape. Determine whether
173 /// the direction of the line at each intersection point is up or down. The winding number is determined
174 /// by summing the direction of each intersection. If the number is non zero, the point is inside the shape.
175 /// This fill mode can also in most cases be considered as the intersection of closed shapes.
176 WindingFill,
177 }
178
179 /// This enum type specifies the direction of Qt's layouts and text handling.
180 #[repr(i32)]
181 enum LayoutDirection {
182 /// Left-to-right layout.
183 LeftToRight,
184 /// Right-to-left layout.
185 RightToLeft,
186 /// Automatic layout. Text directionality is determined from the content of the string to be layouted.
187 LayoutDirectionAuto,
188 }
189
190 /// This enum type specifies the background mode.
191 #[repr(i32)]
192 enum BGMode {
193 TransparentMode,
194 OpaqueMode,
195 }
196
197 #[repr(i32)]
198 enum ClipOperation {
199 /// This operation turns clipping off.
200 NoClip,
201 /// Replaces the current clip path/rect/region with the one supplied in the function call.
202 ReplaceClip,
203 /// Intersects the current clip path/rect/region with the one supplied in the function call.
204 IntersectClip,
205 }
206
207 /// This enum is used by [`QPainter::draw_rounded_rect`](crate::QPainter::draw_rounded_rect) and [`QPainterPath::add_rounded_rect`](crate::QPainterPath::add_rounded_rect)
208 /// functions to specify the radii of rectangle corners with respect to the dimensions
209 /// of the bounding rectangles specified.
210 #[repr(i32)]
211 enum SizeMode {
212 /// Specifies the size using absolute measurements.
213 AbsoluteSize,
214 /// Specifies the size relative to the bounding rectangle, typically using percentage measurements.
215 RelativeSize,
216 }
217
218 /// This enum describes the modifier keys.
219 #[derive(Debug)]
220 #[repr(u32)]
221 enum KeyboardModifier {
222 /// No modifier key is pressed.
223 NoModifier = 0x00000000,
224 /// A Shift key on the keyboard is pressed.
225 ShiftModifier = 0x02000000,
226 /// A Ctrl key on the keyboard is pressed.
227 ControlModifier = 0x04000000,
228 /// An Alt key on the keyboard is pressed.
229 AltModifier = 0x08000000,
230 /// A Meta key on the keyboard is pressed.
231 MetaModifier = 0x10000000,
232 /// A keypad button is pressed.
233 KeypadModifier = 0x20000000,
234 /// X11 only (unless activated on Windows by a command line argument).
235 /// A Mode_switch key on the keyboard is pressed.
236 GroupSwitchModifier = 0x40000000,
237 }
238
239 /// This enum type describes the different mouse buttons.
240 #[derive(Debug)]
241 #[repr(u32)]
242 enum MouseButton {
243 /// The button state does not refer to any button.
244 NoButton = 0x00000000,
245 /// This value corresponds to a mask of all possible mouse buttons. Use to set the
246 /// ['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.
247 AllButtons = 0x07ffffff,
248 /// The left button is pressed, or an event refers to the left button. (The left button may
249 /// be the right button on left-handed mice.)
250 LeftButton = 0x00000001,
251 /// The right button.
252 RightButton = 0x00000002,
253 /// The middle button.
254 MiddleButton = 0x00000004,
255 /// The 'Back' button. (Typically present on the 'thumb' side of a mouse with extra buttons.
256 /// This is NOT the tilt wheel.)
257 BackButton = 0x00000008,
258 /// The 'Forward' button. (Typically present beside the 'Back' button, and also pressed by
259 /// the thumb.)
260 ForwardButton = 0x00000010,
261 /// The 'Task' button.
262 TaskButton = 0x00000020,
263 ExtraButton4 = 0x00000040,
264 ExtraButton5 = 0x00000080,
265 ExtraButton6 = 0x00000100,
266 ExtraButton7 = 0x00000200,
267 ExtraButton8 = 0x00000400,
268 ExtraButton9 = 0x00000800,
269 ExtraButton10 = 0x00001000,
270 ExtraButton11 = 0x00002000,
271 ExtraButton12 = 0x00004000,
272 ExtraButton13 = 0x00008000,
273 ExtraButton14 = 0x00010000,
274 ExtraButton15 = 0x00020000,
275 ExtraButton16 = 0x00040000,
276 ExtraButton17 = 0x00080000,
277 ExtraButton18 = 0x00100000,
278 ExtraButton19 = 0x00200000,
279 ExtraButton20 = 0x00400000,
280 ExtraButton21 = 0x00800000,
281 ExtraButton22 = 0x01000000,
282 ExtraButton23 = 0x02000000,
283 ExtraButton24 = 0x04000000,
284 }
285
286 #[derive(Debug)]
287 #[repr(u32)]
288 /// This type is used to signify an object's orientation.
289 enum Orientation {
290 /// Horizontal orientation
291 Horizontal = 0x1,
292 /// Vertical orientation
293 Vertical = 0x2,
294 }
295
296 unsafe extern "C++" {
297 include!("cxx-qt-lib/qt.h");
298 type AspectRatioMode;
299 type CaseSensitivity;
300 type DateFormat;
301 type SplitBehaviorFlags;
302 type TimeSpec;
303 type TransformationMode;
304 type PenStyle;
305 type PenCapStyle;
306 type PenJoinStyle;
307 type FillRule;
308 type LayoutDirection;
309 type BGMode;
310 type ClipOperation;
311 type SizeMode;
312 type MouseButton;
313 type KeyboardModifier;
314 type Orientation;
315 type GlobalColor;
316 }
317}
318
319pub use ffi::{
320 AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, DateFormat, FillRule, GlobalColor,
321 KeyboardModifier, LayoutDirection, MouseButton, Orientation, PenCapStyle, PenJoinStyle,
322 PenStyle, SizeMode, SplitBehaviorFlags, TimeSpec, TransformationMode,
323};
324
325// Reexport ConnectionType from cxx-qt
326pub use cxx_qt::ConnectionType;
327
328/// [`QFlags`] of [`MouseButton`].
329pub type MouseButtons = QFlags<MouseButton>;
330/// [`QFlags`] of [`KeyboardModifier`].
331pub type KeyboardModifiers = QFlags<KeyboardModifier>;
332/// [`QFlags`] of [`Orientation`].
333pub type Orientations = QFlags<Orientation>;
334
335unsafe_impl_qflag!(MouseButton, "Qt::MouseButtons", u32);
336unsafe_impl_qflag!(KeyboardModifier, "Qt::KeyboardModifiers", u32);
337unsafe_impl_qflag!(Orientation, "Qt::Orientations", u32);