diff --git a/src/qt/textctrl.cpp b/src/qt/textctrl.cpp index a9249fe3f8..56c2c2974b 100644 --- a/src/qt/textctrl.cpp +++ b/src/qt/textctrl.cpp @@ -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 +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: