diff --git a/crates/cxx-qt-lib-headers/include/gui/qpainter.h b/crates/cxx-qt-lib-headers/include/gui/qpainter.h index c2e9dc533..dafa81bd8 100644 --- a/crates/cxx-qt-lib-headers/include/gui/qpainter.h +++ b/crates/cxx-qt-lib-headers/include/gui/qpainter.h @@ -10,3 +10,10 @@ #include #include + +namespace rust { +namespace cxxqtlib1 { +using QPainterRenderHint = QPainter::RenderHint; + +} // namespace cxxqtlib1 +} // namespace rust diff --git a/crates/cxx-qt-lib/src/gui/mod.rs b/crates/cxx-qt-lib/src/gui/mod.rs index b2a04c39b..192cb0bfd 100644 --- a/crates/cxx-qt-lib/src/gui/mod.rs +++ b/crates/cxx-qt-lib/src/gui/mod.rs @@ -37,4 +37,4 @@ mod qpainterpath; pub use qpainterpath::QPainterPath; mod qpainter; -pub use qpainter::QPainter; +pub use qpainter::{QPainter, QPainterRenderHint}; diff --git a/crates/cxx-qt-lib/src/gui/qpainter.rs b/crates/cxx-qt-lib/src/gui/qpainter.rs index 3ae3a03cd..816112599 100644 --- a/crates/cxx-qt-lib/src/gui/qpainter.rs +++ b/crates/cxx-qt-lib/src/gui/qpainter.rs @@ -15,6 +15,27 @@ mod ffi { type SizeMode = crate::SizeMode; } + /// Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine. + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + #[derive(Debug)] + enum QPainterRenderHint { + /// Indicates that the engine should antialias edges of primitives if possible. + Antialiasing = 0x01, + /// Indicates that the engine should antialias text if possible. + /// To forcibly disable antialiasing for text, do not use this hint. + /// Instead, set QFont::NoAntialias on your font's style strategy. + TextAntialiasing = 0x02, + /// Indicates that the engine should use a smooth pixmap transformation algorithm + /// (such as bilinear) rather than nearest neighbor. + SmoothPixmapTransform = 0x04, + /// Use a lossless image rendering, whenever possible. Currently, this hint is only + /// used when QPainter is employed to output a PDF file through QPrinter or QPdfWriter, + /// where drawImage()/drawPixmap() calls will encode images using a lossless compression + /// algorithm instead of lossy JPEG compression. This value was added in Qt 5.13. + LosslessImageRendering = 0x40, + } + unsafe extern "C++" { include!("cxx-qt-lib/qpainter.h"); type QPainter; @@ -197,15 +218,19 @@ mod ffi { #[rust_name = "set_layout_direction"] fn setLayoutDirection(self: Pin<&mut QPainter>, direction: LayoutDirection); - /// Sets the painter's pen to be the given pen. - #[rust_name = "set_pen"] - fn setPen(self: Pin<&mut QPainter>, pen: &QPen); - /// Sets the opacity of the painter to opacity. The value should be in the range 0.0 to 1.0, /// where 0.0 is fully transparent and 1.0 is fully opaque. #[rust_name = "set_opacity"] fn setOpacity(self: Pin<&mut QPainter>, opacity: f64); + /// Sets the painter's pen to be the given pen. + #[rust_name = "set_pen"] + fn setPen(self: Pin<&mut QPainter>, pen: &QPen); + + /// Sets the given render hint on the painter if on is true; otherwise clears the render hint. + #[rust_name = "set_render_hint"] + fn setRenderHint(self: Pin<&mut QPainter>, hint: QPainterRenderHint, on: bool); + /// Sets the painter's viewport rectangle to the given rectangle, and enables view transformations. #[rust_name = "set_viewport"] fn setViewport(self: Pin<&mut QPainter>, rectangle: &QRect); @@ -218,6 +243,10 @@ mod ffi { #[rust_name = "stroke_path"] fn strokePath(self: Pin<&mut QPainter>, path: &QPainterPath, pen: &QPen); + /// Returns true if hint is set; otherwise returns false. + #[rust_name = "test_render_hint"] + fn testRenderHint(self: &QPainter, hint: QPainterRenderHint) -> bool; + /// Restores the current painter state (pops a saved state off the stack). fn restore(self: Pin<&mut QPainter>); @@ -239,13 +268,15 @@ mod ffi { unsafe extern "C++" { include!("cxx-qt-lib/common.h"); + type QPainterRenderHint; + #[doc(hidden)] #[rust_name = "qpainter_init_default"] fn make_unique() -> UniquePtr; } } -pub use ffi::QPainter; +pub use ffi::{QPainter, QPainterRenderHint}; impl QPainter { /// Create a QPainter