Example #1
0
void FindDialog::find(bool backwards)
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}
	if (backwards) {
		flags |= QTextDocument::FindBackward;
	}

	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->document()->find(text, document->textCursor(), flags);
	if (cursor.isNull()) {
		cursor = document->textCursor();
		cursor.movePosition(!backwards ? QTextCursor::Start : QTextCursor::End);
		cursor = document->document()->find(text, cursor, flags);
	}

	if (!cursor.isNull()) {
		document->setTextCursor(cursor);
	} else {
		QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
	}
}
Example #2
0
void MainWindow::initTextEditor()
{
    //create tab
    QWidget *tab = new QWidget(this);
    QString objName = QString("tab"),
            fileName = "";
    tab->setObjectName(objName);
    //create layout
    QHBoxLayout *layout = new QHBoxLayout(tab);
    layout->setSpacing(0);
    layout->setContentsMargins(11, 11, 11, 11);
    layout->setObjectName(QString("horizontalLayout"));
    layout->setContentsMargins(0, 0, 0, 0);

    //create textedit
    QTextEdit *edit = new QTextEdit(tab);
    edit->setObjectName(QString("textEdit"));

    layout->addWidget(edit);
    ui->tabs->addWidget(tab);

    //slot and signal
    //font change signal
    connect(edit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
            this, SLOT(currentCharFormatChanged(QTextCharFormat)));
    connect(edit, SIGNAL(cursorPositionChanged()),
            this, SLOT(cursorPositionChanged()));

    //modification
    connect(edit->document(), SIGNAL(modificationChanged(bool)),
            ui->actionSave, SLOT(setEnabled(bool)));
    connect(edit->document(), SIGNAL(modificationChanged(bool)),
            this, SLOT(setWindowModified(bool)));
    connect(edit->document(), SIGNAL(undoAvailable(bool)),
            ui->actionUndo, SLOT(setEnabled(bool)));
    connect(edit->document(), SIGNAL(redoAvailable(bool)),
            ui->actionRedo, SLOT(setEnabled(bool)));

    //redo undo
    connect(ui->actionUndo, SIGNAL(triggered()), edit, SLOT(undo()));
    connect(ui->actionRedo, SIGNAL(triggered()), edit, SLOT(redo()));

    //cut copy paste
    connect(ui->actionCut, SIGNAL(triggered()), edit, SLOT(cut()));
    connect(ui->actionCopy, SIGNAL(triggered()), edit, SLOT(copy()));
    connect(ui->actionPaste, SIGNAL(triggered()), edit, SLOT(paste()));

    connect(edit, SIGNAL(copyAvailable(bool)), ui->actionCut, SLOT(setEnabled(bool)));
    connect(edit, SIGNAL(copyAvailable(bool)), ui->actionCopy, SLOT(setEnabled(bool)));

    textEditor.tab = tab;
    textEditor.editor = edit;
    textEditor.layout = layout;
    textEditor.objName = objName;
    textEditor.fileName = fileName;
}
Example #3
0
QTextDocument *QTextEditProto::document() const
{
  QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
  if (DEBUG) qDebug("QTextEditProto::document() item = %p", item);
  if (item)
  {
    if (DEBUG) qDebug("QTextEditProto::document() item->document() = %p", item->document());
    return item->document();
  }
  return 0;
}
Example #4
0
bool MainWindow::fileSave()
{
    QTextEdit *pEdit = textEditor.editor;
    QString fileName = textEditor.fileName;
    if (fileName.isEmpty())
        return fileSaveAs();

    QTextDocumentWriter writer(fileName);
    bool success = writer.write(pEdit->document());
    if (success)
        pEdit->document()->setModified(false);
    return success;
}
Example #5
0
void FindDialog::replaceAll()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}

	// Count instances
	int found = 0;
	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	cursor.movePosition(QTextCursor::Start);
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			found++;
		} else {
			break;
		}
	}
	if (found) {
		if (QMessageBox::question(this, tr("Question"), tr("Replace %n instance(s)?", "", found), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
			return;
		}
	} else {
		QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
		return;
	}

	// Replace instances
	QTextCursor start_cursor = document->textCursor();
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			cursor.insertText(m_replace_string->text());
			document->setTextCursor(cursor);
		} else {
			break;
		}
	}
	document->setTextCursor(start_cursor);
}
Example #6
0
void ClipboardDialog::on_listWidgetFormats_currentItemChanged(
        QListWidgetItem *current, QListWidgetItem *)
{
    ui->actionRemove_Format->setEnabled(current != NULL);

    QTextEdit *edit = ui->textEditContent;
    QString mime = current ? current->text() : QString();

    edit->clear();
    const QByteArray bytes = m_data.value(mime).toByteArray();
    if ( mime.startsWith(QString("image")) ) {
        edit->document()->addResource( QTextDocument::ImageResource,
                                       QUrl("data://1"), bytes );
        edit->setHtml( QString("<img src=\"data://1\" />") );
    } else {
        QTextCodec *codec = QTextCodec::codecForName("utf-8");
        if (mime == QLatin1String("text/html"))
            codec = QTextCodec::codecForHtml(bytes, codec);
        else
            codec = QTextCodec::codecForUtfText(bytes, codec);
        edit->setPlainText( codec ? codec->toUnicode(bytes) : QString() );
    }

    ui->labelProperties->setText(
        tr("<strong> mime:</strong> %1 <strong>size:</strong> %2 bytes")
            .arg(escapeHtml(mime))
            .arg(QString::number(bytes.size())));
}
Example #7
0
void FindDialog::replaceAll()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}
	QRegExp regex(text, !m_ignore_case->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2);

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked() && !m_regular_expressions->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}

	// Count instances
	int found = 0;
	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	cursor.movePosition(QTextCursor::Start);
	if (!m_regular_expressions->isChecked()) {
		forever {
			cursor = document->document()->find(text, cursor, flags);
			if (!cursor.isNull()) {
				found++;
			} else {
				break;
			}
		}
	} else {
// Testing get/set functions
void tst_QTextObject::getSetCheck()
{
    QTextEdit edit;
    QTextFrame obj1(edit.document());
    // QTextFrameLayoutData * QTextFrame::layoutData()
    // void QTextFrame::setLayoutData(QTextFrameLayoutData *)
    QTextFrameLayoutData *var1 = new QTextFrameLayoutData;
    obj1.setLayoutData(var1);
    QCOMPARE(var1, obj1.layoutData());
    obj1.setLayoutData((QTextFrameLayoutData *)0);
    QCOMPARE((QTextFrameLayoutData *)0, obj1.layoutData());
    // delete var1; // No delete, since QTextFrame takes ownership

    QTextBlock obj2 = edit.textCursor().block();
    // QTextBlockUserData * QTextBlock::userData()
    // void QTextBlock::setUserData(QTextBlockUserData *)
    QTextBlockUserData *var2 = new QTextBlockUserData;
    obj2.setUserData(var2);
    QCOMPARE(var2, obj2.userData());
    obj2.setUserData((QTextBlockUserData *)0);
    QCOMPARE((QTextBlockUserData *)0, obj2.userData());

    // int QTextBlock::userState()
    // void QTextBlock::setUserState(int)
    obj2.setUserState(0);
    QCOMPARE(0, obj2.userState());
    obj2.setUserState(INT_MIN);
    QCOMPARE(INT_MIN, obj2.userState());
    obj2.setUserState(INT_MAX);
    QCOMPARE(INT_MAX, obj2.userState());
}
Example #9
0
QTextDocument* Printer::getPuzzleDocumentForPrinting(crossword::CrosswordBase& puzzle) const
{
    QDir dir;
    QString postalAddress = assets::getPostalAddress();

    QString textToPrint;

    textToPrint.append(puzzle.getInformation().append("<br/><br/>"));

    //copy and sort by calendar date
    std::vector<crossword::CrosswordEntry> entries = puzzle.getEntries();
    std::sort(entries.begin(), entries.end(), crossword::SortByIdentifier());

    for (unsigned int i = 0; i < entries.size(); i++) {
        QString id = entries.at(i).getIdentifier();
        QString entryName = entries.at(i).getEntry();
        QString direction = entries.at(i).getDirection();
        QString answer = entries.at(i).getGuess().getString();

        // QTextEdit understands a HTML subset and \n is treated as a space, so using <br/> tag for newlines instead
        textToPrint.append(id).append(" - ").append(entryName).append(" ").append(
            direction).append(" --- ").append(answer).append("<br/>");
    }

    textToPrint.append("<br/>").append(postalAddress);

    QTextEdit* textViewer = new QTextEdit(textToPrint);

    QTextDocument* document = textViewer->document();

    return document;
}
Example #10
0
File: main.cpp Project: Afreeca/qt
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

//! [0]
    QTextDocument *document = editor->document();
    QTextCursor redCursor(document);
//! [0] //! [1]
    QTextCursor blueCursor(document);
//! [1]

    QTextCharFormat redFormat(redCursor.charFormat());
    redFormat.setForeground(Qt::red);
    QTextCharFormat blueFormat(blueCursor.charFormat());
    blueFormat.setForeground(Qt::blue);

    redCursor.setCharFormat(redFormat);
    blueCursor.setCharFormat(blueFormat);

    for (int i = 0; i < 20; ++i) {
        if (i % 2 == 0)
            redCursor.insertText(tr("%1 ").arg(i), redFormat);
        if (i % 5 == 0)
            blueCursor.insertText(tr("%1 ").arg(i), blueFormat);
    }

    editor->setWindowTitle(tr("Text Document Cursors"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
// Extract the wrapped text from a text edit, which performs
// the wrapping only optically.
void SubmitEditorWidget::wrapDescription()
{
    if (!lineWrap())
        return;
    const QChar newLine = QLatin1Char('\n');
    QTextEdit e;
    e.setVisible(false);
    e.setMinimumWidth(1000);
    e.setFontPointSize(1.0);
    e.setLineWrapColumnOrWidth(d->m_ui.description->lineWrapColumnOrWidth());
    e.setLineWrapMode(d->m_ui.description->lineWrapMode());
    e.setWordWrapMode(d->m_ui.description->wordWrapMode());
    e.setPlainText(d->m_description);
    d->m_description.clear();
    QTextCursor cursor(e.document());
    cursor.movePosition(QTextCursor::Start);
    while (!cursor.atEnd()) {
        const QString block = cursor.block().text();
        if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap
            d->m_description += block + newLine;
            cursor.movePosition(QTextCursor::EndOfBlock);
        } else {
            forever {
                cursor.select(QTextCursor::LineUnderCursor);
                d->m_description += cursor.selectedText();
                d->m_description += newLine;
                cursor.clearSelection();
                if (cursor.atBlockEnd())
                    break;
                cursor.movePosition(QTextCursor::NextCharacter);
            }
        }
        cursor.movePosition(QTextCursor::NextBlock);
    }
}
Example #12
0
SEXP
qt_qsetRSyntaxHighlighter(SEXP x)
{
    QTextEdit *edit = unwrapSmoke(x, QTextEdit);
    RSyntaxHighlighter *highlighter = new RSyntaxHighlighter(edit->document());
    highlighter->setActive(true);
    return R_NilValue;
}
Example #13
0
void ItemWidget::setModelData(QWidget *editor, QAbstractItemModel *model,
                              const QModelIndex &index) const
{
    QTextEdit *textEdit = qobject_cast<QTextEdit*>(editor);
    if (textEdit != NULL) {
        // Clear text.
        model->setData(index, QString());

        QVariantMap data;
        data["text/plain"] = textEdit->toPlainText().toUtf8();
        if ( containsRichText(*textEdit->document()) )
            data["text/html"] = textEdit->toHtml().toUtf8();
        model->setData(index, data, contentType::updateData);

        textEdit->document()->setModified(false);
    }
}
Example #14
0
void ItemWidget::setModelData(QWidget *editor, QAbstractItemModel *model,
                              const QModelIndex &index) const
{
    QTextEdit *textEdit = qobject_cast<QTextEdit*>(editor);
    if (textEdit != NULL) {
        model->setData(index, textEdit->toPlainText());
        textEdit->document()->setModified(false);
    }
}
Example #15
0
  /*!
     * \class TextCursorChangeBorder
   * \author Anders Fernström
   * \date 2005-11-03
   * \date 2005-11-07 (update)
     *
     * \brief Command for changing border
   *
   * 2005-11-07 AF, implemented the function
     */
  void TextCursorChangeBorder::execute()
  {
    QTextEdit *editor = document()->getCursor()->currentCell()->textEdit();

    if( editor )
    {
      QTextFrameFormat format = editor->document()->rootFrame()->frameFormat();
      format.setBorder( border_ );
      editor->document()->rootFrame()->setFrameFormat( format );

      // create a rule for the border
      QString ruleValue;
      ruleValue.setNum( border_ );
      Rule *rule = new Rule( "OMNotebook_Border", ruleValue );
      document()->getCursor()->currentCell()->addRule( rule );

      // update the cells style
      document()->getCursor()->currentCell()->style()->textFrameFormat()->setBorder( border_ );
    }
  }
Example #16
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    LineEdit l;
    l.show();

    QTextEdit* text = new QTextEdit;
    text->setPlainText("Simple text2");
    QTextDocumentWriter writer;
    writer.setFileName("teeeext.txt");
    writer.write(text->document());

    QTextEdit* pdf = new QTextEdit("PDF text");
    QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("output.pdf");
    pdf->document()->print(&printer);

    return a.exec();
}
Example #17
0
void Editor::setModified(bool b)
{
    const int num = this->count();
    for (int i = 0; i < num; i++)
    {
        QTextEdit * editor = qobject_cast<QTextEdit *>(this->widget(i));
        
        if (editor != NULL) {
            editor->document()->setModified(b);
        }
    }
}
Example #18
0
ZoomConfigurator::ZoomConfigurator(QWidget *parent) :QWidget(parent)
{
    #ifdef K_DEBUG
        #ifdef Q_OS_WIN32
            qDebug() << "[ZoomConfigurator()]";
        #else
            TINIT;
        #endif
    #endif

    QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
    QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);

    scale = new QLabel(tr("Scale Factor"));
    scale->setFont(QFont("Arial", 8, QFont::Normal, false));
    scale->setAlignment(Qt::AlignHCenter);
    layout->addWidget(scale);

    factor = new QDoubleSpinBox();

    factor->setDecimals(1);
    factor->setSingleStep(0.1);
    factor->setMinimum(0.1);
    factor->setMaximum(0.9);
    layout->addWidget(factor);

    QLabel *label = new QLabel(tr("Tips"));
    label->setAlignment(Qt::AlignHCenter);
    label->setFont(QFont("Arial", 8, QFont::Normal, false));

    QTextEdit *textArea = new QTextEdit; 

    textArea->setFont(QFont("Arial", 8, QFont::Normal, false));
    textArea->setHtml("<p><b>" + tr("Zoom Square mode") + ":</b> " + tr("Press Ctrl key + Mouse left button") + "</p>"); 

    QString text = textArea->document()->toPlainText();
    int height = (text.length()*270)/207;

    textArea->setFixedHeight(height);

    mainLayout->addLayout(layout);
    mainLayout->addWidget(label);
    mainLayout->addWidget(textArea);
    mainLayout->addStretch(2);

    TCONFIG->beginGroup("ZoomTool");
    double value = TCONFIG->value("zoomFactor", -1).toDouble();

    if (value > 0) 
        factor->setValue(value);
    else 
        factor->setValue(0.5);
}
QTextDocument* QsvTextOperationsWidget::getTextDocument()
{
	QTextEdit *t = qobject_cast<QTextEdit*>(parent());
	if (t) {
		return t->document();
	} else {
		QPlainTextEdit *pt = qobject_cast<QPlainTextEdit*>(parent());
		if (pt) {
			return pt->document();
		}
	}
	return NULL;
}
Example #20
0
bool FindDialog::find() {
    QTextEdit* textEdit = getCurrentTextEdit();
    if (textEdit == NULL) return false;
    int from = textEdit->textCursor().selectionEnd();
    QTextCursor cursor = textEdit->document()->find(ui->findString->text(), from);
    if (!cursor.isNull()) {
        textEdit->setTextCursor(cursor);
        return true;
    }
    else {
        return false;
    }
}
Example #21
0
void MainWindow::on_tabs_currentChanged(int index)
{
    if(index == -1)
        return;
    if(ui->tabs->currentWidget()->objectName() == "welcome"){
        ui->toolBox->hide();
        setWelcomActions(false);
    }
    else{
        ui->toolBox->show();
        setWelcomActions(true);

        //set enable
        QTextEdit *pe = textEditor.editor;
        if(pe != NULL){
            ui->actionSave->setEnabled(pe->document()->isModified());
            ui->actionUndo->setEnabled(pe->document()->isUndoAvailable());
            ui->actionRedo->setEnabled(pe->document()->isRedoAvailable());
            ui->actionCut->setEnabled(false);
            ui->actionCopy->setEnabled(false);
        }
    }
}
Example #22
0
void MainWindow::on_actionExportPDF_triggered()
{
    QString fileName = QFileDialog::getSaveFileName(this, "导出为pdf",
                                                    QString(), "*.pdf");
    QTextEdit *pEdit = textEditor.editor;
    if (!fileName.isEmpty()) {
        if (QFileInfo(fileName).suffix().isEmpty())
            fileName.append(".pdf");
        QPrinter printer(QPrinter::HighResolution);
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
        pEdit->document()->print(&printer);
    }
}
Example #23
0
bool Editor::isModified() const
{
    bool modified = false;

    const int num = this->count();
    for (int i = 0; i < num; i++)
    {
        QTextEdit * editor = qobject_cast<QTextEdit *>(this->widget(i));
        
        if (editor != NULL && editor->document()->isModified()) {
            modified = true;
        }
    }

    return modified;	
}
Example #24
0
int main(int argc, char ** argv) {
   QApplication app{argc, argv};
   QWidget w;
   QVBoxLayout layout{&w};
   QLineEdit edit;
   QTextEdit message;
   message.setReadOnly(true);
   message.setText("Foo Bar!");
   layout.addWidget(&edit);
   layout.addWidget(&message);
   layout.addStretch();
   QObject::connect(&edit, &QLineEdit::textChanged, &message, &QTextEdit::setPlainText);
   QObject::connect(message.document()->documentLayout(),
                    &QAbstractTextDocumentLayout::documentSizeChanged,
                    &message, [&]{ updateSize(&message); });
   w.show();
   return app.exec();
}
Example #25
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit();

    QTextCursor cursor(editor->textCursor());
    cursor.movePosition(QTextCursor::Start);

    QTextCharFormat plainFormat(cursor.charFormat());
    QTextCharFormat colorFormat = plainFormat;
    colorFormat.setForeground(Qt::red);

    cursor.insertText(tr("Text can be displayed in a variety of "
                                  "different character "
                                  "formats. "), plainFormat);
    cursor.insertText(tr("We can emphasize text by making it "));
    cursor.insertText(tr("italic, give it a different color "));
    cursor.insertText(tr("to the default text color, underline it, "));
    cursor.insertText(tr("and use many other effects."));

    QString searchString = tr("text");

    QTextDocument *document = editor->document();
//! [0]
    QTextCursor newCursor(document);

    while (!newCursor.isNull() && !newCursor.atEnd()) {
        newCursor = document->find(searchString, newCursor);

        if (!newCursor.isNull()) {
            newCursor.movePosition(QTextCursor::WordRight,
                                   QTextCursor::KeepAnchor);

            newCursor.mergeCharFormat(colorFormat);
        }
//! [0] //! [1]
    }
//! [1]

    editor->setWindowTitle(tr("Text Document Find"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
Example #26
0
bool MainWindow::maybeSave()
{
    QTextEdit *pEdit = textEditor.editor;
    if(pEdit == NULL)
        return true;
    if (!pEdit->document()->isModified())
        return true;
    QMessageBox::StandardButton ret;
    ret = QMessageBox::warning(this, tr("自动出卷系统"),
                               tr("文档%1已经被修改。\n"
                                  "想要保存文档内容吗?").arg(
                                   ""),
                               QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
    if (ret == QMessageBox::Save)
        return fileSave();
    else if (ret == QMessageBox::Cancel)
        return false;
    return true;
}
Example #27
0
void PsiTipLabel::initUi()
{
	margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this);
	setFrameStyle(QFrame::NoFrame);

	// doc = new QTextDocument(this);
	// QTextDocumentLayout is private in Qt4
	// and it's impossible to set wrapping mode directly.
	// So we create this QTextEdit instance and use its QTextDocument,
	// just because QTextEdit can set the wrapping mode.
	// Yes, this is crazy...
	QTextEdit *edit = new QTextEdit(this);
	edit->hide();
	edit->setWordWrapMode(QTextOption::WordWrap);
	doc = edit->document();
	doc->setUndoRedoEnabled(false);
	doc->setDefaultFont(font());

	ensurePolished();
	setText(theText_);
}
Example #28
0
void ClipboardDialog::on_listWidgetFormats_currentItemChanged(
        QListWidgetItem *current, QListWidgetItem *)
{
    ui->actionRemove_Format->setEnabled(current != NULL);

    QTextEdit *edit = ui->textEditContent;
    QString mime = current ? current->text() : QString();

    edit->clear();
    const QByteArray bytes = m_data.value(mime).toByteArray();
    if ( mime.startsWith(QString("image")) ) {
        edit->document()->addResource( QTextDocument::ImageResource,
                                       QUrl("data://1"), bytes );
        edit->setHtml( QString("<img src=\"data://1\" />") );
    } else {
        edit->setPlainText( dataToText(bytes, mime) );
    }

    ui->labelProperties->setText(
                tr("<strong>Size:</strong> %1 bytes", "Size of data in bytes").arg(bytes.size()) );
}
Example #29
0
    void highlightMatches(const QString &pattern)
    {
        QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget);
        if (!ed)
            return;

        QTextCursor cur = ed->textCursor();

        QTextEdit::ExtraSelection selection;
        selection.format.setBackground(Qt::yellow);
        selection.format.setForeground(Qt::black);

        // Highlight matches.
        QTextDocument *doc = ed->document();
        QRegExp re(pattern);
        cur = doc->find(re);

        m_searchSelection.clear();

        int a = cur.position();
        while ( !cur.isNull() ) {
            if ( cur.hasSelection() ) {
                selection.cursor = cur;
                m_searchSelection.append(selection);
            } else {
                cur.movePosition(QTextCursor::NextCharacter);
            }
            cur = doc->find(re, cur);
            int b = cur.position();
            if (a == b) {
                cur.movePosition(QTextCursor::NextCharacter);
                cur = doc->find(re, cur);
                b = cur.position();
                if (a == b) break;
            }
            a = b;
        }

        updateExtraSelections();
    }
QsvTextOperationsWidget::QsvTextOperationsWidget( QWidget *parent )
	: QObject(parent)
{
	setObjectName("QsvTextOperationWidget");
	m_gotoLine    = NULL;
	m_search      = NULL;
	m_replace     = NULL;
	m_document    = NULL;
	searchFormUi  = NULL;
	replaceFormUi = NULL;
	searchFoundColor	= QColor( "#DDDDFF" ); //QColor::fromRgb( 220, 220, 255)
	searchNotFoundColor	= QColor( "#FFAAAA" ); //QColor::fromRgb( 255, 102, 102) "#FF6666"
	
	m_replaceTimer.setInterval(100);
	m_replaceTimer.setSingleShot(true);
	connect(&m_replaceTimer,SIGNAL(timeout()),this,SLOT(updateReplaceInput()));

	// this one is slower, to let the user think about his action
	// this is a modifying command, unlike a passive search
	m_searchTimer.setInterval(250);
	m_searchTimer.setSingleShot(true);
	connect(&m_searchTimer,SIGNAL(timeout()),this,SLOT(updateSearchInput()));
	
	// TODO clean this up, this is too ugly to be in a constructor
	QTextEdit *t = qobject_cast<QTextEdit*>(parent);
	if (t) {
		m_document = t->document();
	}
	else {
		QPlainTextEdit *pt = qobject_cast<QPlainTextEdit*>(parent);
		if (pt) {
			m_document = pt->document();
		}
	}
	connect(parent,SIGNAL(widgetResized()),this,SLOT(adjustBottomWidget()));
	parent->installEventFilter(this);
}