Skip to content
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
4 changes: 2 additions & 2 deletions crates/cxx-qt-lib/src/core/qline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod ffi {

#[doc(hidden)]
#[rust_name = "qline_new"]
fn construct(pt1: QPoint, pt2: QPoint) -> QLine;
fn construct(pt1: &QPoint, pt2: &QPoint) -> QLine;

#[doc(hidden)]
#[rust_name = "qline_to_debug_qstring"]
Expand All @@ -112,7 +112,7 @@ pub struct QLine {
impl QLine {
/// Constructs a line object that represents the line between `p1` and `p2`.
pub fn new(pt1: QPoint, pt2: QPoint) -> Self {
ffi::qline_new(pt1, pt2)
ffi::qline_new(&pt1, &pt2)
}
}

Expand Down
21 changes: 17 additions & 4 deletions crates/cxx-qt-lib/src/core/qlinef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod ffi {

#[doc(hidden)]
#[rust_name = "qlinef_new"]
fn construct(pt1: QPointF, pt2: QPointF) -> QLineF;
fn construct(pt1: &QPointF, pt2: &QPointF) -> QLineF;
#[doc(hidden)]
#[rust_name = "qlinef_from_qline"]
fn construct(line: &QLine) -> QLineF;
Expand All @@ -150,7 +150,7 @@ pub struct QLineF {
impl QLineF {
/// Constructs a line object that represents the line between `pt1` and `pt2`.
pub fn new(pt1: QPointF, pt2: QPointF) -> Self {
ffi::qlinef_new(pt1, pt2)
ffi::qlinef_new(&pt1, &pt2)
}
}

Expand All @@ -167,12 +167,25 @@ impl From<&QLine> for QLineF {
ffi::qlinef_from_qline(line)
}
}
impl From<QLine> for QLineF {
/// Construct a `QLineF` object from the given integer-based line.
fn from(line: QLine) -> Self {
Self::from(&line)
}
}

impl From<&QLineF> for QLine {
/// Returns an integer-based copy of this line.
/// Note that the returned line's start and end points are rounded to the nearest integer.
fn from(line: &QLineF) -> Self {
line.to_line()
}
}
impl From<QLineF> for QLine {
/// Returns an integer-based copy of this line.
/// Note that the returned line's start and end points are rounded to the nearest integer.
fn from(value: QLineF) -> Self {
value.to_line()
fn from(line: QLineF) -> Self {
Self::from(&line)
}
}

Expand Down
14 changes: 14 additions & 0 deletions crates/cxx-qt-lib/src/core/qmarginsf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ impl From<&QMargins> for QMarginsF {
ffi::qmarginsf_from_qmargin(margins)
}
}
impl From<QMargins> for QMarginsF {
/// Constructs margins copied from the given `margins`.
fn from(margins: QMargins) -> Self {
Self::from(&margins)
}
}

impl From<&QMarginsF> for QMargins {
/// Returns an integer-based copy of `margins`.
Expand All @@ -183,6 +189,14 @@ impl From<&QMarginsF> for QMargins {
margins.to_margins()
}
}
impl From<QMarginsF> for QMargins {
/// Returns an integer-based copy of `margins`.
///
/// Note that the components in the returned margins will be rounded to the nearest integer.
fn from(margins: QMarginsF) -> Self {
Self::from(&margins)
}
}

// Safety:
//
Expand Down
15 changes: 14 additions & 1 deletion crates/cxx-qt-lib/src/core/qpointf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,25 @@ impl From<&QPoint> for QPointF {
ffi::qpointf_from_qpoint(point)
}
}
impl From<QPoint> for QPointF {
/// Constructs a copy of the given `point`.
fn from(point: QPoint) -> Self {
Self::from(&point)
}
}

impl From<&QPointF> for QPoint {
/// Rounds the coordinates of `point` to the nearest integer,
/// and returns a `QPoint` object with the rounded coordinates.
fn from(point: &QPointF) -> Self {
point.to_point()
}
}
impl From<QPointF> for QPoint {
/// Rounds the coordinates of `point` to the nearest integer,
/// and returns a `QPoint` object with the rounded coordinates.
fn from(point: QPointF) -> Self {
point.to_point()
Self::from(&point)
}
}

Expand Down
17 changes: 15 additions & 2 deletions crates/cxx-qt-lib/src/core/qrectf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,25 @@ impl From<&QRect> for QRectF {
ffi::qrectf_from_qrect(rectangle)
}
}
impl From<QRect> for QRectF {
/// Constructs a `QRectF` rectangle from the given `QRect` rectangle.
fn from(rectangle: QRect) -> Self {
Self::from(&rectangle)
}
}

impl From<&QRectF> for QRect {
/// Returns a `QRect` based on the values of this rectangle.
/// Note that the coordinates in the returned rectangle are rounded to the nearest integer.
fn from(value: &QRectF) -> Self {
value.to_rect()
fn from(rectangle: &QRectF) -> Self {
rectangle.to_rect()
}
}
impl From<QRectF> for QRect {
/// Returns a `QRect` based on the values of this rectangle.
/// Note that the coordinates in the returned rectangle are rounded to the nearest integer.
fn from(rectangle: QRectF) -> Self {
Self::from(&rectangle)
}
}

Expand Down
16 changes: 15 additions & 1 deletion crates/cxx-qt-lib/src/core/qsizef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,27 @@ impl From<&QSize> for QSizeF {
ffi::qsizef_from_qsize(size)
}
}
impl From<QSize> for QSizeF {
/// Constructs a size with floating point accuracy from the given `size`.
fn from(size: QSize) -> Self {
Self::from(&size)
}
}

impl From<&QSizeF> for QSize {
/// Returns an integer based copy of this size.
///
/// Note that the coordinates in the returned size will be rounded to the nearest integer.
fn from(size: &QSizeF) -> Self {
size.to_size()
}
}
impl From<QSizeF> for QSize {
/// Returns an integer based copy of this size.
///
/// Note that the coordinates in the returned size will be rounded to the nearest integer.
fn from(size: QSizeF) -> Self {
size.to_size()
Self::from(&size)
}
}

Expand Down
6 changes: 6 additions & 0 deletions crates/cxx-qt-lib/src/gui/qpainterpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ impl From<&QPointF> for QPainterPath {
ffi::qpainterpath_from_qpointf(start_point)
}
}
impl From<QPointF> for QPainterPath {
/// Creates a `QPainterPath` object with the given `start_point` as its current position.
fn from(start_point: QPointF) -> Self {
Self::from(&start_point)
}
}

impl PartialEq for QPainterPath {
fn eq(&self, other: &Self) -> bool {
Expand Down
16 changes: 14 additions & 2 deletions crates/cxx-qt-lib/src/gui/qpen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod ffi {

#[doc(hidden)]
#[rust_name = "qpen_init_from_penstyle"]
fn construct(penstyle: &PenStyle) -> QPen;
fn construct(penstyle: PenStyle) -> QPen;

#[doc(hidden)]
#[rust_name = "qpen_drop"]
Expand Down Expand Up @@ -182,11 +182,23 @@ impl From<&QColor> for QPen {
ffi::qpen_init_from_qcolor(color)
}
}
impl From<QColor> for QPen {
/// Constructs a solid line pen with 1 width and the given `color`.
fn from(color: QColor) -> Self {
Self::from(&color)
}
}

impl From<PenStyle> for QPen {
/// Constructs a black pen with 1 width and the given `style`.
fn from(style: PenStyle) -> Self {
ffi::qpen_init_from_penstyle(style)
}
}
impl From<&PenStyle> for QPen {
/// Constructs a black pen with 1 width and the given `style`.
fn from(style: &PenStyle) -> Self {
ffi::qpen_init_from_penstyle(style)
ffi::qpen_init_from_penstyle(*style)
}
}

Expand Down
32 changes: 31 additions & 1 deletion crates/cxx-qt-lib/src/gui/qpolygonf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cxx_qt::casting::Upcast;
use std::fmt;
use std::ops::{Deref, DerefMut};

use crate::{QPointF, QVector};
use crate::{QPointF, QPolygon, QVector};

#[cxx::bridge]
mod ffi {
Expand Down Expand Up @@ -101,6 +101,10 @@ mod ffi {
#[rust_name = "qpolygonf_init_default"]
fn construct() -> QPolygonF;

#[doc(hidden)]
#[rust_name = "qpolygonf_from_qpolygon"]
fn construct(polygon: &QPolygon) -> QPolygonF;

#[doc(hidden)]
#[rust_name = "qpolygonf_drop"]
fn drop(pen: &mut QPolygonF);
Expand Down Expand Up @@ -185,6 +189,32 @@ impl DerefMut for QPolygonF {
}
}

impl From<&QPolygon> for QPolygonF {
/// Constructs a float based polygon from the specified integer based polygon.
fn from(polygon: &QPolygon) -> Self {
ffi::qpolygonf_from_qpolygon(polygon)
}
}
impl From<QPolygon> for QPolygonF {
/// Constructs a float based polygon from the specified integer based polygon.
fn from(polygon: QPolygon) -> Self {
Self::from(&polygon)
}
}

impl From<&QPolygonF> for QPolygon {
/// Creates and returns a `QPolygon` by converting each `QPointF` to a `QPoint`.
fn from(polygon: &QPolygonF) -> Self {
polygon.to_polygon()
}
}
impl From<QPolygonF> for QPolygon {
/// Creates and returns a `QPolygon` by converting each `QPointF` to a `QPoint`.
fn from(value: QPolygonF) -> Self {
Self::from(&value)
}
}

unsafe impl Upcast<QVector<QPointF>> for QPolygonF {
unsafe fn upcast_ptr(this: *const Self) -> *const QVector<QPointF> {
ffi::upcast_qpolygonf(this)
Expand Down
6 changes: 6 additions & 0 deletions crates/cxx-qt-lib/src/gui/qquaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ impl From<&QVector4D> for QQuaternion {
ffi::qquaternion_init_qvector4d(value)
}
}
impl From<QVector4D> for QQuaternion {
/// Constructs a quaternion from the components of vector.
fn from(value: QVector4D) -> Self {
Self::from(&value)
}
}

// Safety:
//
Expand Down
Loading