mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Show dictionary info on right click in groups edit dialog
This commit is contained in:
parent
193eb556ea
commit
9c9faff6f6
|
@ -5,9 +5,9 @@
|
|||
#include <QString>
|
||||
|
||||
DictInfo::DictInfo( Config::Class &cfg_, QWidget *parent ) :
|
||||
cfg( cfg_)
|
||||
QDialog( parent),
|
||||
cfg( cfg_)
|
||||
{
|
||||
(void) parent;
|
||||
ui.setupUi( this );
|
||||
if( cfg.dictInfoGeometry.size() > 0 )
|
||||
restoreGeometry( cfg.dictInfoGeometry );
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "editdictionaries.hh"
|
||||
#include "loaddictionaries.hh"
|
||||
#include "dictinfo.hh"
|
||||
#include <QMessageBox>
|
||||
|
||||
using std::vector;
|
||||
|
@ -46,6 +47,9 @@ EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,
|
|||
this, SLOT( buttonBoxClicked( QAbstractButton * ) ) );
|
||||
|
||||
connect( &sources, SIGNAL( rescan() ), this, SLOT( rescanSources() ) );
|
||||
|
||||
connect( groups.get(), SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SLOT( showDictionaryInfo(QString const & ) ) );
|
||||
}
|
||||
|
||||
void EditDictionaries::editGroup( unsigned id )
|
||||
|
@ -232,3 +236,16 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
|||
}
|
||||
}
|
||||
|
||||
void EditDictionaries::showDictionaryInfo( QString const & dictId )
|
||||
{
|
||||
unsigned n;
|
||||
for( n = 0; n < dictionaries.size(); n++ )
|
||||
if( dictId.compare( QString::fromUtf8( dictionaries[ n ]->getId().c_str() ) ) == 0 )
|
||||
break;
|
||||
if( n < dictionaries.size() )
|
||||
{
|
||||
DictInfo infoMsg( cfg, this );
|
||||
infoMsg.showInfo( dictionaries[ n ] );
|
||||
infoMsg.exec();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ private slots:
|
|||
|
||||
void rescanSources();
|
||||
|
||||
void showDictionaryInfo( QString const & dictId );
|
||||
|
||||
private:
|
||||
|
||||
bool isSourcesChanged() const;
|
||||
|
|
26
groups.cc
26
groups.cc
|
@ -43,6 +43,12 @@ Groups::Groups( QWidget * parent,
|
|||
this, SLOT( removeFromGroup() ) );
|
||||
connect( ui.autoGroups, SIGNAL( clicked() ),
|
||||
this, SLOT( addAutoGroups() ) );
|
||||
connect( ui.groups, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SIGNAL( showDictionaryInfo( QString const & ) ) );
|
||||
|
||||
ui.dictionaries->setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
connect( ui.dictionaries, SIGNAL( customContextMenuRequested( QPoint ) ),
|
||||
this, SLOT( showDictInfo( QPoint ) ) );
|
||||
|
||||
countChanged();
|
||||
}
|
||||
|
@ -175,3 +181,23 @@ void Groups::removeFromGroup()
|
|||
ui.groups->getCurrentModel()->removeSelectedRows( ui.groups->getCurrentSelectionModel() );
|
||||
}
|
||||
}
|
||||
|
||||
void Groups::showDictInfo( QPoint const & pos )
|
||||
{
|
||||
QVariant data = ui.dictionaries->getModel()->data( ui.dictionaries->indexAt( pos ), Qt::EditRole );
|
||||
QString id;
|
||||
if( data.canConvert< QString >() )
|
||||
id = data.toString();
|
||||
|
||||
if( !id.isEmpty() )
|
||||
{
|
||||
vector< sptr< Dictionary::Class > > const & dicts = ui.dictionaries->getCurrentDictionaries();
|
||||
unsigned n;
|
||||
for( n = 0; n < dicts.size(); n++ )
|
||||
if( id.compare( QString::fromUtf8( dicts.at( n )->getId().c_str() ) ) == 0 )
|
||||
break;
|
||||
if( n < dicts.size() )
|
||||
emit showDictionaryInfo( id );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,10 @@ private slots:
|
|||
void addToGroup();
|
||||
void removeFromGroup();
|
||||
void addAutoGroups();
|
||||
void showDictInfo( const QPoint & pos );
|
||||
|
||||
signals:
|
||||
void showDictionaryInfo( QString const & id );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -63,6 +63,10 @@ DictGroupWidget::DictGroupWidget( QWidget * parent,
|
|||
|
||||
connect( ui.groupIcon, SIGNAL(activated(int)),this,SLOT(groupIconActivated(int)),
|
||||
Qt::QueuedConnection );
|
||||
|
||||
ui.dictionaries->setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
connect( ui.dictionaries, SIGNAL( customContextMenuRequested( QPoint ) ),
|
||||
this, SLOT( showDictInfo( QPoint ) ) );
|
||||
}
|
||||
|
||||
void DictGroupWidget::groupIconActivated( int index )
|
||||
|
@ -123,6 +127,25 @@ Config::Group DictGroupWidget::makeGroup() const
|
|||
return g.makeConfigGroup();
|
||||
}
|
||||
|
||||
void DictGroupWidget::showDictInfo( QPoint const & pos )
|
||||
{
|
||||
QVariant data = ui.dictionaries->getModel()->data( ui.dictionaries->indexAt( pos ), Qt::EditRole );
|
||||
QString id;
|
||||
if( data.canConvert< QString >() )
|
||||
id = data.toString();
|
||||
|
||||
if( !id.isEmpty() )
|
||||
{
|
||||
vector< sptr< Dictionary::Class > > const & dicts = ui.dictionaries->getCurrentDictionaries();
|
||||
unsigned n;
|
||||
for( n = 0; n < dicts.size(); n++ )
|
||||
if( id.compare( QString::fromUtf8( dicts.at( n )->getId().c_str() ) ) == 0 )
|
||||
break;
|
||||
if( n < dicts.size() )
|
||||
emit showDictionaryInfo( id );
|
||||
}
|
||||
}
|
||||
|
||||
/// DictListModel
|
||||
|
||||
void DictListModel::populate(
|
||||
|
@ -170,6 +193,9 @@ int DictListModel::rowCount( QModelIndex const & ) const
|
|||
|
||||
QVariant DictListModel::data( QModelIndex const & index, int role ) const
|
||||
{
|
||||
if( index.row() < 0 )
|
||||
return QVariant();
|
||||
|
||||
sptr< Dictionary::Class > const & item = dictionaries[ index.row() ];
|
||||
|
||||
if ( !item )
|
||||
|
@ -516,7 +542,12 @@ void DictGroupsWidget::populate( Config::Groups const & groups,
|
|||
activeDicts = &activeDicts_;
|
||||
|
||||
for( int x = 0; x < groups.size(); ++x )
|
||||
addTab( new DictGroupWidget( this, *allDicts, groups[ x ] ), escapeAmps( groups[ x ].name ) );
|
||||
{
|
||||
DictGroupWidget *gr = new DictGroupWidget( this, *allDicts, groups[ x ] );
|
||||
addTab( gr, escapeAmps( groups[ x ].name ) );
|
||||
connect( gr, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SIGNAL( showDictionaryInfo( QString const & ) ) );
|
||||
}
|
||||
|
||||
nextId = groups.nextId;
|
||||
|
||||
|
@ -577,9 +608,10 @@ void DictGroupsWidget::addNewGroup( QString const & name )
|
|||
|
||||
newGroup.id = nextId++;
|
||||
|
||||
insertTab( idx,
|
||||
new DictGroupWidget( this, *allDicts, newGroup ),
|
||||
escapeAmps( name ) );
|
||||
DictGroupWidget *gr = new DictGroupWidget( this, *allDicts, newGroup );
|
||||
insertTab( idx, gr, escapeAmps( name ) );
|
||||
connect( gr, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SIGNAL( showDictionaryInfo( QString const & ) ) );
|
||||
|
||||
setCurrentIndex( idx );
|
||||
|
||||
|
|
|
@ -118,10 +118,14 @@ public:
|
|||
private slots:
|
||||
|
||||
void groupIconActivated( int );
|
||||
void showDictInfo( const QPoint & pos );
|
||||
|
||||
private:
|
||||
Ui::DictGroupWidget ui;
|
||||
unsigned groupId;
|
||||
|
||||
signals:
|
||||
void showDictionaryInfo( QString const & id );
|
||||
};
|
||||
|
||||
/// A tab widget with groups inside
|
||||
|
@ -167,6 +171,9 @@ private:
|
|||
unsigned nextId;
|
||||
std::vector< sptr< Dictionary::Class > > const * allDicts;
|
||||
std::vector< sptr< Dictionary::Class > > const * activeDicts;
|
||||
|
||||
signals:
|
||||
void showDictionaryInfo( QString const & id );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3050,7 +3050,7 @@ void MainWindow::showDictionaryInfo( const QString & id )
|
|||
{
|
||||
if( dictionaries[ x ]->getId() == id.toUtf8().data() )
|
||||
{
|
||||
DictInfo infoMsg( cfg );
|
||||
DictInfo infoMsg( cfg, this );
|
||||
infoMsg.showInfo( dictionaries[ x ] );
|
||||
infoMsg.exec();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue