#![allow(dead_code)]
use cpp::{cpp, cpp_class};
cpp! {{
#include <QtGui/QImage>
}}
cpp_class!(
pub unsafe struct QImage as "QImage"
);
impl QImage {
pub fn data(&self) -> &[u8] {
unsafe {
let len = cpp!([self as "const QImage*"] -> usize as "std::size_t" { return self->sizeInBytes(); });
let data = cpp!([self as "const QImage*"] -> *const u8 as "const unsigned char*" { return self->bits(); });
return core::slice::from_raw_parts(data, len);
}
}
pub fn size(&self) -> QSize {
cpp!(unsafe [self as "const QImage*"] -> QSize as "QSize" { return self->size(); })
}
}
cpp_class!(
#[derive(PartialEq, PartialOrd, Eq, Ord)]
pub unsafe struct QString as "QString"
);
impl QString {
pub fn to_slice(&self) -> &[u16] {
unsafe {
let mut size: usize = 0;
let c_ptr = cpp!([self as "const QString*", mut size as "size_t"] -> *const u16 as "const QChar*" {
size = self->size();
return self->constData();
});
std::slice::from_raw_parts(c_ptr, size)
}
}
}
impl<'a> From<&'a str> for QString {
fn from(s: &'a str) -> QString {
let len = s.len();
let ptr = s.as_ptr();
cpp!(unsafe [len as "size_t", ptr as "char*"] -> QString as "QString" {
return QString::fromUtf8(ptr, len);
})
}
}
impl From<String> for QString {
fn from(s: String) -> QString {
QString::from(&*s)
}
}
impl Into<String> for QString {
fn into(self) -> String {
String::from_utf16_lossy(self.to_slice())
}
}
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Debug)]
pub struct QSize {
pub width: u32,
pub height: u32,
}
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Debug)]
pub struct QPoint {
pub x: i32,
pub y: i32,
}
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Debug)]
pub struct QMargins {
pub left: i32,
pub top: i32,
pub right: i32,
pub bottom: i32,
}
#[allow(non_camel_case_types)]
pub type qreal = f64;
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Debug)]
pub struct QRectF {
pub x: qreal,
pub y: qreal,
pub width: qreal,
pub height: qreal,
}