Refactor work with RTL languages in word search list and history list

This commit is contained in:
Abs62 2013-07-06 19:31:31 +04:00
parent f202cb422e
commit 89755f8c09
7 changed files with 59 additions and 7 deletions

19
delegate.cc Normal file
View file

@ -0,0 +1,19 @@
#include <QStyleOptionViewItemV4>
#include "delegate.hh"
WordListItemDelegate::WordListItemDelegate( QAbstractItemDelegate * delegate ) :
QStyledItemDelegate()
{
mainDelegate = static_cast< QStyledItemDelegate * >( delegate );
}
void WordListItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QStyleOptionViewItemV4 opt4 = option;
QStyleOptionViewItem opt = option;
initStyleOption( &opt4, index );
if( opt4.text.isRightToLeft() )
opt.direction = Qt::RightToLeft;
mainDelegate->paint( painter, opt, index );
}

18
delegate.hh Normal file
View file

@ -0,0 +1,18 @@
#ifndef __DELEGATE_HH_INCLUDED__
#define __DELEGATE_HH_INCLUDED__
#include <QAbstractItemDelegate>
#include <QStyledItemDelegate>
class WordListItemDelegate : public QStyledItemDelegate
{
public:
WordListItemDelegate( QAbstractItemDelegate * delegate );
virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
private:
QStyledItemDelegate * mainDelegate;
};
#endif

View file

@ -242,7 +242,8 @@ HEADERS += folding.hh \
mdx.hh \ mdx.hh \
voiceengines.hh \ voiceengines.hh \
ffmpegaudio.hh \ ffmpegaudio.hh \
articleinspector.hh articleinspector.hh \
delegate.hh
FORMS += groups.ui \ FORMS += groups.ui \
dictgroupwidget.ui \ dictgroupwidget.ui \
@ -350,7 +351,8 @@ SOURCES += folding.cc \
mdx.cc \ mdx.cc \
voiceengines.cc \ voiceengines.cc \
ffmpegaudio.cc \ ffmpegaudio.cc \
articleinspector.cc articleinspector.cc \
delegate.cc
win32 { win32 {
FORMS += texttospeechsource.ui FORMS += texttospeechsource.ui

View file

@ -87,6 +87,14 @@ void HistoryPaneWidget::setUp( Config::Class * cfg, History * history, QMenu *
connect( m_historyList, SIGNAL( customContextMenuRequested( QPoint const & ) ), connect( m_historyList, SIGNAL( customContextMenuRequested( QPoint const & ) ),
this, SLOT( showCustomMenu( QPoint const & ) ) ); this, SLOT( showCustomMenu( QPoint const & ) ) );
listItemDelegate = new WordListItemDelegate( m_historyList->itemDelegate() );
m_historyList->setItemDelegate( listItemDelegate );
}
HistoryPaneWidget::~HistoryPaneWidget()
{
if( listItemDelegate )
delete listItemDelegate;
} }
void HistoryPaneWidget::copySelectedItems() void HistoryPaneWidget::copySelectedItems()

View file

@ -14,6 +14,7 @@
#include <config.hh> #include <config.hh>
#include "history.hh" #include "history.hh"
#include "delegate.hh"
/// A widget holding the contents of the 'History' docklet. /// A widget holding the contents of the 'History' docklet.
class HistoryPaneWidget : public QWidget class HistoryPaneWidget : public QWidget
@ -22,7 +23,9 @@ class HistoryPaneWidget : public QWidget
public: public:
explicit HistoryPaneWidget( QWidget * parent = 0 ): QWidget( parent ), explicit HistoryPaneWidget( QWidget * parent = 0 ): QWidget( parent ),
itemSelectionChanged( false ) itemSelectionChanged( false )
, listItemDelegate( 0 )
{} {}
virtual ~HistoryPaneWidget();
virtual QSize sizeHint() const virtual QSize sizeHint() const
{ return QSize( 204, 204 ); } { return QSize( 204, 204 ); }
@ -63,6 +66,7 @@ private:
/// when selecting history items via mouse and keyboard /// when selecting history items via mouse and keyboard
bool itemSelectionChanged; bool itemSelectionChanged;
WordListItemDelegate * listItemDelegate;
}; };
class HistoryModel : public QAbstractListModel class HistoryModel : public QAbstractListModel

View file

@ -6,9 +6,11 @@
#include "wordlist.hh" #include "wordlist.hh"
WordList::WordList( QWidget * parent ) : QListWidget( parent ) WordList::WordList( QWidget * parent ) : QListWidget( parent )
, listItemDelegate( itemDelegate() )
{ {
wordFinder = 0; wordFinder = 0;
translateLine = 0; translateLine = 0;
setItemDelegate( &listItemDelegate );
} }
void WordList::attachFinder( WordFinder * finder ) void WordList::attachFinder( WordFinder * finder )
@ -78,9 +80,7 @@ void WordList::updateMatchResults( bool finished )
i->setFont( f ); i->setFont( f );
} }
} }
if (i->text().at(0).direction() == QChar::DirR)
i->setTextAlignment(Qt::AlignRight);
if (i->text().at(0).direction() == QChar::DirL)
i->setTextAlignment(Qt::AlignLeft); i->setTextAlignment(Qt::AlignLeft);
} }
@ -132,4 +132,3 @@ void WordList::refreshTranslateLine()
} }
} }

View file

@ -8,6 +8,7 @@
#include <QLineEdit> #include <QLineEdit>
#include "wordfinder.hh" #include "wordfinder.hh"
#include "delegate.hh"
class WordList : public QListWidget class WordList : public QListWidget
{ {
@ -34,6 +35,7 @@ private:
WordFinder * wordFinder; WordFinder * wordFinder;
QLineEdit * translateLine; QLineEdit * translateLine;
WordListItemDelegate listItemDelegate;
}; };
#endif // WORDLIST_HH #endif // WORDLIST_HH