[Kde-pim] Right-To-Left (RTL) Support in KMail's Composer

Diego Iastrubni elcuco at kde.org
Mon Jun 1 19:39:28 BST 2009


After some tests... I can say that implementing this feature (RTL support for 
HTML mail in the composer) is quite trivial. I did this on a plain Qt4 
application as I don't have a development environment for KDE4, but in theory 
this should not be that hard to port.

This is part of the code I wrote. It's not perfect, when I change the 
direction of the paragraph, the alignment is not changed on screen, even 
tough that when exporting to HTML I do see the direction+layout saved in the 
correct manner.

== begin code ==
directionGroup = new QActionGroup(this);
actionLTR	 = new QAction( "LTR", directionGroup );
actionRTL	 = new QAction( "RTL", directionGroup );
actionLTR->setCheckable( true );
actionRTL->setCheckable( true );
connect( directionGroup, SIGNAL(triggered(QAction *)), this,
	SLOT(textDirection(QAction *)));
connect( richText, SIGNAL(cursorPositionChanged()), this,
	SLOT(cursorPositionChanged()));

// updates the status of the buttons on the toolbar
void RichTextWidget::cursorPositionChanged()
{
	directionChanged( richText->textCursor().blockFormat().layoutDirection() );
	//.... more stuff
}

// updates the status of the buttons on the toolbar
void RichTextWidget::directionChanged(Qt::LayoutDirection d)
{
	if (d == Qt::RightToLeft)
		actionRTL->setChecked(true);
	else if (d == Qt::LeftToRight)
		actionLTR->setChecked(true);
}

// called from the toobar - sets the new direction for a paragraph
void RichTextWidget::textDirection( QAction *a )
{
	QTextCursor qtc = richText->textCursor();
	QTextBlockFormat qtbf = qtc.blockFormat();
	Qt::Alignment qta = richText->alignment();
	
	if (a == actionLTR)
	{
		qtbf.setLayoutDirection( Qt::LeftToRight );
		qtc.setBlockFormat( qtbf );
		
		if (qta == Qt::AlignRight)
			qta = Qt::AlignLeft;
		else if (qta == Qt::AlignLeft)
			qta = Qt::AlignRight;
	}
	else if (a == actionRTL)
	{
		qtbf.setLayoutDirection( Qt::RightToLeft );
		qtc.setBlockFormat( qtbf );
		
		if (qta == Qt::AlignRight)
			qta = Qt::AlignLeft;
		else if (richText->alignment() == Qt::AlignLeft)
			qta = Qt::AlignRight;
	}
	
	richText->setTextCursor( qtc );
	richText->setAlignment( qta );
}
== end code ==
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list