From 8535604e213dcc2e922b63d0829b56b1a2ec0e74 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Sun, 24 May 2009 15:45:37 +0000 Subject: [PATCH] + Implement basic 'Dictionary information' pane functionality. - Hide arrow buttons in 'Dictionaries' for now. + Add 'ja' flag to comply to ISO (copied from 'jp') --- src/flags.qrc | 1 + src/flags/ja.png | Bin 0 -> 420 bytes src/langcoder.cc | 13 +++++ src/langcoder.hh | 2 + src/orderandprops.cc | 77 +++++++++++++++++++++++++ src/orderandprops.hh | 7 +++ src/orderandprops.ui | 132 ++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 src/flags/ja.png diff --git a/src/flags.qrc b/src/flags.qrc index d4492adc..4a9120c1 100644 --- a/src/flags.qrc +++ b/src/flags.qrc @@ -112,6 +112,7 @@ flags/ir.png flags/is.png flags/it.png + flags/ja.png flags/jm.png flags/jo.png flags/jp.png diff --git a/src/flags/ja.png b/src/flags/ja.png new file mode 100644 index 0000000000000000000000000000000000000000..325fbad3ffd3075a4a84d8d898ad26ef7d3e0d56 GIT binary patch literal 420 zcmV;V0bBlwP)9whYk?f=!Q|Ns8||JN@lTD;`{R1ZWk|EGa3dAO8ObDh3E3Cb;oH_5X#1 z|NHy@|M?558b}5Q|Cf`4hZv9q2p|@?lb|{i68>{>{ol0lx`{mi O0000> 8 ) & 0xFF; + + return QString::fromAscii( code, 2 ); +} + quint32 LangCoder::code3toInt(const std::string& code3) { if (code3.length() < 2) diff --git a/src/langcoder.hh b/src/langcoder.hh index 4bd31d03..4322a26d 100644 --- a/src/langcoder.hh +++ b/src/langcoder.hh @@ -224,6 +224,8 @@ public: static quint32 code2toInt(const char code[2]) { return ( ((quint32)code[1]) << 8 ) + (quint32)code[0]; } + static QString intToCode2( quint32 ); + static quint32 code3toInt(const std::string& code3); /// Finds the id for the given language name, written in english. The search diff --git a/src/orderandprops.cc b/src/orderandprops.cc index a43abe44..7df3f353 100644 --- a/src/orderandprops.cc +++ b/src/orderandprops.cc @@ -3,6 +3,7 @@ #include "orderandprops.hh" #include "instances.hh" +#include "langcoder.hh" OrderAndProps::OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder, @@ -13,6 +14,13 @@ OrderAndProps::OrderAndProps( QWidget * parent, { ui.setupUi( this ); + // For now we don't support arrows, so remove them until we get to that + delete ui.moveActiveUp; + delete ui.moveActiveDown; + + delete ui.moveToActive; + delete ui.moveToInactive; + Instances::Group order( dictionaryOrder, allDictionaries ); Instances::Group inactive( inactiveDictionaries, allDictionaries ); @@ -20,6 +28,8 @@ OrderAndProps::OrderAndProps( QWidget * parent, ui.dictionaryOrder->populate( order.dictionaries, allDictionaries ); ui.inactiveDictionaries->populate( inactive.dictionaries, allDictionaries ); + + disableDictionaryDescription(); } Config::Group OrderAndProps::getCurrentDictionaryOrder() const @@ -39,3 +49,70 @@ Config::Group OrderAndProps::getCurrentInactiveDictionaries() const return g.makeConfigGroup(); } + +void OrderAndProps::on_dictionaryOrder_clicked( QModelIndex const & idx ) +{ + describeDictionary( ui.dictionaryOrder, idx ); +} + +void OrderAndProps::on_inactiveDictionaries_clicked( QModelIndex const & idx ) +{ + describeDictionary( ui.inactiveDictionaries, idx ); +} + +void OrderAndProps::disableDictionaryDescription() +{ + ui.dictionaryInformation->setEnabled( false ); + + ui.dictionaryName->clear(); + ui.dictionaryTotalArticles->clear(); + ui.dictionaryTotalWords->clear(); + ui.dictionaryTranslatesFrom->clear(); + ui.dictionaryTranslatesTo->clear(); + ui.dictionaryFileList->clear(); +} + +namespace { + QString makeLangText( quint32 langId ) + { + QString name = LangCoder::decode( langId ); + + if ( name.isEmpty() ) + return name; + + QString iconId = LangCoder::intToCode2( langId ); + + return QString( " %2" ).arg( iconId ).arg( name ); + } +} + +void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx ) +{ + if ( !idx.isValid() || (unsigned) idx.row() >= lst->getCurrentDictionaries().size() ) + disableDictionaryDescription(); + else + { + sptr< Dictionary::Class > dict = lst->getCurrentDictionaries()[ idx.row() ]; + + ui.dictionaryInformation->setEnabled( true ); + + ui.dictionaryName->setText( QString::fromUtf8( dict->getName().c_str() ) ); + + ui.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) ); + ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) ); + ui.dictionaryTranslatesFrom->setText( makeLangText( dict->getLangFrom() ) ); + ui.dictionaryTranslatesTo->setText( makeLangText( dict->getLangTo() ) ); + + std::vector< std::string > const & filenames = dict->getDictionaryFilenames(); + + QString filenamesText; + + for( unsigned x = 0; x < filenames.size(); x++ ) + { + filenamesText += QString::fromLocal8Bit( filenames[ x ].c_str() ); + filenamesText += '\n'; + } + + ui.dictionaryFileList->setPlainText( filenamesText ); + } +} diff --git a/src/orderandprops.hh b/src/orderandprops.hh index d796ba91..9777d6d5 100644 --- a/src/orderandprops.hh +++ b/src/orderandprops.hh @@ -20,10 +20,17 @@ public: Config::Group getCurrentDictionaryOrder() const; Config::Group getCurrentInactiveDictionaries() const; +private slots: + + void on_dictionaryOrder_clicked( QModelIndex const & ); + void on_inactiveDictionaries_clicked( QModelIndex const & ); + private: Ui::OrderAndProps ui; + void disableDictionaryDescription(); + void describeDictionary( DictListWidget *, QModelIndex const & ); }; #endif diff --git a/src/orderandprops.ui b/src/orderandprops.ui index 9646be95..6dd9f2aa 100644 --- a/src/orderandprops.ui +++ b/src/orderandprops.ui @@ -145,7 +145,7 @@ - + Dictionary information @@ -162,7 +162,78 @@ - TextLabel + TextLabel + + + Qt::PlainText + + + + + + + TextLabel + + + Qt::PlainText + + + + + + + Total articles: + + + + + + + Total words: + + + + + + + TextLabel + + + Qt::PlainText + + + + + + + Translates from: + + + + + + + Translates to: + + + + + + + TextLabel + + + Qt::RichText + + + + + + + TextLabel + + + Qt::RichText @@ -194,6 +265,63 @@ + + + + Files comprising this dictionary: + + + + + + + + + + + + 224 + 223 + 222 + + + + + + + + + 224 + 223 + 222 + + + + + + + + + 224 + 223 + 222 + + + + + + + + QFrame::NoFrame + + + Qt::ScrollBarAlwaysOff + + + QPlainTextEdit::NoWrap + + +