📄 render_form.cpp
字号:
} else if (m_replace->options() & KFindDialog::FindBackwards) { m_repPara = paragraphs() - 1; m_repIndex = paragraphLength(m_repPara) - 1; } else { m_repPara = 0; m_repIndex = 0; } // Connect highlight signal to code which handles highlighting // of found text. connect(m_replace, SIGNAL(highlight(const QString &, int, int)), this, SLOT(slotFindHighlight(const QString &, int, int))); connect(m_replace, SIGNAL(findNext()), this, SLOT(slotReplaceNext())); connect(m_replace, SIGNAL(replace(const QString &, int, int, int)), this, SLOT(slotReplaceText(const QString &, int, int, int))); m_repDlg->close(); slotReplaceNext();#endif // KHTML_NO_SPELLING}void TextAreaWidget::slotReplaceNext(){#ifndef KHTML_NO_SPELLING if (!m_replace) { // assert? return; } if (!(m_replace->options() & KReplaceDialog::PromptOnReplace)) { viewport()->setUpdatesEnabled(false); } KFind::Result res = KFind::NoMatch; while (res == KFind::NoMatch) { // If we're done..... if (m_replace->options() & KFindDialog::FindBackwards) { if (m_repIndex == 0 && m_repPara == 0) { break; } } else { if (m_repPara == paragraphs() - 1 && m_repIndex == paragraphLength(m_repPara) - 1) { break; } } if (m_replace->needData()) { m_replace->setData(text(m_repPara), m_repIndex); } res = m_replace->replace(); if (res == KFind::NoMatch) { if (m_replace->options() & KFindDialog::FindBackwards) { if (m_repPara == 0) { m_repIndex = 0; } else { m_repPara--; m_repIndex = paragraphLength(m_repPara) - 1; } } else { if (m_repPara == paragraphs() - 1) { m_repIndex = paragraphLength(m_repPara) - 1; } else { m_repPara++; m_repIndex = 0; } } } } if (!(m_replace->options() & KReplaceDialog::PromptOnReplace)) { viewport()->setUpdatesEnabled(true); repaintChanged(); } if (res == KFind::NoMatch) { // at end m_replace->displayFinalDialog(); delete m_replace; m_replace = 0; ensureCursorVisible(); //or if ( m_replace->shouldRestart() ) { reinit (w/o FromCursor) and call slotReplaceNext(); } } else { //m_replace->closeReplaceNextDialog(); }#endif // KHTML_NO_SPELLING}void TextAreaWidget::slotDoFind(){#ifndef KHTML_NO_SPELLING if (!m_findDlg) { // Should really assert() return; } delete m_find; m_find = new KFind(m_findDlg->pattern(), m_findDlg->options(), this); if (m_find->options() & KFindDialog::FromCursor) { getCursorPosition(&m_findPara, &m_findIndex); } else if (m_find->options() & KFindDialog::FindBackwards) { m_findPara = paragraphs() - 1; m_findIndex = paragraphLength(m_findPara) - 1; } else { m_findPara = 0; m_findIndex = 0; } // Connect highlight signal to code which handles highlighting // of found text. connect(m_find, SIGNAL(highlight(const QString &, int, int)), this, SLOT(slotFindHighlight(const QString &, int, int))); connect(m_find, SIGNAL(findNext()), this, SLOT(slotFindNext())); m_findDlg->close(); m_find->closeFindNextDialog(); slotFindNext();#endif // KHTML_NO_SPELLING}void TextAreaWidget::slotFindNext(){#ifndef KHTML_NO_SPELLING if (!m_find) { // assert? return; } KFind::Result res = KFind::NoMatch; while (res == KFind::NoMatch) { // If we're done..... if (m_find->options() & KFindDialog::FindBackwards) { if (m_findIndex == 0 && m_findPara == 0) { break; } } else { if (m_findPara == paragraphs() - 1 && m_findIndex == paragraphLength(m_findPara) - 1) { break; } } if (m_find->needData()) { m_find->setData(text(m_findPara), m_findIndex); } res = m_find->find(); if (res == KFind::NoMatch) { if (m_find->options() & KFindDialog::FindBackwards) { if (m_findPara == 0) { m_findIndex = 0; } else { m_findPara--; m_findIndex = paragraphLength(m_findPara) - 1; } } else { if (m_findPara == paragraphs() - 1) { m_findIndex = paragraphLength(m_findPara) - 1; } else { m_findPara++; m_findIndex = 0; } } } } if (res == KFind::NoMatch) { // at end m_find->displayFinalDialog(); delete m_find; m_find = 0; //or if ( m_find->shouldRestart() ) { reinit (w/o FromCursor) and call slotFindNext(); } } else { //m_find->closeFindNextDialog(); }#endif // KHTML_NO_SPELLING}void TextAreaWidget::slotFind(){#ifndef KHTML_NO_SPELLING if( text().isEmpty() ) // saves having to track the text changes return; if ( m_findDlg ) { KWin::activateWindow( m_findDlg->winId() ); } else { m_findDlg = new KFindDialog(false, this, "KHTML Text Area Find Dialog"); connect( m_findDlg, SIGNAL(okClicked()), this, SLOT(slotDoFind()) ); } m_findDlg->show();#endif // KHTML_NO_SPELLING}void TextAreaWidget::slotReplace(){#ifndef KHTML_NO_SPELLING if( text().isEmpty() ) // saves having to track the text changes return; if ( m_repDlg ) { KWin::activateWindow( m_repDlg->winId() ); } else { m_repDlg = new KReplaceDialog(this, "KHTMLText Area Replace Dialog", 0, QStringList(), QStringList(), false); connect( m_repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) ); } m_repDlg->show();#endif // KHTML_NO_SPELLING}bool TextAreaWidget::event( QEvent *e ){ if ( e->type() == QEvent::AccelAvailable && isReadOnly() ) { QKeyEvent* ke = (QKeyEvent*) e; if ( ke->state() & ControlButton ) { switch ( ke->key() ) { case Key_Left: case Key_Right: case Key_Up: case Key_Down: case Key_Home: case Key_End: ke->accept(); default: break; } } } return KTextEdit::event( e );}// -------------------------------------------------------------------------RenderTextArea::RenderTextArea(HTMLTextAreaElementImpl *element) : RenderFormElement(element){ scrollbarsStyled = false; TextAreaWidget *edit = new TextAreaWidget(element->wrap(), view()); setQWidget(edit); const KHTMLSettings *settings = view()->part()->settings();#ifndef KHTML_NO_SPELLING edit->setCheckSpellingEnabled( settings->autoSpellCheck() );#endif edit->setTabChangesFocus( ! settings->allowTabulation() ); connect(edit,SIGNAL(textChanged()),this,SLOT(slotTextChanged()));}RenderTextArea::~RenderTextArea(){ if ( element()->m_dirtyvalue ) { element()->m_value = text(); element()->m_dirtyvalue = false; }}void RenderTextArea::handleFocusOut(){ TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); if ( w && element()->m_dirtyvalue ) { element()->m_value = text(); element()->m_dirtyvalue = false; element()->onChange(); }}void RenderTextArea::calcMinMaxWidth(){ KHTMLAssert( !minMaxKnown() ); TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); const QFontMetrics &m = style()->fontMetrics(); w->setTabStopWidth(8 * m.width(" ")); QSize size( kMax(element()->cols(), 1L)*m.width('x') + w->frameWidth() + w->verticalScrollBar()->sizeHint().width(), kMax(element()->rows(), 1L)*m.lineSpacing() + w->frameWidth()*4 + (w->wordWrap() == QTextEdit::NoWrap ? w->horizontalScrollBar()->sizeHint().height() : 0) ); setIntrinsicWidth( size.width() ); setIntrinsicHeight( size.height() ); RenderFormElement::calcMinMaxWidth();}void RenderTextArea::setStyle(RenderStyle* _style){ bool unsubmittedFormChange = element()->m_unsubmittedFormChange; RenderFormElement::setStyle(_style); widget()->blockSignals(true); widget()->setAlignment(textAlignment()); widget()->blockSignals(false); scrollbarsStyled = false; element()->m_unsubmittedFormChange = unsubmittedFormChange;}void RenderTextArea::layout(){ KHTMLAssert( needsLayout() ); RenderFormElement::layout(); TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); if (!scrollbarsStyled) { w->horizontalScrollBar()->setPalette(style()->palette()); w->verticalScrollBar()->setPalette(style()->palette()); scrollbarsStyled=true; }}void RenderTextArea::updateFromElement(){ TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); w->setReadOnly(element()->readOnly()); QString elementText = element()->value().string(); if ( elementText != w->text() ) { w->blockSignals(true); int line, col; w->getCursorPosition( &line, &col ); int cx = w->contentsX(); int cy = w->contentsY(); w->setText( elementText ); w->setCursorPosition( line, col ); w->scrollBy( cx, cy ); w->blockSignals(false); } element()->m_dirtyvalue = false; RenderFormElement::updateFromElement();}void RenderTextArea::close( ){ element()->setValue( element()->defaultValue() ); RenderFormElement::close();}static QString expandLF(const QString& s){ // LF -> CRLF unsigned crs = s.contains( '\n' ); if (crs == 0) return s; unsigned len = s.length(); QString r; r.reserve(len + crs + 1); unsigned pos2 = 0; for(unsigned pos = 0; pos < len; pos++) { QChar c = s.at(pos); switch(c.unicode()) { case '\n': r[pos2++] = '\r'; r[pos2++] = '\n'; break; case '\r': break; default: r[pos2++]= c; break; } } r.squeeze(); return r;}QString RenderTextArea::text(){ QString txt; TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); if(element()->wrap() == DOM::HTMLTextAreaElementImpl::ta_Physical) { // yeah, QTextEdit has no accessor for getting the visually wrapped text for (int p=0; p < w->paragraphs(); ++p) { int pl = w->paragraphLength(p); int ll = 0; int lindex = w->lineOfChar(p, 0); QString paragraphText = w->text(p); for (int l = 0; l < pl; ++l) { if (lindex != w->lineOfChar(p, l)) { paragraphText.insert(l+ll++, QString::fromLatin1("\n")); lindex = w->lineOfChar(p, l); } } txt += paragraphText; if (p < w->paragraphs() - 1) txt += QString::fromLatin1("\n"); } } else txt = w->text(); return expandLF(txt);}void RenderTextArea::highLightWord( unsigned int length, unsigned int pos ){#ifndef KHTML_NO_SPELLING TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget); if ( w ) w->highLightWord( length, pos );#endif // KHTML_NO_SPELLING}void RenderTextArea::slotTextChanged(){ element()->m_dirtyvalue = true; if (element()->m_value != text()) element()->m_unsubmittedFormChange = true;}void RenderTextArea::select(){ static_cast<TextAreaWidget *>(m_widget)->selectAll();}// ---------------------------------------------------------------------------#include "render_form.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -