From c028f61d0f95334f333585b46a0b1a1ecbcb35bf Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 22:27:47 +0100 Subject: [PATCH 1/6] Default ctor should create uninitialised wxPen too in wxQt as documented --- src/qt/dc.cpp | 2 ++ src/qt/pen.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index 520cc64797..393548fcfd 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -178,6 +178,8 @@ void wxQtDCImpl::SetPen(const wxPen& pen) { m_pen = pen; + if ( !m_pen.IsOk() ) return; + m_qtPainter->setPen(pen.GetHandle()); ApplyRasterColourOp(); diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index 8e9052fce8..a2f930bae6 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -241,7 +241,6 @@ class wxPenRefData: public wxGDIRefData wxPen::wxPen() { - m_refData = new wxPenRefData(); } wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style) @@ -334,6 +333,8 @@ void wxPen::SetCap(wxPenCap cap) wxColour wxPen::GetColour() const { + wxCHECK_MSG( IsOk(), wxNullColour, "invalid pen" ); + wxColour c(M_PENDATA.color()); return c; } @@ -345,33 +346,43 @@ wxBitmap *wxPen::GetStipple() const wxPenStyle wxPen::GetStyle() const { + wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, "invalid pen" ); + return ConvertPenStyle(M_PENDATA.style()); } wxPenJoin wxPen::GetJoin() const { + wxCHECK_MSG( IsOk(), wxJOIN_INVALID, "invalid pen" ); + return ConvertPenJoinStyle(M_PENDATA.joinStyle()); } wxPenCap wxPen::GetCap() const { + wxCHECK_MSG( IsOk(), wxCAP_INVALID, "invalid pen" ); + return ConvertPenCapStyle(M_PENDATA.capStyle()); } int wxPen::GetWidth() const { + wxCHECK_MSG( IsOk(), -1, "invalid pen" ); + return M_PENDATA.width(); } int wxPen::GetDashes(wxDash **ptr) const { + wxCHECK_MSG( IsOk(), -1, "invalid pen" ); + *ptr = (wxDash *)((wxPenRefData *)m_refData)->m_dashes; return ((wxPenRefData *)m_refData)->m_dashesSize; } QPen wxPen::GetHandle() const { - return M_PENDATA; + return IsOk() ? M_PENDATA : QPen(); } wxGDIRefData *wxPen::CreateGDIRefData() const From a38774206d97d2af122a0bbbb9c2a7ede4a9a574 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 23:00:43 +0100 Subject: [PATCH 2/6] Added ctor taking a wxPenInfo to wxPen in wxQt --- include/wx/qt/pen.h | 2 ++ src/qt/pen.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/wx/qt/pen.h b/include/wx/qt/pen.h index 132003114f..89c2659734 100644 --- a/include/wx/qt/pen.h +++ b/include/wx/qt/pen.h @@ -17,6 +17,8 @@ public: wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID ); + wxPen( const wxPenInfo& info ); + wxDEPRECATED_MSG("use wxPENSTYLE_XXX constants") wxPen(const wxColour& col, int width, int style); diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index a2f930bae6..2695cbe2e0 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -225,9 +225,36 @@ class wxPenRefData: public wxGDIRefData defaultPen(); } + wxPenRefData(const wxPenInfo& info) + { + m_qtPen.setWidth(info.GetWidth()); + m_qtPen.setStyle(ConvertPenStyle(info.GetStyle())); + m_qtPen.setCapStyle(ConvertPenCapStyle(info.GetCap())); + m_qtPen.setJoinStyle(ConvertPenJoinStyle(info.GetJoin())); + m_qtPen.setColor(info.GetColour().GetQColor()); + + m_dashesSize = info.GetDashes(const_cast(&m_dashes)); + } + bool operator == (const wxPenRefData& data) const { - return m_qtPen == data.m_qtPen; + if ( m_dashesSize != data.m_dashesSize ) + return false; + + if ( m_dashes ) + { + if ( !data.m_dashes || + memcmp(m_dashes, data.m_dashes, m_dashesSize*sizeof(wxDash)) ) + { + return false; + } + } + else if ( data.m_dashes ) + { + return false; + } + + return m_qtPen == data.m_qtPen; } QPen m_qtPen; @@ -259,6 +286,10 @@ wxPen::wxPen(const wxColour& col, int width, int style) M_PENDATA.setColor(col.GetQColor()); } +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); +} bool wxPen::operator==(const wxPen& pen) const { From c7d51a93940090e4aef3e5d088de77a376abfef5 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 23:01:57 +0100 Subject: [PATCH 3/6] Fix code indentation for consistency --- src/qt/pen.cpp | 100 ++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index 2695cbe2e0..989057410a 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -204,62 +204,62 @@ static wxPenJoin ConvertPenJoinStyle(Qt::PenJoinStyle style) class wxPenRefData: public wxGDIRefData { - public: - void defaultPen() +public: + void defaultPen() + { + m_qtPen.setCapStyle(Qt::RoundCap); + m_qtPen.setJoinStyle(Qt::RoundJoin); + m_dashes = nullptr; + m_dashesSize = 0; + } + + wxPenRefData() + { + defaultPen(); + } + + wxPenRefData( const wxPenRefData& data ) + : wxGDIRefData() + , m_qtPen(data.m_qtPen) + { + defaultPen(); + } + + wxPenRefData(const wxPenInfo& info) + { + m_qtPen.setWidth(info.GetWidth()); + m_qtPen.setStyle(ConvertPenStyle(info.GetStyle())); + m_qtPen.setCapStyle(ConvertPenCapStyle(info.GetCap())); + m_qtPen.setJoinStyle(ConvertPenJoinStyle(info.GetJoin())); + m_qtPen.setColor(info.GetColour().GetQColor()); + + m_dashesSize = info.GetDashes(const_cast(&m_dashes)); + } + + bool operator == (const wxPenRefData& data) const + { + if ( m_dashesSize != data.m_dashesSize ) + return false; + + if ( m_dashes ) { - m_qtPen.setCapStyle(Qt::RoundCap); - m_qtPen.setJoinStyle(Qt::RoundJoin); - m_dashes = nullptr; - m_dashesSize = 0; - } - - wxPenRefData() - { - defaultPen(); - } - - wxPenRefData( const wxPenRefData& data ) - : wxGDIRefData() - , m_qtPen(data.m_qtPen) - { - defaultPen(); - } - - wxPenRefData(const wxPenInfo& info) - { - m_qtPen.setWidth(info.GetWidth()); - m_qtPen.setStyle(ConvertPenStyle(info.GetStyle())); - m_qtPen.setCapStyle(ConvertPenCapStyle(info.GetCap())); - m_qtPen.setJoinStyle(ConvertPenJoinStyle(info.GetJoin())); - m_qtPen.setColor(info.GetColour().GetQColor()); - - m_dashesSize = info.GetDashes(const_cast(&m_dashes)); - } - - bool operator == (const wxPenRefData& data) const - { - if ( m_dashesSize != data.m_dashesSize ) - return false; - - if ( m_dashes ) - { - if ( !data.m_dashes || - memcmp(m_dashes, data.m_dashes, m_dashesSize*sizeof(wxDash)) ) - { - return false; - } - } - else if ( data.m_dashes ) + if ( !data.m_dashes || + memcmp(m_dashes, data.m_dashes, m_dashesSize*sizeof(wxDash)) ) { return false; } - - return m_qtPen == data.m_qtPen; + } + else if ( data.m_dashes ) + { + return false; } - QPen m_qtPen; - const wxDash *m_dashes; - int m_dashesSize; + return m_qtPen == data.m_qtPen; + } + + QPen m_qtPen; + const wxDash *m_dashes; + int m_dashesSize; }; //----------------------------------------------------------------------------- From a248edaf6fbc5e9765cbc2717e16c9f2d52c42b9 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 23:07:40 +0100 Subject: [PATCH 4/6] Default ctor should create uninitialised wxBrush too in wxQt as documented --- src/qt/brush.cpp | 9 +++++++-- src/qt/dc.cpp | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 1e05a6ffd3..28c4122ddc 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -92,7 +92,6 @@ class wxBrushRefData: public wxGDIRefData wxBrush::wxBrush() { - m_refData = new wxBrushRefData(); } wxBrush::wxBrush(const wxColour& col, wxBrushStyle style ) @@ -165,16 +164,22 @@ bool wxBrush::operator==(const wxBrush& brush) const wxColour wxBrush::GetColour() const { + wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") ); + return wxColour(M_BRUSHDATA.color()); } wxBrushStyle wxBrush::GetStyle() const { + wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, "invalid brush" ); + return M_STYLEDATA; } wxBitmap *wxBrush::GetStipple() const { + wxCHECK_MSG( IsOk(), nullptr, "invalid brush" ); + QPixmap p = M_BRUSHDATA.texture(); if (p.isNull()) @@ -185,7 +190,7 @@ wxBitmap *wxBrush::GetStipple() const QBrush wxBrush::GetHandle() const { - return M_BRUSHDATA; + return IsOk() ? M_BRUSHDATA : QBrush(); } wxGDIRefData *wxBrush::CreateGDIRefData() const diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index 393548fcfd..21491af7f3 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -189,6 +189,8 @@ void wxQtDCImpl::SetBrush(const wxBrush& brush) { m_brush = brush; + if ( !m_brush.IsOk() ) return; + if (brush.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE) { // Use a monochrome mask: use foreground color for the mask From 662b04e67310c9f89a1c037b168eba9518fc9f85 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 23:08:17 +0100 Subject: [PATCH 5/6] Fix code indentation for consistency --- src/qt/brush.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 28c4122ddc..4c2d9d6dfd 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -61,28 +61,28 @@ static Qt::BrushStyle ConvertBrushStyle(wxBrushStyle style) class wxBrushRefData: public wxGDIRefData { - public: - wxBrushRefData() : - m_style(wxBRUSHSTYLE_INVALID) - { - } +public: + wxBrushRefData() : + m_style(wxBRUSHSTYLE_INVALID) + { + } - wxBrushRefData( const wxBrushRefData& data ) - : wxGDIRefData(), - m_qtBrush(data.m_qtBrush) - { - m_style = data.m_style; - } + wxBrushRefData( const wxBrushRefData& data ) + : wxGDIRefData(), + m_qtBrush(data.m_qtBrush) + { + m_style = data.m_style; + } - bool operator == (const wxBrushRefData& data) const - { - return m_qtBrush == data.m_qtBrush; - } + bool operator == (const wxBrushRefData& data) const + { + return m_qtBrush == data.m_qtBrush; + } - QBrush m_qtBrush; + QBrush m_qtBrush; - // To keep if mask is stippled - wxBrushStyle m_style; + // To keep if mask is stippled + wxBrushStyle m_style; }; //----------------------------------------------------------------------------- From 1bdcfd33e6f1e8de142cf14f0df842c1eeb948e2 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 23:32:35 +0100 Subject: [PATCH 6/6] Fix clearing the dc with invalid brush in wxQt --- src/qt/dc.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index 21491af7f3..50f4c350dc 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -223,7 +223,14 @@ void wxQtDCImpl::SetBackground(const wxBrush& brush) m_backgroundBrush = brush; if (m_qtPainter->isActive()) - m_qtPainter->setBackground(brush.GetHandle()); + { + // For consistency with the other ports: clearing the dc with + // invalid brush (Qt::NoBrush) should use white colour (which + // happens to be the default colour in Qt too) instead of no + // colour at all. + m_qtPainter->setBackground( + brush.IsOk() ? brush.GetHandle() : Qt::white); + } } void wxQtDCImpl::SetBackgroundMode(int mode)