コード例 #1
0
void KoPointedAt::fillInLinks(const QTextCursor &cursor, KoInlineTextObjectManager *inlineManager, KoTextRangeManager *rangeManager)
{
    bookmark = 0;
    externalHRef.clear();
    note = 0;

    if (!inlineManager)
        return;

    // Is there an href here ?
    if (cursor.charFormat().isAnchor()) {
        QString href = cursor.charFormat().anchorHref();
        // local href starts with #
        if (href.startsWith("#")) {
            // however bookmark does not contain it, so strip it
            href = href.right(href.size() - 1);

            if (!href.isEmpty()) {
                bookmark = rangeManager->bookmarkManager()->bookmark(href);
            }
            return;
        } else {
            // Nope, then it must be external;
            externalHRef = href;
        }
    } else {
        note = dynamic_cast<KoInlineNote*>(inlineManager->inlineTextObject(cursor));
    }
}
コード例 #2
0
/*!
	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);
        }
    }
}
コード例 #3
0
ファイル: chatedit.cpp プロジェクト: akahan/qutim
QString ChatEdit::textEditToPlainText()
{
	QTextDocument *doc = document();
	QString result;
	result.reserve(doc->characterCount());
	QTextCursor begin(doc);
	QTextCursor end;
	QString specialChar = QChar(QChar::ObjectReplacementCharacter);
	bool first = true;
	while (!begin.atEnd()) {
		end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
		QString postValue;
		bool atEnd = end.isNull();
		if (atEnd) {
			end = QTextCursor(doc);
			QTextBlock block = doc->lastBlock();
			end.setPosition(block.position() + block.length() - 1);
		} else {
			postValue = end.charFormat().toolTip();
		}
		begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
						   end.position() - begin.position() - (atEnd ? 0 : 1));
		QString selectionText = begin.selection().toPlainText();
		if (!first)
			result += selectionText.midRef(1);
		else
			result += selectionText;
		result += postValue;
		begin = end;
		end.clearSelection();
		first = false;
	}
	return result;
}
コード例 #4
0
void
FormText::clearFormat()
{
	QTextCursor c = textCursor();

	if( c.hasSelection() )
	{
		QTextCharFormat fmt = c.charFormat();

		fmt.setFontUnderline( false );
		fmt.setFontItalic( false );
		fmt.setFontWeight( QFont::Normal );
		fmt.setFontPointSize( 10 );

		textCursor().setCharFormat( fmt );
	}
	else
	{
		QFont f = font();
		f.setUnderline( false );
		f.setItalic( false );
		f.setWeight( QFont::Normal );
		f.setPointSize( 10.0 );

		setFont( f );
	}

	QRectF r = boundingRect();
	r.moveTo( pos() );

	d->m_proxy->setRect( r );
}
コード例 #5
0
void
FormText::underline( bool on )
{
	QTextCursor c = textCursor();

	if( c.hasSelection() )
	{
		if( c.position() != c.selectionEnd() )
			c.setPosition( c.selectionEnd() );

		QTextCharFormat fmt = c.charFormat();

		fmt.setFontUnderline( on );

		textCursor().setCharFormat( fmt );
	}
	else
	{
		QFont f = font();

		f.setUnderline( on );

		setFont( f );
	}

	QRectF r = boundingRect();
	r.moveTo( pos() );

	d->m_proxy->setRect( r );
}
コード例 #6
0
void KoTextInlineRdf::attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor)
{
    QTextCharFormat format = cursor.charFormat();
    QVariant v = QVariant::fromValue(inlineRdf);
    format.setProperty(KoCharacterStyle::InlineRdf, v);
    cursor.mergeCharFormat(format);
}
コード例 #7
0
ファイル: docedit.cpp プロジェクト: hermixy/qtplatz
            text_writer( docEdit& e ) : edit( e ) {
                QTextCursor cursor = edit.textCursor();
                cursor.movePosition( QTextCursor::Start );
                mainFrame = cursor.currentFrame();

                plainFormat = cursor.charFormat();
                plainFormat.setFontPointSize( 10 );

                paragraphFormat = plainFormat;
                paragraphFormat.setFontPointSize( 12 );

                headingFormat = plainFormat;
                headingFormat.setFontWeight( QFont::Bold );
                headingFormat.setFontPointSize( 16 );

                empasisFormat = plainFormat;
                empasisFormat.setFontItalic( true );

                tagFormat = plainFormat;
                tagFormat.setForeground( QColor( "#990000" ) );
                tagFormat.setFontUnderline( true );
                
                underlineFormat = plainFormat;
                underlineFormat.setFontUnderline( true );

                frameFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Inset );
                frameFormat.setBorder( 1 );
                frameFormat.setMargin( 10 );
                frameFormat.setPadding( 4 );
            }
コード例 #8
0
ファイル: itemeditorwidget.cpp プロジェクト: amosbird/CopyQ
void ItemEditorWidget::toggleItalicText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontItalic( !format.fontItalic() );
    tc.setCharFormat(format);
}
コード例 #9
0
QT_BEGIN_NAMESPACE

static void formatError(const QFormScriptRunner::Error &error,
                        QTextCursor &cursor)
{
    const QTextCharFormat oldFormat = cursor.charFormat();
    // Message
    cursor.insertText(QCoreApplication::translate("ScriptErrorDialog", "An error occurred while running the scripts for \"%1\":\n").arg(error.objectName));

    QTextCharFormat format(oldFormat);

    // verbatim listing
    format.setFontFamily(QLatin1String("Courier"));
    cursor.insertText(error.script, format);

    const QString newLine(QLatin1Char('\n'));

    cursor.insertText(newLine);

    // red error
    format = oldFormat;
    format.setTextOutline(QPen(Qt::red));
    cursor.insertText(error.errorMessage, format);
    cursor.insertText(newLine);
    cursor.setCharFormat (oldFormat);
}
コード例 #10
0
ファイル: caret.cpp プロジェクト: Narsil/QWave
QString CaretInterface::caretOwner(const QTextCursor& cursor)
{
    QTextCharFormat fmt = cursor.charFormat();
    if ( fmt.objectType() == CaretFormat )
        return fmt.property(Owner).toString();
    return QString::null;
}
コード例 #11
0
/*! Append a new message to the current session and scroll to the end of the message protocol and
    returns true if the action was successful. The \a messageColor defines the color of the message
    box and should be provided as a full-color (no dimming required) color, as it is automatically
    adjusted for the border and background.
*/
bool QwcPrivateMessager::appendMessageToCurrentSession(QTextDocument *document, const QString message, const QColor messageColor)
{
    if (!document) { return false; }

    QTextCursor cursor = document->rootFrame()->lastCursorPosition();
    cursor.movePosition(QTextCursor::StartOfBlock);

    QTextFrameFormat frameFormat;
    frameFormat.setPadding(4);
    frameFormat.setBackground(messageColor.lighter(190));
    frameFormat.setMargin(0);
    frameFormat.setBorder(2);
    frameFormat.setBorderBrush(messageColor.lighter(150));
    frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Outset);

    // Title
    QTextCharFormat backupCharFormat = cursor.charFormat();

    QTextCharFormat newCharFormat;
    newCharFormat.setFontPointSize(9);

    QTextBlockFormat headerFormat;
    headerFormat.setAlignment(Qt::AlignHCenter);
    cursor.insertBlock(headerFormat);
    cursor.setCharFormat(newCharFormat);
    cursor.insertText(QDateTime::currentDateTime().toString());

    QTextFrame *frame = cursor.insertFrame(frameFormat);
    cursor.setCharFormat(backupCharFormat);
    frame->firstCursorPosition().insertText(message);

    return true;
}
コード例 #12
0
void TextZone::cursorPositionChangedSlot()
{
    if (QApplication::mouseButtons() == Qt::NoButton) {
        centerCursor();
    }


    emit cursorPositionChanged(this->textCursor().position());



    // for textstyle :
    QTextCursor tCursor = this->textCursor();

    if((tCursor.atStart() == true
        || tCursor.position() == 1
        || tCursor.position() == 0) && tCursor.hasSelection() == false){
        this->changeTextStyleSlot(textStyles->defaultStyleIndex());
    }

    int currentStyleIndex = textStyles->compareStylesWithText(tCursor.charFormat(), tCursor.blockFormat());

    emit setStyleSelectionSignal(currentStyleIndex);


}
コード例 #13
0
ファイル: itemeditorwidget.cpp プロジェクト: amosbird/CopyQ
void ItemEditorWidget::toggleUnderlineText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontUnderline( !format.fontUnderline() );
    tc.setCharFormat(format);
}
コード例 #14
0
ファイル: itemeditorwidget.cpp プロジェクト: amosbird/CopyQ
void ItemEditorWidget::toggleStrikethroughText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontStrikeOut( !format.fontStrikeOut() );
    tc.setCharFormat(format);
}
コード例 #15
0
QString DocumentHandler::fontFamily() const
{
    QTextCursor cursor = textCursor();
    if (cursor.isNull())
        return QString();
    QTextCharFormat format = cursor.charFormat();
    return format.font().family();
}
コード例 #16
0
QColor DocumentHandler::textColor() const
{
    QTextCursor cursor = textCursor();
    if (cursor.isNull())
        return QColor(Qt::black);
    QTextCharFormat format = cursor.charFormat();
    return format.foreground().color();
}
コード例 #17
0
int DocumentHandler::fontSize() const
{
    QTextCursor cursor = textCursor();
    if (cursor.isNull())
        return 0;
    QTextCharFormat format = cursor.charFormat();
    return format.font().pointSize();
}
コード例 #18
0
ファイル: itemeditorwidget.cpp プロジェクト: amosbird/CopyQ
void ItemEditorWidget::toggleBoldText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    const int weight = format.fontWeight() == QFont::Bold ? QFont::Normal : QFont::Bold;
    format.setFontWeight(weight);
    tc.setCharFormat(format);
}
コード例 #19
0
ファイル: utils.cpp プロジェクト: Ficer/rockbox
void MyTextEditor::OnTextBold(bool checked)
{
    QTextCursor cursor = m_edit->textCursor();
    QTextCharFormat fmt = cursor.charFormat();
    fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
    cursor.setCharFormat(fmt);
    m_edit->setTextCursor(cursor);
}
コード例 #20
0
ファイル: utils.cpp プロジェクト: Ficer/rockbox
void MyTextEditor::OnTextUnderline(bool checked)
{
    QTextCursor cursor = m_edit->textCursor();
    QTextCharFormat fmt = cursor.charFormat();
    fmt.setFontUnderline(checked);
    cursor.setCharFormat(fmt);
    m_edit->setTextCursor(cursor);
}
コード例 #21
0
 void changeChar(int pos, QChar c)
 {
     QTextCursor cur = te_->textCursor();
     cur.setPosition(pos+1);
     const QTextCharFormat cf = cur.charFormat();
     cur.deletePreviousChar();
     cur.setCharFormat(cf);
     cur.insertText(c);
 }
コード例 #22
0
ファイル: maileditorwindow.cpp プロジェクト: toby82/keyhotee
void MailEditorMainWindow::onCursorPositionChanged()
  {
  /** When cursor pos. changes update alignment & text formatting controls according to format
      of text under cursor.
  */
  alignmentChanged(ui->messageEdit->alignment());
  QTextCursor cursor = ui->messageEdit->textCursor();
  fontChanged(cursor.charFormat().font());
  }
コード例 #23
0
void FillCellHelper::fill( QTextTable* textTable, KDReports::ReportBuilder& builder, QTextDocument& textDoc, QTextTableCell& cell )
{
    cellCursor = cell.firstCursorPosition();
    QTextCharFormat cellFormat = cell.format();
    if ( background.isValid() ) {
        cellFormat.setBackground( background );
    }
    cellFormat.setVerticalAlignment( toVerticalAlignment( alignment ) );
    cell.setFormat( cellFormat );

    QTextBlockFormat blockFormat = cellCursor.blockFormat();
    blockFormat.setAlignment( alignment );
    blockFormat.setNonBreakableLines( nonBreakableLines );
    builder.setupBlockFormat( blockFormat );

    cellCursor.setBlockFormat( blockFormat );

    const bool hasIcon = !cellDecoration.isNull();
    const bool iconAfterText = decorationAlignment.isValid() && ( decorationAlignment.toInt() & Qt::AlignRight );
    if ( hasIcon && !iconAfterText ) {
        insertDecoration( builder, textDoc );
    }

    QTextCharFormat charFormat = cellCursor.charFormat();
    if ( cellFont.isValid() ) {
        QFont cellQFont = qvariant_cast<QFont>( cellFont );
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
        charFormat.setFont( cellQFont, QTextCharFormat::FontPropertiesSpecifiedOnly );
#else
        charFormat.setFont( cellQFont );
#endif
    } else {
        charFormat.setFont( builder.defaultFont() );
    }
    if ( foreground.isValid() )
        charFormat.setForeground( foreground );
    cellCursor.setCharFormat( charFormat );

    if ( hasIcon && !iconAfterText ) {
        cellCursor.insertText( QChar::fromLatin1( ' ' ) ); // spacing between icon and text
    }

    //qDebug() << cellText;
    if (cellText.startsWith(QLatin1String("<qt>")) || cellText.startsWith(QLatin1String("<html>")))
        cellCursor.insertHtml( cellText );
    else
        cellCursor.insertText( cellText );

    if ( hasIcon && iconAfterText ) {
        cellCursor.insertText( QChar::fromLatin1( ' ' ) ); // spacing between icon and text
        insertDecoration( builder, textDoc );
    }

    if ( span.width() > 1 || span.height() > 1 )
        textTable->mergeCells( cell.row(), cell.column(), span.height(), span.width() );
}
コード例 #24
0
ファイル: note.cpp プロジェクト: bacchante95/fritzing
bool Note::eventFilter(QObject * object, QEvent * event)
{
	if (event->type() == QEvent::Shortcut || event->type() == QEvent::ShortcutOverride)
	{
		if (!object->inherits("QGraphicsView"))
		{
			event->accept();
			return true;
		}
	}

	if (event->type() == QEvent::KeyPress) {
		QKeyEvent * kevent = static_cast<QKeyEvent *>(event);
		if (kevent->matches(QKeySequence::Bold)) {
			QTextCursor textCursor = m_graphicsTextItem->textCursor();
			QTextCharFormat cf = textCursor.charFormat();
			bool isBold = cf.fontWeight() == QFont::Bold;
			QTextCharFormat textCharFormat;
			textCharFormat.setFontWeight(isBold ? QFont::Normal : QFont::Bold);
			textCursor.mergeCharFormat(textCharFormat);
			event->accept();
			return true;
		}
		if (kevent->matches(QKeySequence::Italic)) {
			QTextCursor textCursor = m_graphicsTextItem->textCursor();
			QTextCharFormat cf = textCursor.charFormat();
			QTextCharFormat textCharFormat;
			textCharFormat.setFontItalic(!cf.fontItalic());
			textCursor.mergeCharFormat(textCharFormat);
			event->accept();
			return true;
		}
		if ((kevent->key() == Qt::Key_L) && (kevent->modifiers() & Qt::ControlModifier)) {
			QTimer::singleShot(75, this, SLOT(linkDialog()));
			event->accept();
			return true;

		}
	}
	return false;
}
コード例 #25
0
ファイル: chatview.cpp プロジェクト: Akira586/Cockatrice
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
{
    QTextCharFormat oldFormat = cursor.charFormat();
    QTextCharFormat anchorFormat = oldFormat;
    anchorFormat.setForeground(Qt::blue);
    anchorFormat.setAnchor(true);
    anchorFormat.setAnchorHref("card://" + cardName);
    
    cursor.setCharFormat(anchorFormat);
    cursor.insertText(cardName);
    cursor.setCharFormat(oldFormat);
}
コード例 #26
0
ファイル: textroom.cpp プロジェクト: AlanLZY/textroom
void TextRoom::textBold()
{
	QTextCharFormat fmt;
	QTextCursor cursor = textEdit->textCursor();
	if (cursor.charFormat().fontWeight() == 75)
	{
		fmt.setFontWeight(50);
	}
	else
	{
		fmt.setFontWeight(75);
	}
	mergeFormatOnWordOrSelection(fmt);
}
コード例 #27
0
ファイル: textroom.cpp プロジェクト: AlanLZY/textroom
void TextRoom::textItalic()
{
	QTextCharFormat fmt;
	QTextCursor cursor = textEdit->textCursor();
	if (cursor.charFormat().fontItalic())
	{
		fmt.setFontItalic(false);
	}
	else
	{
		fmt.setFontItalic(true);
	}
	mergeFormatOnWordOrSelection(fmt);
}
コード例 #28
0
void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const
{
    if (_cursor.isNull())
        return;

    QTextDocumentPrivate *destPieceTable = _cursor.d->priv;
    destPieceTable->beginEditBlock();

    QTextCursor sourceCursor(doc);
    sourceCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy();

    destPieceTable->endEditBlock();
}
コード例 #29
0
ファイル: pagebreakentry.cpp プロジェクト: KDE/cantor
PageBreakEntry::PageBreakEntry(Worksheet* worksheet)
  : WorksheetEntry(worksheet)
{
    m_msgItem = new WorksheetTextItem(this);

    QTextCursor cursor = m_msgItem->textCursor();
    KColorScheme color = KColorScheme(QPalette::Normal, KColorScheme::View);
    QTextCharFormat cformat(cursor.charFormat());
    cformat.setForeground(color.foreground(KColorScheme::InactiveText));

    cursor.insertText(i18n("--- Page Break ---"), cformat);

    setFlag(QGraphicsItem::ItemIsFocusable);
}
コード例 #30
0
ファイル: itemeditorwidget.cpp プロジェクト: amosbird/CopyQ
void ItemEditorWidget::setFont()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();

    QFontDialog dialog(this);
    dialog.setCurrentFont( format.font() );

    if ( dialog.exec() == QDialog::Accepted ) {
        const QFont font = dialog.selectedFont();
        format.setFont(font);
        tc.setCharFormat(format);
    }
}