diff --git a/dictinfo.cc b/dictinfo.cc new file mode 100644 index 00000000..e010d0a2 --- /dev/null +++ b/dictinfo.cc @@ -0,0 +1,39 @@ +#include "dictinfo.hh" +#include "langcoder.hh" +#include "language.hh" +#include "fsencoding.hh" +#include + +DictInfo::DictInfo( QWidget *parent ) +{ + ui.setupUi( this ); +} + +void DictInfo::showInfo( sptr dict ) +{ + setWindowTitle( QString::fromUtf8( dict->getName().data(), dict->getName().size() ) ); + + ui.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) ); + ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) ); + ui.dictionaryTranslatesFrom->setText( Language::localizedStringForId( dict->getLangFrom() ) ); + ui.dictionaryTranslatesTo->setText( Language::localizedStringForId( dict->getLangTo() ) ); + + std::vector< std::string > const & filenames = dict->getDictionaryFilenames(); + + QString filenamesText; + + for( unsigned x = 0; x < filenames.size(); x++ ) + { + filenamesText += FsEncoding::decode( filenames[ x ].c_str() ); + filenamesText += '\n'; + } + + ui.dictionaryFileList->setPlainText( filenamesText ); + + QString info = dict->getDescription(); + + if( !info.isEmpty() && info.compare( "NONE" ) != 0 ) + ui.infoLabel->setPlainText( info ); + else + ui.infoLabel->clear(); +} diff --git a/dictinfo.hh b/dictinfo.hh new file mode 100644 index 00000000..0fbdd6d1 --- /dev/null +++ b/dictinfo.hh @@ -0,0 +1,20 @@ +#ifndef DICTINFO_HH +#define DICTINFO_HH + +#include +#include "ui_dictinfo.h" +#include "dictionary.hh" + +class DictInfo: public QDialog +{ + Q_OBJECT +public: + + DictInfo( QWidget * parent = 0 ); + void showInfo( sptr< Dictionary::Class > dict ); + +private: + Ui::DictInfo ui; +}; + +#endif // DICTINFO_HH diff --git a/dictinfo.ui b/dictinfo.ui new file mode 100644 index 00000000..e116de2b --- /dev/null +++ b/dictinfo.ui @@ -0,0 +1,258 @@ + + + DictInfo + + + + 0 + 0 + 400 + 400 + + + + + + + true + + + + + + + + + + + + Total articles: + + + + + + + + + + + + + + Translates from: + + + + + + + + + + + + + + Total words: + + + + + + + + + + + + + + Translates to: + + + + + + + + + + + + + + + + + Files comprising this dictionary: + + + + + + + + 0 + 65 + + + + + 0 + 65 + + + + + + + + + 224 + 223 + 223 + + + + + + + + + 224 + 223 + 223 + + + + + + + + + 212 + 208 + 200 + + + + + + + + + + + QPlainTextEdit::NoWrap + + + + + + + + + + Description: + + + + + + + + + + + + 224 + 223 + 223 + + + + + + + + + 224 + 223 + 223 + + + + + + + + + 212 + 208 + 200 + + + + + + + + + + + Qt::ScrollBarAlwaysOff + + + true + + + + + + + QDialogButtonBox::Ok + + + true + + + + + + + + + buttonBox + accepted() + DictInfo + accept() + + + 180 + 379 + + + 25 + 791 + + + + + buttonBox + rejected() + DictInfo + reject() + + + 199 + 378 + + + 199 + 199 + + + + + diff --git a/goldendict.pro b/goldendict.pro index 69e17a00..a3336a4a 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -200,7 +200,8 @@ HEADERS += folding.hh \ sdict.hh \ decompress.hh \ aard.hh \ - mruqmenu.hh + mruqmenu.hh \ + dictinfo.hh FORMS += groups.ui \ dictgroupwidget.ui \ mainwindow.ui \ @@ -212,7 +213,8 @@ FORMS += groups.ui \ preferences.ui \ about.ui \ editdictionaries.ui \ - orderandprops.ui + orderandprops.ui \ + dictinfo.ui SOURCES += folding.cc \ main.cc \ dictionary.cc \ @@ -293,7 +295,8 @@ SOURCES += folding.cc \ sdict.cc \ decompress.cc \ aard.cc \ - mruqmenu.cc + mruqmenu.cc \ + dictinfo.cc win32 { SOURCES += mouseover_win32/ThTypes.c \ wordbyauto.cc \ diff --git a/language.cc b/language.cc index d486e6ae..5c44156d 100644 --- a/language.cc +++ b/language.cc @@ -449,4 +449,15 @@ QString countryCodeForId( Id id ) return i->second; } +QString localizedStringForId( Id langId ) +{ + QString name = localizedNameForId( langId ); + + if ( name.isEmpty() ) + return name; + + QString iconId = countryCodeForId( langId ); + + return QString( " %2" ).arg( iconId ).arg( name ); + } } diff --git a/language.hh b/language.hh index 2822dfca..a2d02a3d 100644 --- a/language.hh +++ b/language.hh @@ -34,6 +34,10 @@ QString localizedNameForId( Id ); /// corresponding country it the database, returns an empty strings. QString countryCodeForId( Id ); +/// Returns name for the given Id, translated to the current UI language, wish corresponding image tag. +/// If the Id is incorrect, or has Unknown/Any values, returns empty string. +QString localizedStringForId( Id ); + // All other functions are to be used from LangCoder, which is supposed to // be migrated here over time. diff --git a/mainwindow.cc b/mainwindow.cc index 72a38e01..f4199187 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -20,6 +20,7 @@ #include "dprintf.hh" #include #include +#include "dictinfo.hh" #ifdef Q_OS_MAC #include "lionsupport.h" @@ -100,12 +101,16 @@ MainWindow::MainWindow( Config::Class & cfg_ ): dictsPaneTitleBarLayout.addWidget( &foundInDictsLabel ); dictsPaneTitleBar.setLayout( &dictsPaneTitleBarLayout ); ui.dictsPane->setTitleBarWidget( &dictsPaneTitleBar ); + ui.dictsList->setContextMenuPolicy( Qt::CustomContextMenu ); connect( ui.dictsPane, SIGNAL( visibilityChanged( bool ) ), this, SLOT( dictsPaneVisibilityChanged ( bool ) ) ); connect( ui.dictsList, SIGNAL( itemClicked( QListWidgetItem * ) ), - this, SLOT( dictsPaneClicked( QListWidgetItem * ) ) ); + this, SLOT( foundDictsPaneClicked( QListWidgetItem * ) ) ); + + connect( ui.dictsList, SIGNAL( customContextMenuRequested( const QPoint & ) ), + this, SLOT( foundDictsContextMenuRequested( const QPoint & ) ) ); // Make the toolbar navToolbar = addToolBar( tr( "Navigation" ) ); @@ -2968,7 +2973,7 @@ void MainWindow::switchExpandOptionalPartsMode() view->switchExpandOptionalParts(); } -void MainWindow::dictsPaneClicked( QListWidgetItem * item ) +void MainWindow::foundDictsPaneClicked( QListWidgetItem * item ) { if ( QApplication::keyboardModifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) ) @@ -2978,6 +2983,27 @@ void MainWindow::dictsPaneClicked( QListWidgetItem * item ) } } +void MainWindow::foundDictsContextMenuRequested( const QPoint &pos ) +{ + QListWidgetItem *item = ui.dictsList->itemAt( pos ); + if( item ) + { + QString id = item->data( Qt::UserRole ).toString(); + for( unsigned x = 0; x < dictionaries.size(); x++ ) + { + if( dictionaries[ x ]->getId() == id.toUtf8().data() ) + { + scanPopup.get()->blockSignals( true ); + DictInfo infoMsg; + infoMsg.showInfo( dictionaries[ x ] ); + infoMsg.exec(); + scanPopup.get()->blockSignals( false ); + break; + } + } + } +} + #ifdef Q_OS_WIN32 bool MainWindow::winEvent( MSG * message, long * result ) diff --git a/mainwindow.hh b/mainwindow.hh index f2666800..8b2fcf23 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -194,7 +194,10 @@ private slots: void latestReleaseReplyReady(); /// Receive click on "Found in:" pane - void dictsPaneClicked( QListWidgetItem * item ); + void foundDictsPaneClicked( QListWidgetItem * item ); + + /// Receive right click on "Found in:" pane + void foundDictsContextMenuRequested( const QPoint & pos ); private slots: diff --git a/orderandprops.cc b/orderandprops.cc index 558de715..a88b2d1c 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -78,20 +78,6 @@ void OrderAndProps::disableDictionaryDescription() ui.dictionaryDescriptionLabel->setVisible( false ); } -namespace { - QString makeLangText( Language::Id langId ) - { - QString name = Language::localizedNameForId( langId ); - - if ( name.isEmpty() ) - return name; - - QString iconId = Language::countryCodeForId( 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() ) @@ -106,8 +92,8 @@ void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const 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() ) ); + ui.dictionaryTranslatesFrom->setText( Language::localizedStringForId( dict->getLangFrom() ) ); + ui.dictionaryTranslatesTo->setText( Language::localizedStringForId( dict->getLangTo() ) ); std::vector< std::string > const & filenames = dict->getDictionaryFilenames();