コード例 #1
0
void CEditorContainer::CreateEditorL(void)
	{
	iEditor = new (ELeave) CEikRichTextEditor;
	iEditor->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
	iEditor->SetContainerWindowL(*this);
	iEditor->SetAvkonWrap(ETrue);
	iEditor->ConstructL(this, 0, 0, 0);

	iEditor->SetFocus(ETrue);
	iEditor->SetReadOnly(EFalse);
	iEditor->EnableCcpuSupportL(ETrue);
	iEditor->SetCursorPosL(0, EFalse);
	iEditor->SetAvkonWrap(ETrue);
	iEditor->SetInputCapabilitiesL(TCoeInputCapabilities::EAllText);
	iEditor->SetAknEditorAllowedInputModes(EAknEditorAllInputModes);
	iEditor->SetAknEditorInputMode(EAknEditorTextInputMode);
	iEditor->SetAknEditorCase(EAknEditorLowerCase);

	//iEditor->SetTextL(&_L("CIAO!!!!"));

	TFontSpec fontspec = LatinBold16()->FontSpecInTwips();
	TCharFormat charFormat(fontspec.iTypeface.iName, fontspec.iHeight);
	TCharFormatMask charFormatMask;

	charFormat.iFontPresentation.iTextColor = KRgbBlack;
	charFormatMask.SetAttrib(EAttColor);

	charFormatMask.SetAttrib(EAttFontTypeface);
	charFormatMask.SetAttrib(EAttFontHeight);
	iEditor->ApplyCharFormatL(charFormat, charFormatMask);

	iEditor->UpdateScrollBarsL();
	SizeChanged();
	}
コード例 #2
0
void CUiLoftAppView::SetTypefaceL(const TDesC& aTypeFace)
{
	TCharFormat charFormat( aTypeFace, 3);
	TCharFormatMask charFormatMask;
	charFormatMask.SetAll();
	iEditor->ApplyCharFormatL(charFormat, charFormatMask);	
	}
コード例 #3
0
ファイル: ktextcursor.cpp プロジェクト: kxtry/kxfw
void KTextCursor::insertHtml( const QString &text, const QMap<QString, QString>& imgs )
{
	if(!imgs.isEmpty())
	{
		for(QMap<QString,QString>::const_iterator iter = imgs.begin(); iter != imgs.end(); iter++)
		{
			QString key = iter.key();
			QString file = iter.value();
			if(moviePool()->insertMovie(file, file))
			{
				//修改属性为动画。
				document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file));
			}
			else
			{
				QImage image(file);
				if(!image.isNull())
				{
					document()->addResource(QTextDocument::ImageResource, QUrl(file), image);
				}
			}
		}
	}

	int istart = position();
	insertHtml(text);
	int inow = position();

	if(!imgs.isEmpty() && inow > istart)
	{
		setPosition(istart);
		movePosition(NextCharacter, KeepAnchor, inow-istart);
		QString txt = selectedText();
		int index = txt.indexOf(QChar::ObjectReplacementCharacter, 0);
		while(index >= 0)
		{
			/*修改字体类型。*/
			setPosition(istart+index);
			movePosition(NextCharacter, KeepAnchor, 1);
			QTextCharFormat fmt = charFormat();			
			QTextImageFormat imgFmt = fmt.toImageFormat();
			QString key = imgFmt.name();
			if(imgs.contains(key))
			{
				imgFmt.setProperty(KImageKey, key);
				imgFmt.setName(imgs.value(key));
				imgFmt.setProperty(KAnimationImage, true);
				setCharFormat(imgFmt);
			}
			int idx = index+1;
			index = txt.indexOf(QChar::ObjectReplacementCharacter, idx);
		}
	}

	setPosition(inow);
}
コード例 #4
0
void PythonQtScriptingConsole::setCurrentFont(const QColor& color, bool bold) {

  QTextCharFormat charFormat(_defaultTextCharacterFormat);

  QFont font(charFormat.font());
  font.setBold(bold);
  charFormat.setFont(font);

  QBrush brush(charFormat.foreground());
  brush.setColor(color);
  charFormat.setForeground(brush);

  setCurrentCharFormat(charFormat);
}
コード例 #5
0
void TextZone::createContent()
{
    //    sounds = new Sounds(this);


    this->setAttribute(Qt::WA_KeyCompression, true);

    textDocument = new MainTextDocument(this);

    createActions();
    setContextMenuPolicy(Qt::DefaultContextMenu);
    connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(charFormat(QTextCharFormat)));
    connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChangedSlot()));

    setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


    applyConfig();
}
コード例 #6
0
ファイル: message_field.cpp プロジェクト: cuiwm/tdesktop
AutocompleteQuery ParseMentionHashtagBotCommandQuery(
		not_null<const Ui::InputField*> field) {
	auto result = AutocompleteQuery();

	const auto cursor = field->textCursor();
	if (cursor.hasSelection()) {
		return result;
	}

	const auto position = cursor.position();
	const auto document = field->document();
	const auto block = document->findBlock(position);
	for (auto item = block.begin(); !item.atEnd(); ++item) {
		const auto fragment = item.fragment();
		if (!fragment.isValid()) {
			continue;
		}

		const auto fragmentPosition = fragment.position();
		const auto fragmentEnd = fragmentPosition + fragment.length();
		if (fragmentPosition >= position || fragmentEnd < position) {
			continue;
		}

		const auto format = fragment.charFormat();
		if (format.isImageFormat()) {
			continue;
		}

		bool mentionInCommand = false;
		const auto text = fragment.text();
		for (auto i = position - fragmentPosition; i != 0; --i) {
			if (text[i - 1] == '@') {
				if ((position - fragmentPosition - i < 1 || text[i].isLetter()) && (i < 2 || !(text[i - 2].isLetterOrNumber() || text[i - 2] == '_'))) {
					result.fromStart = (i == 1) && (fragmentPosition == 0);
					result.query = text.mid(i - 1, position - fragmentPosition - i + 1);
				} else if ((position - fragmentPosition - i < 1 || text[i].isLetter()) && i > 2 && (text[i - 2].isLetterOrNumber() || text[i - 2] == '_') && !mentionInCommand) {
					mentionInCommand = true;
					--i;
					continue;
				}
				return result;
			} else if (text[i - 1] == '#') {
				if (i < 2 || !(text[i - 2].isLetterOrNumber() || text[i - 2] == '_')) {
					result.fromStart = (i == 1) && (fragmentPosition == 0);
					result.query = text.mid(i - 1, position - fragmentPosition - i + 1);
				}
				return result;
			} else if (text[i - 1] == '/') {
				if (i < 2) {
					result.fromStart = (i == 1) && (fragmentPosition == 0);
					result.query = text.mid(i - 1, position - fragmentPosition - i + 1);
				}
				return result;
			}
			if (position - fragmentPosition - i > 127 || (!mentionInCommand && (position - fragmentPosition - i > 63))) {
				break;
			}
			if (!text[i - 1].isLetterOrNumber() && text[i - 1] != '_') {
				break;
			}
		}
		break;
	}
	return result;
}
コード例 #7
0
void ScriptFormatter::setParagraphType( QQuickTextDocument* document, ScriptFormatter::paragraphType newType, int cursorPosition ) {
	
	QTextCursor cursor( document->textDocument()->findBlock( cursorPosition ) );
	
	//cursor.setPosition( cursorPosition, QTextCursor::MoveAnchor);
	cursor.beginEditBlock();
	QTextCharFormat charFormat( cursor.charFormat() );
	QTextBlockFormat blockFormat;
	
	switch( newType ) {
		case paragraphType::SCENE: {
			charFormat.setFont( sceneFont );
			blockFormat = sceneBlockFormat;
			break;
		}
		case paragraphType::ACTION: {
			charFormat.setFont( actionFont );
			blockFormat = actionBlockFormat;
			break;
		}
		case paragraphType::CHARACTER: {
			charFormat.setFont( characterFont );
			blockFormat = characterBlockFormat;
			break;
		}
		case paragraphType::DIALOG: {
			charFormat.setFont( dialogFont );
			blockFormat = dialogBlockFormat;
			break;
		}
		case paragraphType::PARENTHETICAL: {
			charFormat.setFont( parentheticalFont );
			blockFormat = parentheticalBlockFormat;
			
			if( !cursor.block().text().startsWith( '(' ) ) {
				auto position = cursor.position();
				auto start = cursor.selectionStart();
				auto end = cursor.selectionEnd();
				
				cursor.movePosition( QTextCursor::StartOfBlock );
				cursor.insertText( "(" );
				
				/*if( position == end ) {
					cursor.setPosition( start, QTextCursor::MoveAnchor );
					cursor.movePosition( end, QTextCursor::KeepAnchor );
				} else {
					cursor.setPosition( end, QTextCursor::MoveAnchor );
					cursor.movePosition( start, QTextCursor::KeepAnchor );
				}*/
			}
			
			if( !cursor.block().text().endsWith( ')' ) ) {
				auto position = cursor.position();
				auto start = cursor.selectionStart();
				auto end = cursor.selectionEnd();
				
				cursor.movePosition( QTextCursor::EndOfBlock );
				cursor.insertText( ")" );
				
				/*if( position == end ) {
					cursor.setPosition( start, QTextCursor::MoveAnchor );
					cursor.movePosition( end, QTextCursor::KeepAnchor );
				} else {
					cursor.setPosition( end, QTextCursor::MoveAnchor );
					cursor.movePosition( start, QTextCursor::KeepAnchor );
				}*/
			}
			
			break;
		}
		case paragraphType::TRANSITION: {
			charFormat.setFont( transitionFont );
			blockFormat = transitionBlockFormat;
			break;
		}
		case paragraphType::SHOT: {
			charFormat.setFont( shotFont );
			blockFormat = shotBlockFormat;
			break;
		}
		case paragraphType::ACT_BREAK: {
			charFormat.setFont( actBreakFont );
			blockFormat = actBreakBlockFormat;
			break;
		}
	}
	
	cursor.block().setUserState( (uint_fast8_t) newType );
	
	//cursor.select( QTextCursor::BlockUnderCursor ); //For some reason selecting BlockUnderCursor does not work the same as moving from the start to the end of the block
	cursor.movePosition( QTextCursor::StartOfLine, QTextCursor::MoveAnchor );
	cursor.movePosition( QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
	cursor.setCharFormat( charFormat );
	
	cursor.setBlockCharFormat( charFormat );
	cursor.setBlockFormat( blockFormat );
	cursor.endEditBlock();
	//document->textDocument()->setModified( false );
}