Skip to content

Add QPainterRenderHint #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/cxx-qt-lib-headers/include/gui/qpainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
#include <memory>

#include <QtGui/QPainter>

namespace rust {
namespace cxxqtlib1 {
using QPainterRenderHint = QPainter::RenderHint;

} // namespace cxxqtlib1
} // namespace rust
2 changes: 1 addition & 1 deletion crates/cxx-qt-lib/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ mod qpainterpath;
pub use qpainterpath::QPainterPath;

mod qpainter;
pub use qpainter::QPainter;
pub use qpainter::{QPainter, QPainterRenderHint};
41 changes: 36 additions & 5 deletions crates/cxx-qt-lib/src/gui/qpainter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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>);

Expand All @@ -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<QPainter>;
}
}

pub use ffi::QPainter;
pub use ffi::{QPainter, QPainterRenderHint};

impl QPainter {
/// Create a QPainter
Expand Down