Skip to content

Commit 9193d6d

Browse files
committed
fix(qt): no accent in old version
1 parent 90d4f71 commit 9193d6d

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/ui/qt/canvas.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ void painter_draw_text(QPainter &p, QRectF rect, rust::Str text) {
9393

9494
void color_transparent(QColor &c) { new (&c) QColor{Qt::transparent}; }
9595

96-
void color_accent(QColor &c) {
96+
bool color_accent(QColor &c) {
97+
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
9798
auto accent = QApplication::palette().color(QPalette::Accent);
9899
new (&c) QColor{accent};
100+
return true;
101+
#else
102+
return false;
103+
#endif
99104
}
100105

101106
std::unique_ptr<QBrush> new_brush(QColor const &c) {

src/ui/qt/canvas.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QSizeF painter_measure_text(QPainter &p, QRectF rect, rust::Str text);
5151
void painter_draw_text(QPainter &p, QRectF rect, rust::Str text);
5252

5353
void color_transparent(QColor &c);
54-
void color_accent(QColor &c);
54+
bool color_accent(QColor &c);
5555
std::unique_ptr<QBrush> new_brush(QColor const &c);
5656
std::unique_ptr<QPen> new_pen(QBrush const &b, double width);
5757

src/ui/qt/canvas.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl DrawingImage {
470470

471471
/// Get the accent color.
472472
pub fn accent_color() -> Option<Color> {
473-
Some(QColor::accent().into())
473+
QColor::accent().map(From::from)
474474
}
475475

476476
#[repr(i32)]
@@ -570,13 +570,16 @@ impl QColor {
570570
c
571571
}
572572

573-
pub fn accent() -> Self {
573+
pub fn accent() -> Option<Self> {
574574
let mut c = Self {
575575
cspec: Spec::Invalid,
576576
ct: [0; 5],
577577
};
578-
ffi::color_accent(Pin::new(&mut c));
579-
c
578+
if ffi::color_accent(Pin::new(&mut c)) {
579+
Some(c)
580+
} else {
581+
None
582+
}
580583
}
581584
}
582585

@@ -709,7 +712,7 @@ mod ffi {
709712
fn setPen(self: Pin<&mut QPainter>, color: &QColor);
710713

711714
fn color_transparent(c: Pin<&mut QColor>);
712-
fn color_accent(c: Pin<&mut QColor>);
715+
fn color_accent(c: Pin<&mut QColor>) -> bool;
713716
fn new_brush(c: &QColor) -> UniquePtr<QBrush>;
714717
fn new_pen(b: &QBrush, width: f64) -> UniquePtr<QPen>;
715718

0 commit comments

Comments
 (0)