Make wxQt wxPen and wxBrush classes behave more consistently with the
other ports.

See #23863.
This commit is contained in:
Vadim Zeitlin 2023-09-10 17:35:42 +02:00
commit eb8a57760e
4 changed files with 108 additions and 48 deletions

View file

@ -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);

View file

@ -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;
};
//-----------------------------------------------------------------------------
@ -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

View file

@ -178,6 +178,8 @@ void wxQtDCImpl::SetPen(const wxPen& pen)
{
m_pen = pen;
if ( !m_pen.IsOk() ) return;
m_qtPainter->setPen(pen.GetHandle());
ApplyRasterColourOp();
@ -187,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
@ -219,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)

View file

@ -204,35 +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<wxDash**>(&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;
if ( !data.m_dashes ||
memcmp(m_dashes, data.m_dashes, m_dashesSize*sizeof(wxDash)) )
{
return false;
}
}
else if ( data.m_dashes )
{
return false;
}
wxPenRefData()
{
defaultPen();
}
return m_qtPen == data.m_qtPen;
}
wxPenRefData( const wxPenRefData& data )
: wxGDIRefData()
, m_qtPen(data.m_qtPen)
{
defaultPen();
}
bool operator == (const wxPenRefData& data) const
{
return m_qtPen == data.m_qtPen;
}
QPen m_qtPen;
const wxDash *m_dashes;
int m_dashesSize;
QPen m_qtPen;
const wxDash *m_dashes;
int m_dashesSize;
};
//-----------------------------------------------------------------------------
@ -241,7 +268,6 @@ class wxPenRefData: public wxGDIRefData
wxPen::wxPen()
{
m_refData = new wxPenRefData();
}
wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style)
@ -260,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
{
@ -334,6 +364,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 +377,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