Skip to content

Commit 166fc07

Browse files
committed
Improve QImage support
1 parent 15c584d commit 166fc07

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ QImage
2929
qimageInitFromData(const rust::Slice<std::uint8_t const> data,
3030
rust::Str format);
3131

32+
::std::int64_t
33+
qimageCacheKey(const QImage& image);
34+
3235
} // namespace cxxqtlib1
3336
} // namespace rust
3437
#endif

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ qimageInitFromData(const rust::Slice<std::uint8_t const> data, rust::Str format)
4545
formatString.empty() ? nullptr : formatString.data());
4646
}
4747

48+
::std::int64_t
49+
qimageCacheKey(const QImage& image)
50+
{
51+
return static_cast<::std::int64_t>(image.cacheKey());
52+
}
4853
}
4954
}
5055

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,100 @@ mod ffi {
1111
unsafe extern "C++" {
1212
include!("cxx-qt-lib/qimage.h");
1313
type QImage = super::QImage;
14+
include!("cxx-qt-lib/qsize.h");
15+
type QSize = crate::QSize;
16+
include!("cxx-qt-lib/qrect.h");
17+
type QRect = crate::QRect;
18+
include!("cxx-qt-lib/qcolor.h");
19+
type QColor = crate::QColor;
20+
include!("cxx-qt-lib/qpoint.h");
21+
type QPoint = crate::QPoint;
1422

1523
/// Whether the QImage is null.
1624
///
1725
/// This means that the QImage has all parameters set to zero and no allocated data.
1826
#[rust_name = "is_null"]
1927
fn isNull(self: &QImage) -> bool;
28+
29+
/// Returns true if all the colors in the image are shades of gray
30+
#[rust_name = "all_gray"]
31+
fn allGray(self: &QImage) -> bool;
32+
33+
/// For 32-bit images, this function is equivalent to allGray().
34+
/// For color indexed images, this function returns true if color(i) is QRgb(i, i, i)
35+
/// for all indexes of the color table; otherwise returns false.
36+
#[rust_name = "is_gray_scale"]
37+
fn isGrayscale(self: &QImage) -> bool;
38+
39+
/// Returns true if the image has a format that respects the alpha channel, otherwise returns false.
40+
#[rust_name = "has_alpha_channel"]
41+
fn hasAlphaChannel(self: &QImage) -> bool;
42+
43+
/// Returns a sub-area of the image as a new image.
44+
fn copy(self: &QImage, rect: &QRect) -> QImage;
45+
46+
/// Returns the size of the color table for the image.
47+
#[rust_name = "color_count"]
48+
fn colorCount(self: &QImage) -> i32;
49+
50+
/// Resizes the color table to contain colorCount entries.
51+
#[rust_name = "set_color_count"]
52+
fn setColorCount(self: &mut QImage, colorCount: i32);
53+
54+
/// Returns the depth of the image.
55+
fn depth(self: &QImage) -> i32;
56+
57+
/// Fills the entire image with the given color.
58+
fn fill(self: &mut QImage, color: &QColor);
59+
60+
/// Returns the height of the image.
61+
fn height(self: &QImage) -> i32;
62+
63+
/// Returns the width of the image.
64+
fn width(self: &QImage) -> i32;
65+
66+
/// Returns the size of the image.
67+
fn size(self: &QImage) -> QSize;
68+
69+
/// Returns the enclosing rectangle (0, 0, width(), height()) of the image.
70+
fn rect(self: &QImage) -> QRect;
71+
72+
/// Returns the color of the pixel at coordinates (x, y) as a QColor.
73+
#[rust_name = "pixel_color"]
74+
fn pixelColor(self: &QImage, x: i32, y: i32) -> QColor;
75+
76+
/// Sets the pixel color at (x, y) to color.
77+
#[rust_name = "set_pixel_color"]
78+
fn setPixelColor(self: &mut QImage, x: i32, y: i32, color: &QColor);
79+
80+
/// Returns the number of pixels that fit horizontally in a physical meter.
81+
#[rust_name = "dots_per_meterx"]
82+
fn dotsPerMeterX(self: &QImage) -> i32;
83+
84+
/// Returns the number of pixels that fit vertically in a physical meter.
85+
#[rust_name = "dots_per_metery"]
86+
fn dotsPerMeterY(self: &QImage) -> i32;
87+
88+
/// Returns true if pos is a valid coordinate pair within the image.
89+
fn valid(self: &QImage, x: i32, y: i32) -> bool;
90+
91+
/// Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
92+
fn offset(self: &QImage) -> QPoint;
93+
94+
/// Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset.
95+
#[rust_name = "set_offset"]
96+
fn setOffset(self: &mut QImage, point: &QPoint);
97+
98+
/// Returns the pixel index at (x, y).
99+
#[rust_name = "pixel_index"]
100+
fn pixelIndex(self: &QImage, x: i32, y: i32) -> i32;
101+
102+
/// Mirrors of the image in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false.
103+
fn mirror(self: &mut QImage, horizontal: bool, vertical: bool);
104+
105+
/// Sets the alpha channel of this image to the given alphaChannel.
106+
#[rust_name = "set_alpha_channel"]
107+
fn setAlphaChannel(self: &mut QImage, alphaChannel: &QImage);
20108
}
21109

22110
#[namespace = "rust::cxxqtlib1"]
@@ -30,6 +118,10 @@ mod ffi {
30118
#[doc(hidden)]
31119
#[rust_name = "qimage_init_from_data"]
32120
fn qimageInitFromData(data: &[u8], format: &str) -> QImage;
121+
122+
#[doc(hidden)]
123+
#[rust_name = "qimage_cache_key"]
124+
fn qimageCacheKey(image: &QImage) -> i64;
33125
}
34126
}
35127

@@ -79,4 +171,8 @@ impl QImage {
79171
None
80172
}
81173
}
174+
/// Returns a number that identifies the contents of this QImage object.
175+
pub fn cache_key(&self) -> i64 {
176+
ffi::qimage_cache_key(self)
177+
}
82178
}

0 commit comments

Comments
 (0)