Show information about a dictionary on rigth mouse click in "Found in" pane

This commit is contained in:
Abs62 2012-09-24 16:51:51 +04:00
parent 405c2b50ee
commit 34419706c9
9 changed files with 372 additions and 22 deletions

39
dictinfo.cc Normal file
View file

@ -0,0 +1,39 @@
#include "dictinfo.hh"
#include "langcoder.hh"
#include "language.hh"
#include "fsencoding.hh"
#include <QString>
DictInfo::DictInfo( QWidget *parent )
{
ui.setupUi( this );
}
void DictInfo::showInfo( sptr<Dictionary::Class> 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();
}

20
dictinfo.hh Normal file
View file

@ -0,0 +1,20 @@
#ifndef DICTINFO_HH
#define DICTINFO_HH
#include <QDialog>
#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

258
dictinfo.ui Normal file
View file

@ -0,0 +1,258 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DictInfo</class>
<widget class="QDialog" name="DictInfo">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Total articles:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="dictionaryTotalArticles">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Translates from:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="dictionaryTranslatesFrom">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Total words:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="dictionaryTotalWords">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Translates to:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="dictionaryTranslatesTo">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Files comprising this dictionary:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="dictionaryFileList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>65</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>65</height>
</size>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>224</red>
<green>223</green>
<blue>223</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>224</red>
<green>223</green>
<blue>223</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>212</red>
<green>208</green>
<blue>200</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="plainText">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="dictionaryDescriptionLabel">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="infoLabel">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>224</red>
<green>223</green>
<blue>223</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>224</red>
<green>223</green>
<blue>223</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>212</red>
<green>208</green>
<blue>200</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DictInfo</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>180</x>
<y>379</y>
</hint>
<hint type="destinationlabel">
<x>25</x>
<y>791</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DictInfo</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>378</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>199</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -200,7 +200,8 @@ HEADERS += folding.hh \
sdict.hh \ sdict.hh \
decompress.hh \ decompress.hh \
aard.hh \ aard.hh \
mruqmenu.hh mruqmenu.hh \
dictinfo.hh
FORMS += groups.ui \ FORMS += groups.ui \
dictgroupwidget.ui \ dictgroupwidget.ui \
mainwindow.ui \ mainwindow.ui \
@ -212,7 +213,8 @@ FORMS += groups.ui \
preferences.ui \ preferences.ui \
about.ui \ about.ui \
editdictionaries.ui \ editdictionaries.ui \
orderandprops.ui orderandprops.ui \
dictinfo.ui
SOURCES += folding.cc \ SOURCES += folding.cc \
main.cc \ main.cc \
dictionary.cc \ dictionary.cc \
@ -293,7 +295,8 @@ SOURCES += folding.cc \
sdict.cc \ sdict.cc \
decompress.cc \ decompress.cc \
aard.cc \ aard.cc \
mruqmenu.cc mruqmenu.cc \
dictinfo.cc
win32 { win32 {
SOURCES += mouseover_win32/ThTypes.c \ SOURCES += mouseover_win32/ThTypes.c \
wordbyauto.cc \ wordbyauto.cc \

View file

@ -449,4 +449,15 @@ QString countryCodeForId( Id id )
return i->second; return i->second;
} }
QString localizedStringForId( Id langId )
{
QString name = localizedNameForId( langId );
if ( name.isEmpty() )
return name;
QString iconId = countryCodeForId( langId );
return QString( "<img src=\":/flags/%1.png\"> %2" ).arg( iconId ).arg( name );
}
} }

View file

@ -34,6 +34,10 @@ QString localizedNameForId( Id );
/// corresponding country it the database, returns an empty strings. /// corresponding country it the database, returns an empty strings.
QString countryCodeForId( Id ); 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 // All other functions are to be used from LangCoder, which is supposed to
// be migrated here over time. // be migrated here over time.

View file

@ -20,6 +20,7 @@
#include "dprintf.hh" #include "dprintf.hh"
#include <QDebug> #include <QDebug>
#include <QTextStream> #include <QTextStream>
#include "dictinfo.hh"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include "lionsupport.h" #include "lionsupport.h"
@ -100,12 +101,16 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
dictsPaneTitleBarLayout.addWidget( &foundInDictsLabel ); dictsPaneTitleBarLayout.addWidget( &foundInDictsLabel );
dictsPaneTitleBar.setLayout( &dictsPaneTitleBarLayout ); dictsPaneTitleBar.setLayout( &dictsPaneTitleBarLayout );
ui.dictsPane->setTitleBarWidget( &dictsPaneTitleBar ); ui.dictsPane->setTitleBarWidget( &dictsPaneTitleBar );
ui.dictsList->setContextMenuPolicy( Qt::CustomContextMenu );
connect( ui.dictsPane, SIGNAL( visibilityChanged( bool ) ), connect( ui.dictsPane, SIGNAL( visibilityChanged( bool ) ),
this, SLOT( dictsPaneVisibilityChanged ( bool ) ) ); this, SLOT( dictsPaneVisibilityChanged ( bool ) ) );
connect( ui.dictsList, SIGNAL( itemClicked( QListWidgetItem * ) ), 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 // Make the toolbar
navToolbar = addToolBar( tr( "Navigation" ) ); navToolbar = addToolBar( tr( "Navigation" ) );
@ -2968,7 +2973,7 @@ void MainWindow::switchExpandOptionalPartsMode()
view->switchExpandOptionalParts(); view->switchExpandOptionalParts();
} }
void MainWindow::dictsPaneClicked( QListWidgetItem * item ) void MainWindow::foundDictsPaneClicked( QListWidgetItem * item )
{ {
if ( QApplication::keyboardModifiers() & if ( QApplication::keyboardModifiers() &
( Qt::ControlModifier | Qt::ShiftModifier ) ) ( 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 #ifdef Q_OS_WIN32
bool MainWindow::winEvent( MSG * message, long * result ) bool MainWindow::winEvent( MSG * message, long * result )

View file

@ -194,7 +194,10 @@ private slots:
void latestReleaseReplyReady(); void latestReleaseReplyReady();
/// Receive click on "Found in:" pane /// 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: private slots:

View file

@ -78,20 +78,6 @@ void OrderAndProps::disableDictionaryDescription()
ui.dictionaryDescriptionLabel->setVisible( false ); 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( "<img src=\":/flags/%1.png\"> %2" ).arg( iconId ).arg( name );
}
}
void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx ) void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx )
{ {
if ( !idx.isValid() || (unsigned) idx.row() >= lst->getCurrentDictionaries().size() ) 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.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) );
ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) ); ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) );
ui.dictionaryTranslatesFrom->setText( makeLangText( dict->getLangFrom() ) ); ui.dictionaryTranslatesFrom->setText( Language::localizedStringForId( dict->getLangFrom() ) );
ui.dictionaryTranslatesTo->setText( makeLangText( dict->getLangTo() ) ); ui.dictionaryTranslatesTo->setText( Language::localizedStringForId( dict->getLangTo() ) );
std::vector< std::string > const & filenames = dict->getDictionaryFilenames(); std::vector< std::string > const & filenames = dict->getDictionaryFilenames();