Add helper function to avoid code duplication in wxQt wxTextCtrl
No real changes, just a refactoring to avoid duplicating the code handling wxTE_READONLY and the alignment styles between multi- and single-line versions. Also avoid testing for "style & wxTE_LEFT" as this will never be true anyhow. See https://github.com/wxWidgets/wxWidgets/pull/1211
This commit is contained in:
parent
c8cbdc783a
commit
7d2e6e805f
@ -51,6 +51,22 @@ public:
|
||||
namespace
|
||||
{
|
||||
|
||||
// Helper for SetStyleFlags(): takes care of flags that are handled in the same
|
||||
// way in both QLineEdit and QTextEdit.
|
||||
template <typename Edit>
|
||||
void ApplyCommonStyles(Edit* edit, long flags)
|
||||
{
|
||||
edit->setReadOnly(flags & wxTE_READONLY);
|
||||
|
||||
if ( flags & wxTE_CENTRE )
|
||||
edit->setAlignment(Qt::AlignHCenter);
|
||||
else if ( flags & wxTE_RIGHT )
|
||||
edit->setAlignment(Qt::AlignRight);
|
||||
else // wxTE_LEFT is 0, so can't test for it, just use it by default
|
||||
edit->setAlignment(Qt::AlignLeft);
|
||||
}
|
||||
|
||||
|
||||
struct wxQtLineInfo
|
||||
{
|
||||
wxQtLineInfo(size_t start, size_t end) :
|
||||
@ -251,22 +267,13 @@ public:
|
||||
|
||||
virtual void SetStyleFlags(long flags) wxOVERRIDE
|
||||
{
|
||||
m_edit->setReadOnly(flags & wxTE_READONLY);
|
||||
ApplyCommonStyles(m_edit, flags);
|
||||
|
||||
if ( flags & wxNO_BORDER )
|
||||
m_edit->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
if ( flags & wxTE_RICH || flags & wxTE_RICH2 )
|
||||
m_edit->setAcceptRichText(true);
|
||||
|
||||
if ( flags & wxTE_LEFT )
|
||||
m_edit->setAlignment(Qt::AlignLeft);
|
||||
|
||||
if ( flags & wxTE_CENTRE )
|
||||
m_edit->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
if ( flags & wxTE_RIGHT )
|
||||
m_edit->setAlignment(Qt::AlignRight);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -424,20 +431,12 @@ public:
|
||||
|
||||
virtual void SetStyleFlags(long flags) wxOVERRIDE
|
||||
{
|
||||
ApplyCommonStyles(m_edit, flags);
|
||||
|
||||
m_edit->setFrame(!(flags & wxNO_BORDER));
|
||||
m_edit->setReadOnly(flags & wxTE_READONLY);
|
||||
|
||||
if ( flags & wxTE_PASSWORD )
|
||||
m_edit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
if ( flags & wxTE_LEFT )
|
||||
m_edit->setAlignment(Qt::AlignLeft);
|
||||
|
||||
if ( flags & wxTE_CENTRE )
|
||||
m_edit->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
if ( flags & wxTE_RIGHT )
|
||||
m_edit->setAlignment(Qt::AlignRight);
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user