6#include "QskTextEdit.h"
7#include "QskInternalMacros.h"
11#include <private/qquicktextedit_p.h>
12#include <private/qquicktextedit_p_p.h>
33 class QuickTextEdit final :
public QQuickTextEdit
37 using Inherited = QQuickTextEdit;
42 inline void setAlignment( Qt::Alignment alignment )
44 setHAlign( ( HAlignment ) (
int( alignment ) & 0x0f ) );
45 setVAlign( ( VAlignment ) (
int( alignment ) & 0xf0 ) );
48 Q_INVOKABLE
void updateColors();
49 Q_INVOKABLE
void updateMetrics();
50 Q_INVOKABLE
void setEditing(
bool );
51 Q_INVOKABLE
void handleEvent( QEvent* ev ) { event( ev ); }
55#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
57 const QRectF& newGeometry,
const QRectF& oldGeometry )
override
59 Inherited::geometryChange( newGeometry, oldGeometry );
64 const QRectF& newGeometry,
const QRectF& oldGeometry )
override
66 Inherited::geometryChanged( newGeometry, oldGeometry );
73 setClip( ( contentWidth() > width() ) ||
74 ( contentHeight() > height() ) );
77 QSGNode* updatePaintNode(
78 QSGNode* oldNode, UpdatePaintNodeData* data )
override
81 return Inherited::updatePaintNode( oldNode, data );
85 QuickTextEdit::QuickTextEdit(
QskTextEdit* textField )
86 : QQuickTextEdit( textField )
90 setActiveFocusOnTab(
false );
91 setFlag( ItemAcceptsInputMethod,
false );
92 setFocusOnPress(
false );
93 setSelectByMouse(
true );
97 connect(
this, &QuickTextEdit::contentSizeChanged,
98 this, &QuickTextEdit::updateClip );
101 void QuickTextEdit::setEditing(
bool on )
103 Q_ASSERT( focusOnPress() ==
false );
105 QFocusEvent event( on ? QEvent::FocusIn : QEvent::FocusOut );
106 QQuickTextEditPrivate::get(
this )->handleFocusEvent( &event );
109 void QuickTextEdit::updateMetrics()
111 auto textEdit =
static_cast< const QskTextEdit*
>( parentItem() );
113 setAlignment( textEdit->alignment() );
114 setFont( textEdit->font() );
117 void QuickTextEdit::updateColors()
121 auto input =
static_cast< const Q*
>( parentItem() );
123 setColor( input->color( Q::Text ) );
125 const auto state = QskTextEdit::Selected;
127 setSelectionColor( input->color( Q::TextPanel | state ) );
128 setSelectedTextColor( input->color( Q::Text | state ) );
132class QskTextEdit::PrivateData
135 QuickTextEdit* wrappedEdit;
138QskTextEdit::QskTextEdit( QQuickItem* parent )
139 : Inherited( parent )
140 , m_data( new PrivateData() )
142 m_data->wrappedEdit =
new QuickTextEdit(
this );
143 auto wrappedEdit = m_data->wrappedEdit;
145 setAcceptedMouseButtons( wrappedEdit->acceptedMouseButtons() );
146 wrappedEdit->setAcceptedMouseButtons( Qt::NoButton );
148 initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Expanding );
150 setup( wrappedEdit );
152 connect( wrappedEdit, &QQuickTextEdit::lineCountChanged,
153 this, [
this]() { Q_EMIT lineCountChanged( lineCount() ); } );
155 connect( wrappedEdit, &QQuickTextEdit::linkActivated,
156 this, &QskTextEdit::linkActivated );
158 connect( wrappedEdit, &QQuickTextEdit::linkHovered,
159 this, &QskTextEdit::linkHovered );
161 connect( wrappedEdit, &QQuickTextEdit::linkActivated,
162 this, &QskTextEdit::linkActivated );
165QskTextEdit::~QskTextEdit()
172 if ( subControl == Inherited::Text )
175 if ( subControl == Inherited::TextPanel )
178 return Inherited::substitutedSubcontrol( subControl );
181QUrl QskTextEdit::baseUrl()
const
183 return m_data->wrappedEdit->baseUrl();
186void QskTextEdit::setBaseUrl(
const QUrl& url )
188 if ( url != m_data->wrappedEdit->baseUrl() )
190 m_data->wrappedEdit->setBaseUrl( url );
191 Q_EMIT baseUrlChanged( url );
195void QskTextEdit::resetBaseUrl()
197 m_data->wrappedEdit->resetBaseUrl();
200void QskTextEdit::setTextFormat( QskTextOptions::TextFormat format )
202 if ( format != textFormat() )
204 m_data->wrappedEdit->setTextFormat(
205 static_cast< QQuickTextEdit::TextFormat
>( format ) );
207 Q_EMIT textFormatChanged( format );
211QskTextOptions::TextFormat QskTextEdit::textFormat()
const
213 return static_cast< QskTextOptions::TextFormat
>(
214 m_data->wrappedEdit->textFormat() );
217int QskTextEdit::lineCount()
const
219 return m_data->wrappedEdit->lineCount();
222int QskTextEdit::tabStopDistance()
const
224 return m_data->wrappedEdit->tabStopDistance();
227void QskTextEdit::setTabStopDistance( qreal distance )
230 m_data->wrappedEdit->setTabStopDistance( distance );
233#include "QskTextEdit.moc"
234#include "moc_QskTextEdit.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.