Skip to content

Commit bc79a19

Browse files
authored
Merge branch 'main' into add_valgrind_info
2 parents c59282a + 7cdefb5 commit bc79a19

File tree

15 files changed

+198
-6
lines changed

15 files changed

+198
-6
lines changed

crates/cxx-qt-lib-headers/include/gui/qpainter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@
1010
#include <memory>
1111

1212
#include <QtGui/QPainter>
13+
14+
namespace rust {
15+
namespace cxxqtlib1 {
16+
using QPainterRenderHint = QPainter::RenderHint;
17+
18+
} // namespace cxxqtlib1
19+
} // namespace rust

crates/cxx-qt-lib/src/gui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ mod qpainterpath;
3737
pub use qpainterpath::QPainterPath;
3838

3939
mod qpainter;
40-
pub use qpainter::QPainter;
40+
pub use qpainter::{QPainter, QPainterRenderHint};

crates/cxx-qt-lib/src/gui/qfont.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ mod ffi {
262262
#[doc(hidden)]
263263
#[rust_name = "qfont_clone"]
264264
fn construct(font: &QFont) -> QFont;
265+
266+
#[doc(hidden)]
267+
#[rust_name = "qfont_eq"]
268+
fn operatorEq(a: &QFont, b: &QFont) -> bool;
265269
}
266270
}
267271

@@ -291,6 +295,14 @@ impl Clone for QFont {
291295
}
292296
}
293297

298+
impl PartialEq for QFont {
299+
fn eq(&self, other: &Self) -> bool {
300+
ffi::qfont_eq(self, other)
301+
}
302+
}
303+
304+
impl Eq for QFont {}
305+
294306
impl QFont {
295307
/// Returns the bounding rectangle of the current clip if there is a clip;
296308
/// otherwise returns `None`. Note that the clip region is given in logical coordinates.

crates/cxx-qt-lib/src/gui/qimage.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ mod ffi {
237237
#[doc(hidden)]
238238
#[rust_name = "qimage_cache_key"]
239239
fn qimageCacheKey(image: &QImage) -> i64;
240+
241+
#[doc(hidden)]
242+
#[rust_name = "qimage_eq"]
243+
fn operatorEq(a: &QImage, b: &QImage) -> bool;
240244
}
241245
}
242246

@@ -270,6 +274,14 @@ impl Default for QImage {
270274
}
271275
}
272276

277+
impl PartialEq for QImage {
278+
fn eq(&self, other: &Self) -> bool {
279+
ffi::qimage_eq(self, other)
280+
}
281+
}
282+
283+
impl Eq for QImage {}
284+
273285
// Safety:
274286
//
275287
// Static checks on the C++ side to ensure the size & alignment is the same.

crates/cxx-qt-lib/src/gui/qpainter.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ mod ffi {
1515
type SizeMode = crate::SizeMode;
1616
}
1717

18+
/// Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.
19+
#[repr(i32)]
20+
#[namespace = "rust::cxxqtlib1"]
21+
#[derive(Debug)]
22+
enum QPainterRenderHint {
23+
/// Indicates that the engine should antialias edges of primitives if possible.
24+
Antialiasing = 0x01,
25+
/// Indicates that the engine should antialias text if possible.
26+
/// To forcibly disable antialiasing for text, do not use this hint.
27+
/// Instead, set QFont::NoAntialias on your font's style strategy.
28+
TextAntialiasing = 0x02,
29+
/// Indicates that the engine should use a smooth pixmap transformation algorithm
30+
/// (such as bilinear) rather than nearest neighbor.
31+
SmoothPixmapTransform = 0x04,
32+
/// Use a lossless image rendering, whenever possible. Currently, this hint is only
33+
/// used when QPainter is employed to output a PDF file through QPrinter or QPdfWriter,
34+
/// where drawImage()/drawPixmap() calls will encode images using a lossless compression
35+
/// algorithm instead of lossy JPEG compression. This value was added in Qt 5.13.
36+
LosslessImageRendering = 0x40,
37+
}
38+
1839
unsafe extern "C++" {
1940
include!("cxx-qt-lib/qpainter.h");
2041
type QPainter;
@@ -197,15 +218,19 @@ mod ffi {
197218
#[rust_name = "set_layout_direction"]
198219
fn setLayoutDirection(self: Pin<&mut QPainter>, direction: LayoutDirection);
199220

200-
/// Sets the painter's pen to be the given pen.
201-
#[rust_name = "set_pen"]
202-
fn setPen(self: Pin<&mut QPainter>, pen: &QPen);
203-
204221
/// Sets the opacity of the painter to opacity. The value should be in the range 0.0 to 1.0,
205222
/// where 0.0 is fully transparent and 1.0 is fully opaque.
206223
#[rust_name = "set_opacity"]
207224
fn setOpacity(self: Pin<&mut QPainter>, opacity: f64);
208225

226+
/// Sets the painter's pen to be the given pen.
227+
#[rust_name = "set_pen"]
228+
fn setPen(self: Pin<&mut QPainter>, pen: &QPen);
229+
230+
/// Sets the given render hint on the painter if on is true; otherwise clears the render hint.
231+
#[rust_name = "set_render_hint"]
232+
fn setRenderHint(self: Pin<&mut QPainter>, hint: QPainterRenderHint, on: bool);
233+
209234
/// Sets the painter's viewport rectangle to the given rectangle, and enables view transformations.
210235
#[rust_name = "set_viewport"]
211236
fn setViewport(self: Pin<&mut QPainter>, rectangle: &QRect);
@@ -218,6 +243,10 @@ mod ffi {
218243
#[rust_name = "stroke_path"]
219244
fn strokePath(self: Pin<&mut QPainter>, path: &QPainterPath, pen: &QPen);
220245

246+
/// Returns true if hint is set; otherwise returns false.
247+
#[rust_name = "test_render_hint"]
248+
fn testRenderHint(self: &QPainter, hint: QPainterRenderHint) -> bool;
249+
221250
/// Restores the current painter state (pops a saved state off the stack).
222251
fn restore(self: Pin<&mut QPainter>);
223252

@@ -239,13 +268,15 @@ mod ffi {
239268
unsafe extern "C++" {
240269
include!("cxx-qt-lib/common.h");
241270

271+
type QPainterRenderHint;
272+
242273
#[doc(hidden)]
243274
#[rust_name = "qpainter_init_default"]
244275
fn make_unique() -> UniquePtr<QPainter>;
245276
}
246277
}
247278

248-
pub use ffi::QPainter;
279+
pub use ffi::{QPainter, QPainterRenderHint};
249280

250281
impl QPainter {
251282
/// Create a QPainter

crates/cxx-qt-lib/src/gui/qpainterpath.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ mod ffi {
188188
#[doc(hidden)]
189189
#[rust_name = "qpainterpath_drop"]
190190
fn drop(painterPath: &mut QPainterPath);
191+
192+
#[doc(hidden)]
193+
#[rust_name = "qpainterpath_eq"]
194+
fn operatorEq(a: &QPainterPath, b: &QPainterPath) -> bool;
191195
}
192196
}
193197

@@ -222,6 +226,14 @@ impl From<&QPointF> for QPainterPath {
222226
}
223227
}
224228

229+
impl PartialEq for QPainterPath {
230+
fn eq(&self, other: &Self) -> bool {
231+
ffi::qpainterpath_eq(self, other)
232+
}
233+
}
234+
235+
impl Eq for QPainterPath {}
236+
225237
// Safety:
226238
//
227239
// Static checks on the C++ side to ensure the size is the same.

crates/cxx-qt-lib/src/gui/qpen.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ mod ffi {
113113
#[doc(hidden)]
114114
#[rust_name = "qpen_clone"]
115115
fn construct(pen: &QPen) -> QPen;
116+
117+
#[doc(hidden)]
118+
#[rust_name = "qpen_eq"]
119+
fn operatorEq(a: &QPen, b: &QPen) -> bool;
116120
}
117121
}
118122

@@ -143,6 +147,14 @@ impl Clone for QPen {
143147
}
144148
}
145149

150+
impl PartialEq for QPen {
151+
fn eq(&self, other: &Self) -> bool {
152+
ffi::qpen_eq(self, other)
153+
}
154+
}
155+
156+
impl Eq for QPen {}
157+
146158
impl From<&ffi::QColor> for QPen {
147159
fn from(color: &ffi::QColor) -> Self {
148160
ffi::qpen_init_from_qcolor(color)

crates/cxx-qt-lib/src/gui/qpolygon.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileContributor: Laurent Montel <[email protected]>
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
use crate::QRect;
56
use core::mem::MaybeUninit;
67
use cxx::{type_id, ExternType};
78

@@ -65,13 +66,21 @@ mod ffi {
6566
#[rust_name = "qpolygon_init_default"]
6667
fn construct() -> QPolygon;
6768

69+
#[doc(hidden)]
70+
#[rust_name = "qpolygon_init_qrect"]
71+
fn construct(rect: &QRect, closed: bool) -> QPolygon;
72+
6873
#[doc(hidden)]
6974
#[rust_name = "qpolygon_drop"]
7075
fn drop(pen: &mut QPolygon);
7176

7277
#[doc(hidden)]
7378
#[rust_name = "qpolygon_clone"]
7479
fn construct(p: &QPolygon) -> QPolygon;
80+
81+
#[doc(hidden)]
82+
#[rust_name = "qpolygon_eq"]
83+
fn operatorEq(a: &QPolygon, b: &QPolygon) -> bool;
7584
}
7685
}
7786

@@ -107,6 +116,23 @@ impl Clone for QPolygon {
107116
}
108117
}
109118

119+
impl QPolygon {
120+
/// Constructs a polygon from the given rectangle. If closed is false, the polygon
121+
/// just contains the four points of the rectangle ordered clockwise, otherwise the
122+
/// polygon's fifth point is set to rectangle.topLeft().
123+
pub fn new(rect: &QRect, closed: bool) -> Self {
124+
ffi::qpolygon_init_qrect(rect, closed)
125+
}
126+
}
127+
128+
impl PartialEq for QPolygon {
129+
fn eq(&self, other: &Self) -> bool {
130+
ffi::qpolygon_eq(self, other)
131+
}
132+
}
133+
134+
impl Eq for QPolygon {}
135+
110136
// Safety:
111137
//
112138
// Static checks on the C++ side to ensure the size is the same.

crates/cxx-qt-lib/src/gui/qpolygonf.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ mod ffi {
7575
#[doc(hidden)]
7676
#[rust_name = "qpolygonf_clone"]
7777
fn construct(p: &QPolygonF) -> QPolygonF;
78+
79+
#[doc(hidden)]
80+
#[rust_name = "qpolygonf_eq"]
81+
fn operatorEq(a: &QPolygonF, b: &QPolygonF) -> bool;
7882
}
7983
}
8084

@@ -110,6 +114,14 @@ impl Clone for QPolygonF {
110114
}
111115
}
112116

117+
impl PartialEq for QPolygonF {
118+
fn eq(&self, other: &Self) -> bool {
119+
ffi::qpolygonf_eq(self, other)
120+
}
121+
}
122+
123+
impl Eq for QPolygonF {}
124+
113125
// Safety:
114126
//
115127
// Static checks on the C++ side to ensure the size is the same.

tests/qt_types_standalone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ add_executable(${APP_NAME}
6666
cpp/qpersistentmodelindex.h
6767
cpp/qpoint.h
6868
cpp/qpointf.h
69+
cpp/qpolygon.h
6970
cpp/qqmlapplicationengine.h
7071
cpp/qqmlengine.h
7172
cpp/qrect.h

tests/qt_types_standalone/cpp/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qpersistentmodelindex.h"
2626
#include "qpoint.h"
2727
#include "qpointf.h"
28+
#include "qpolygon.h"
2829
#include "qqmlapplicationengine.h"
2930
#include "qqmlengine.h"
3031
#include "qrect.h"
@@ -90,6 +91,7 @@ main(int argc, char* argv[])
9091
runTest(QScopedPointer<QObject>(new QVector2DTest));
9192
runTest(QScopedPointer<QObject>(new QVector3DTest));
9293
runTest(QScopedPointer<QObject>(new QVector4DTest));
94+
runTest(QScopedPointer<QObject>(new QPolygonTest));
9395

9496
return status;
9597
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// clang-format off
2+
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3+
// clang-format on
4+
// SPDX-FileContributor: Laurent Montel <[email protected]>
5+
//
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
#pragma once
8+
9+
#include <QtGui/QPolygon>
10+
#include <QtTest/QTest>
11+
12+
#include "cxx-qt-gen/qpolygon.cxx.h"
13+
14+
class QPolygonTest : public QObject
15+
{
16+
Q_OBJECT
17+
18+
private Q_SLOTS:
19+
void construct()
20+
{
21+
const auto m = construct_qpolygon();
22+
QVERIFY(m.isEmpty());
23+
}
24+
void clone()
25+
{
26+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
27+
const auto m = QPolygon(QList<QPoint>() << QPoint(1, 2) << QPoint(3, 4));
28+
#else
29+
const auto m = QPolygon(QVector<QPoint>() << QPoint(1, 2) << QPoint(3, 4));
30+
#endif
31+
const auto c = clone_qpolygon(m);
32+
QCOMPARE(c.point(0), QPoint(1, 2));
33+
QCOMPARE(c.point(1), QPoint(3, 4));
34+
}
35+
};

tests/qt_types_standalone/rust/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn main() {
2525
.file("src/qpersistentmodelindex.rs")
2626
.file("src/qpoint.rs")
2727
.file("src/qpointf.rs")
28+
.file("src/qpolygon.rs")
2829
.file("src/qqmlapplicationengine.rs")
2930
.file("src/qqmlengine.rs")
3031
.file("src/qrect.rs")

tests/qt_types_standalone/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod qmodelindex;
2222
mod qpersistentmodelindex;
2323
mod qpoint;
2424
mod qpointf;
25+
mod qpolygon;
2526
mod qqmlapplicationengine;
2627
mod qqmlengine;
2728
mod qrect;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Laurent Montel <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
use cxx_qt_lib::QPolygon;
7+
8+
#[cxx::bridge]
9+
mod qpolygon_cxx {
10+
unsafe extern "C++" {
11+
include!("cxx-qt-lib/qpolygon.h");
12+
13+
type QPolygon = cxx_qt_lib::QPolygon;
14+
}
15+
16+
extern "Rust" {
17+
fn clone_qpolygon(p: &QPolygon) -> QPolygon;
18+
fn construct_qpolygon() -> QPolygon;
19+
}
20+
}
21+
22+
fn construct_qpolygon() -> QPolygon {
23+
QPolygon::default()
24+
}
25+
26+
fn clone_qpolygon(p: &QPolygon) -> QPolygon {
27+
p.clone()
28+
}

0 commit comments

Comments
 (0)