/*!
	This slot applies custom text color for user - entered text
    It does not affect the text originally inserted into editor
 */
void NmEditorTextEdit::updateCustomTextColor()
{
    NM_FUNCTION;
    
    if (mCustomTextColor.first) {
        QTextCursor tcursor = textCursor();
        QTextCharFormat fmt;
        int pos = tcursor.position();
        if (pos > 0) {
            // If there isn't any user-made selection - apply custom color
            if (!tcursor.hasSelection() && !tcursor.hasComplexSelection()) {
                // Select last added char and set its color to custom
                if (tcursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, 1)
                    && tcursor.hasSelection()) {
                    fmt = tcursor.charFormat();
                    fmt.setForeground(mCustomTextColor.second);
                    tcursor.mergeCharFormat(fmt);
                }
            }
        }
        else {
            fmt = tcursor.charFormat();
            fmt.setForeground(mCustomTextColor.second);
            tcursor.mergeCharFormat(fmt);
            setTextCursor(tcursor);
        }
    }
}
void OCamlSource::markCurrentLocation()
{
    timer_index++;
    if ( _start_char != 0  && _end_char != 0 )
    {
        if ( timer_index < nb_timer_values )
        { // blink
            QTextCharFormat selectedFormat;
            QColor outlineColor;

            if ( timer_index % 2 == 0 )
                outlineColor = QColor( Qt::darkYellow );
            else
                outlineColor = QColor( Qt::yellow );

            selectedFormat.setBackground( outlineColor );
            QTextCursor cur = textCursor();
            cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );

            cur.mergeCharFormat( selectedFormat );
        }
        else
        {
           
            QColor currentPositionColor = QColor( Qt::darkYellow );
            QColor currentInstructionColor = QColor( Qt::yellow );
            QTextCharFormat currentPositionFormat;
            currentPositionFormat.setBackground( currentPositionColor );
            QTextCharFormat currentInstructionFormat;
            currentInstructionFormat.setBackground( currentInstructionColor );

            QTextCursor cur = textCursor();
            cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );

            cur.mergeCharFormat( currentInstructionFormat );

            int current_position ;
            if (_after)
                current_position = _end_char - 1;
            else
                current_position = _start_char;

            cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, current_position );
            cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor );

            cur.mergeCharFormat( currentPositionFormat );
        }
    }
    if ( timer_index < nb_timer_values )
    {
        markCurrentLocationTimer->setInterval( timer_values[ timer_index % nb_timer_values ] );
        markCurrentLocationTimer->start();
    }
}
void KoTextInlineRdf::attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor)
{
    QTextCharFormat format = cursor.charFormat();
    QVariant v = QVariant::fromValue(inlineRdf);
    format.setProperty(KoCharacterStyle::InlineRdf, v);
    cursor.mergeCharFormat(format);
}
//init font size
void TextEdit::iniFontSize(){
  //the document contains 50 lines
  cout<<"#textedit::inifontsize";
  QString s="12";
  qreal pointSize = s.toFloat();
  QTextCharFormat fmt;
  fmt.setFontPointSize(pointSize);
  //QColor col = Qt::red;
  //fmt.setForeground(col);
  ///textEdit->setCurrentCharFormat(fmt);

  //cursor is the main widget which handle document editing
  QTextCursor cursor = textEdit->textCursor();
  //cursor.setPosition(120,QTextCursor::MoveAnchor);
  //cursor.movePosition(QTextCursor::NoMove,QTextCursor::KeepAnchor,100000);//textEdit->document().length());
  ////mergeFormatOnWordOrSelection(fmt);

  //cursor has four selection type: the last one select the entire document
  cursor.select(QTextCursor::Document);
  cursor.mergeCharFormat(fmt);
  //  QTextBlock block=cursor.block();
  //  cout<<"TextEdit.initFontSize:the block start and length:";
  //  cout<<block.position()<<","<<block.length();
  //  cout<<"TextEdit.initFontSize:the block text:"<<block.text();
  //cursor.setPosition(0);
}
/*!
 * \brief   Changes the underline attribute of the selected text to \a v
 */
void QwwRichTextEdit::setUnderline(bool v){
    QTextCursor cur = textCursor();
    QTextCharFormat fmt;
    fmt.setFontUnderline(v);
    cur.mergeCharFormat(fmt);
    setTextCursor(cur);
  }
Exemple #6
0
void Setting::setFontColorPer()
{
    QFont pFont;
    QColor  pColor;

    if(radioButtonProgFC->isChecked())
    {
        pFont =fontprog;
        pColor =Qt::black;
    }
    else  if(radioButtonQuranFC->isChecked())
    {
        pFont =fontchapter;
        pColor =colorQ.currentColor();
    }
    else  if(radioButtonTrFC->isChecked())
    {
        pFont =fontchapterTr;
        pColor =colorTr.currentColor();
    } else if(radioButtonBooksFC)
    {
        pFont =fontBook;
        pColor =colorBook.currentColor();
    }

    QTextCharFormat fmt;
    fmt.setForeground(pColor);
    fmt.setFont(pFont);
    textEditFontPerviwe->selectAll();
    QTextCursor cursor = textEditFontPerviwe->textCursor();
    cursor.mergeCharFormat(fmt);
    textEditFontPerviwe->mergeCurrentCharFormat(fmt);
    cursor.clearSelection();
    textEditFontPerviwe->setTextCursor(cursor);
}
void
SimpleRichTextEdit::setRichText(const SubtitleComposer::SString &richText)
{
	setPlainText(richText.string());

	QTextCursor cursor = textCursor();
	cursor.setPosition(0);

	int currentStyleFlags = -1;
	QRgb currentStyleColor = 0;
	QTextCharFormat format;
	for(int position = 0, size = richText.length(); position < size; ++position) {
		if(currentStyleFlags != richText.styleFlagsAt(position) || ((richText.styleFlagsAt(position) & SubtitleComposer::SString::Color) && currentStyleColor != richText.styleColorAt(position))) {
			currentStyleFlags = richText.styleFlagsAt(position);
			currentStyleColor = richText.styleColorAt(position);
			format.setFontWeight(currentStyleFlags & SubtitleComposer::SString::Bold ? QFont::Bold : QFont::Normal);
			format.setFontItalic(currentStyleFlags & SubtitleComposer::SString::Italic);
			format.setFontUnderline(currentStyleFlags & SubtitleComposer::SString::Underline);
			format.setFontStrikeOut(currentStyleFlags & SubtitleComposer::SString::StrikeThrough);
			if((currentStyleFlags &SubtitleComposer::SString::Color) == 0)
				format.setForeground(QBrush());
			else
				format.setForeground(QBrush(QColor(currentStyleColor)));
		}

		cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1);
		cursor.mergeCharFormat(format);
		cursor.setPosition(position + 1);
	}

	clearUndoRedoHistory();
}
QString OCamlSource::stopDebugging( const QString &file, int start_char, int end_char , bool after)
{
    if ( curFile != file )
        loadFile( file );
    QTextCharFormat unselectedFormat;
    unselectedFormat.setBackground( Qt::white );

    QTextCursor cur = textCursor();
    cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
    cur.movePosition( QTextCursor::End, QTextCursor::KeepAnchor );
    cur.mergeCharFormat( unselectedFormat );

    cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
    cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, start_char );

    setTextCursor( cur );

    centerCursor();
    _start_char = start_char;
    _end_char = end_char;
    _after = after;
    timer_index = 0;
    markBreakPoints(false);
    markCurrentLocation();

    cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
    cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
    cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );
    QString text = cur.selectedText();

    return text;
}
void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
}
void XYZTextEditor::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
    QTextCursor cursor = m_ui->textEdit->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    m_ui->textEdit->mergeCurrentCharFormat(format);
}
Exemple #11
0
void MailEditorMainWindow::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
  {
  QTextCursor cursor = ui->messageEdit->textCursor();
  if(cursor.hasSelection() == false)
    cursor.select(QTextCursor::WordUnderCursor);
  cursor.mergeCharFormat(format);
  ui->messageEdit->mergeCurrentCharFormat(format);
  }
void FormattedTextWidget::setTextCursorFont( const QFont &font )
{
    QTextCursor cursor = d->m_description->textCursor();
    QTextCharFormat format;
    format.setFontFamily( font.family() );
    cursor.mergeCharFormat( format );
    d->m_description->setTextCursor( cursor );
}
void FormattedTextWidget::setTextCursorUnderlined( bool underlined )
{
    QTextCursor cursor = d->m_description->textCursor();
    QTextCharFormat format;
    format.setFontUnderline( underlined );
    cursor.mergeCharFormat( format );
    d->m_description->setTextCursor( cursor );
}
void FormattedTextWidget::setTextCursorItalic( bool italic )
{
    QTextCursor cursor = d->m_description->textCursor();
    QTextCharFormat format;
    format.setFontItalic( italic );
    cursor.mergeCharFormat( format );
    d->m_description->setTextCursor( cursor );
}
void FormattedTextWidget::setTextCursorBold( bool bold )
{
    QTextCursor cursor = d->m_description->textCursor();
    QTextCharFormat format;
    format.setFontWeight( bold ? QFont::Bold : QFont::Normal );
    cursor.mergeCharFormat( format );
    d->m_description->setTextCursor( cursor );
}
Exemple #16
0
void ChatWindow::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = ui.textBrowser->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    ui.textBrowser->mergeCurrentCharFormat(format);
}
//  设置光标的选区,使格式作用于选区内的字符,若没有选区则作用于光标所在处的字符
void FontSet::mergeFormat(QTextCharFormat format)
{
    QTextCursor cursor = text->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    text->mergeCurrentCharFormat(format);
}
//格式设置
void MyChild::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = this->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    this->mergeCurrentCharFormat(format);
}
void MainWindow::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = activeEditor()->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    activeEditor()->mergeCurrentCharFormat(format);
}
void CreateBlogMsg::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = ui.msgEdit->textCursor();
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(format);
    ui.msgEdit->mergeCurrentCharFormat(format);
}
/*!
 * \brief   Changes the color of the selected text to \a c
 */
void QwwRichTextEdit::setColor(const QColor &c)
{
    QTextCursor cur = textCursor();
    QTextCharFormat fmt;
    fmt.setForeground(c);
    cur.mergeCharFormat(fmt);
    setTextCursor(cur);
}
void GraphicTextDialog::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    QTextCursor cursor = textEdit->textCursor();
    if(!cursor.hasSelection()) {
        cursor.select(QTextCursor::WordUnderCursor);
    }
    cursor.mergeCharFormat(format);
    textEdit->mergeCurrentCharFormat(format);
}
void TextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
  QTextCursor cursor = textEdit->textCursor();
  if (!cursor.hasSelection())
    cursor.select(QTextCursor::WordUnderCursor);
  cout<<"TextEdit.mergeFormat..:"<<cursor.selectionStart()<<","<<cursor.selectionEnd();
  cursor.mergeCharFormat(format);
  textEdit->mergeCurrentCharFormat(format);
}
Exemple #24
0
void TextRoom::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
    if ( !isPlainText )
    {
	QTextCursor cursor = textEdit->textCursor();
	cursor.mergeCharFormat(format);
	textEdit->mergeCurrentCharFormat(format);
    }
}
/*!
 * \brief   Changes the bold attribute of the selected text to \a v
 */
void QwwRichTextEdit::setBold(bool v){
    QTextCursor cur = textCursor();
    QTextCharFormat fmt;
//    fmt.setFontWeight(QFont::Bold);
//    cur.mergeCharFormat(fmt);
     fmt.setFontWeight(!v ? QFont::Normal : QFont::Bold);
     cur.mergeCharFormat(fmt);
    setTextCursor(cur);
}
Exemple #26
0
void EditorWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
	if (m_initialPag == RichTextIndex) {
		QTextCursor cursor = editor_rich_text->textCursor();
		if (!cursor.hasSelection())
			cursor.select(QTextCursor::WordUnderCursor);
		cursor.mergeCharFormat(format);
		editor_rich_text->mergeCurrentCharFormat(format);
	}
}
void CreateBlogMsg::changeFormatType(int styleIndex )
{
    ui.msgEdit->setFocus( Qt::OtherFocusReason );

    QTextCursor cursor = ui.msgEdit->textCursor();
    //QTextBlockFormat bformat = cursor.blockFormat();
    QTextBlockFormat bformat;
    QTextCharFormat cformat;

    switch (styleIndex) {
         default:
            case 0:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 0 ) );
            cformat.setFontWeight( QFont::Normal );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
            break;
        case 1:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 1 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 3 ) );
            break;
        case 2:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 2 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 2 ) );
            break;
        case 3:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 3 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 1 ) );
            break;
        case 4:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 4 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
            break;
        case 5:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 5 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -1 ) );
            break;
        case 6:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 6 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -2 ) );
            break;
    }
    //cformat.clearProperty( TextFormat::HasCodeStyle );

    cursor.beginEditBlock();
    cursor.mergeBlockFormat( bformat );
    cursor.select( QTextCursor::BlockUnderCursor );
    cursor.mergeCharFormat( cformat );
    cursor.endEditBlock();
}
void TextZone::mergeFormatOnWordOrSelection(const QTextCharFormat &format)


{
    QTextCursor cursor = this->textCursor();
    //    if(cursor.charFormat().fontItalic())
    //        format.setFontItalic(true);

    cursor.mergeCharFormat(format);
    mergeCurrentCharFormat(format);
}
Exemple #29
0
void MainWindow::TextSetFont(QString comboStr)
{
    QTextCharFormat fmt;
    fmt.setFontFamily(comboStr);

    QTextCursor cursor = ui->sans_text->textCursor();
    if(!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    cursor.mergeCharFormat(fmt);
    ui->sans_text->mergeCurrentCharFormat(fmt);
}
void TextEdit::cursorPositionChanged()
{
  //alignmentChanged(textEdit->alignment());
  QColor col = Qt::red;
  QTextCharFormat fmt;
  fmt.setForeground(col);
  QTextCursor cursor = textEdit->textCursor();
  cout<<"#TextEdit::cursorPositionChanged:";
  cout<<"cursor.selectionStart:"<<cursor.selectionStart()<<","<<cursor.selectionEnd();
  int selectionStart=cursor.selectionStart(),
      selectionEnd=cursor.selectionEnd();
  cursor.mergeCharFormat(fmt);
  colorChanged(col);

  if(!cursor.hasSelection()) return;
  QTextBlock block=cursor.block();
  int blockStart=block.position();
  QTextLayout* layout=cursor.block().layout();
  QTextLine layoutLine=layout->lineForTextPosition(selectionStart-blockStart);
  cout<<"layout line:";
  int lineNumber= layoutLine.lineNumber();
  QPoint blockOffset=layout->position().toPoint();
  QPoint lineOffset=layoutLine.position().toPoint();
  printPoint(blockOffset);
  printPoint(lineOffset);
  QPoint linePoint(blockOffset.x()+lineOffset.x(),blockOffset.y()+lineOffset.y());
  QPoint lineEndPoint=QPoint(linePoint.x()+PAGEWIDTH,linePoint.y());
//  cout<<"block:"<<rect.left()<<","<<rect.right()<<":"<<rect.top()<<","<<rect.bottom();
//  cout<<"blockstart:"<<blockStart;

//  int x=blockPoint.x()+(float)((selectionStart-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH;
//  int y=blockPoint.y()+((selectionStart-blockStart)/LINELENGTH+1)*LINEHEIGHT;
//  int x1=blockPoint.x()+(float)((selectionEnd-blockStart)%LINELENGTH)/LINELENGTH*PAGEWIDTH;
//  cout<<"block position:"<<blockPoint.x()<<","<<blockPoint.y();
//  cout<<"selection position:"<<x<<","<<y<<":"<<x1<<","<<y;
////  int y1=blockPoint.y()+((cursor.selectionEnd()-blockStart)/LINELENGTH+1)*15;
//  QPoint selectionPoint(x,y);
//  QPoint selectionEndPoint(x1,y);
  image->paintLine(linePoint,lineEndPoint);

//  int lineStart=blockStart,lineEnd;
//  for(int i=0;i<block.lineCount();i++){
//  QTextLine line = layout->lineAt(i);
//  qreal lineWidth=line.width(),lineHeight=line.height();
//  lineEnd=lineStart+line.textLength();
//  int a=line.textStart(),b=line.textLength()+a;
//  cout<<"line.cursorToX:"<<line.cursorToX(selectionStart)<<","<<line.cursorToX(selectionEnd);
//  cout<<"line.textstart:"<<a<<","<<b;
//  cout<<"line.width:"<<lineWidth<<" height:"<<lineHeight;
//  rect=line.naturalTextRect();
//  cout<<"line.naturaltextrect:"<<rect.left()<<":"<<rect.top()<<":"<<rect.right()<<":"<<rect.bottom();
//  lineStart=lineEnd;
//  }
}