1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// SPDX-FileContributor: Laurent Montel <laurent.montel@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::QPoint;
use cxx::{type_id, ExternType};
use std::fmt;
#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qline.h");
type QLine = super::QLine;
include!("cxx-qt-lib/qpoint.h");
type QPoint = crate::QPoint;
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;
include!("cxx-qt-lib/qlinef.h");
#[allow(dead_code)]
type QLineF = crate::QLineF;
/// Returns the line's start point.
fn p1(self: &QLine) -> QPoint;
/// Returns the line's end point.
fn p2(self: &QLine) -> QPoint;
/// Returns the x-coordinate of the line's start point.
fn x1(self: &QLine) -> i32;
/// Returns the x-coordinate of the line's end point.
fn x2(self: &QLine) -> i32;
/// Returns the y-coordinate of the line's start point.
fn y1(self: &QLine) -> i32;
/// Returns the y-coordinate of the line's end point.
fn y2(self: &QLine) -> i32;
/// Returns the center point of this line. This is equivalent to `(self.p1() + self.p2()) / 2`, except it will never overflow.
fn center(self: &QLine) -> QPoint;
/// Returns the horizontal component of the line's vector.
fn dx(self: &QLine) -> i32;
/// Returns the vertical component of the line's vector.
fn dy(self: &QLine) -> i32;
/// Returns `true` if the line does not have distinct start and end points; otherwise returns `false`.
#[rust_name = "is_null"]
fn isNull(self: &QLine) -> bool;
/// Sets the starting point of this line to `p1`.
#[rust_name = "set_p1"]
fn setP1(self: &mut QLine, p1: &QPoint);
/// Sets the end point of this line to `p2`.
#[rust_name = "set_p2"]
fn setP2(self: &mut QLine, p1: &QPoint);
/// Sets this line to the start in `x1`, `y1` and end in `x2`, `y2`.
#[rust_name = "set_line"]
fn setLine(self: &mut QLine, x1: i32, y1: i32, x2: i32, y2: i32);
/// Sets the start point of this line to `p1` and the end point of this line to `p2`.
#[rust_name = "set_points"]
fn setPoints(self: &mut QLine, p1: &QPoint, p2: &QPoint);
/// Returns this line as a line with floating point accuracy.
///
/// This function was introduced in Qt 6.4.
#[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_4))]
#[rust_name = "to_linef"]
fn toLineF(self: &QLine) -> QLineF;
/// Translates this line by the given `offset`.
fn translate(self: &mut QLine, offset: &QPoint);
/// Returns this line translated by the given `offset`.
fn translated(self: &QLine, offset: &QPoint) -> QLine;
}
#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");
#[doc(hidden)]
#[rust_name = "qline_default"]
fn construct() -> QLine;
#[doc(hidden)]
#[rust_name = "qline_new"]
fn construct(pt1: &QPoint, pt2: &QPoint) -> QLine;
#[doc(hidden)]
#[rust_name = "qline_to_debug_qstring"]
fn toDebugQString(value: &QLine) -> QString;
}
}
/// The `QLine` class provides a two-dimensional vector using integer precision.
///
/// Qt Documentation: [QLine](https://doc.qt.io/qt/qline.html#details)
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct QLine {
pt1: QPoint,
pt2: QPoint,
}
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)
}
}
impl Default for QLine {
/// Constructs a null line.
fn default() -> Self {
ffi::qline_default()
}
}
impl fmt::Display for QLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
ffi::qline_to_debug_qstring(self).fmt(f)
}
}
// Safety:
//
// Static checks on the C++ side ensure that QLine is trivial.
unsafe impl ExternType for QLine {
type Id = type_id!("QLine");
type Kind = cxx::kind::Trivial;
}