mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
added auto creation of language pair based groups
This commit is contained in:
parent
00476b0776
commit
d8b76db518
|
@ -40,6 +40,8 @@ Groups::Groups( QWidget * parent,
|
|||
this, SLOT( addToGroup() ) );
|
||||
connect( ui.removeDictsFromGroup, SIGNAL( clicked() ),
|
||||
this, SLOT( removeFromGroup() ) );
|
||||
connect( ui.autoGroups, SIGNAL( clicked() ),
|
||||
this, SLOT( addAutoGroups() ) );
|
||||
|
||||
countChanged();
|
||||
}
|
||||
|
@ -100,6 +102,12 @@ void Groups::addNew()
|
|||
}
|
||||
}
|
||||
|
||||
void Groups::addAutoGroups()
|
||||
{
|
||||
ui.groups->addAutoGroups();
|
||||
countChanged();
|
||||
}
|
||||
|
||||
void Groups::renameCurrent()
|
||||
{
|
||||
int current = ui.groups->currentIndex();
|
||||
|
|
|
@ -45,6 +45,7 @@ private slots:
|
|||
void removeAll();
|
||||
void addToGroup();
|
||||
void removeFromGroup();
|
||||
void addAutoGroups();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
437
groups.ui
437
groups.ui
|
@ -1,208 +1,229 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Groups</class>
|
||||
<widget class="QWidget" name="Groups">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>662</width>
|
||||
<height>319</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Groups</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Dictionaries available:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DictListWidget" name="dictionaries"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addDictsToGroup">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add selected dictionaries to group (Ins)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ins</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeDictsFromGroup">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove selected dictionaries from group (Del)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Del</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Groups:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DictGroupsWidget" name="groups">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="elideMode">
|
||||
<enum>Qt::ElideRight</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addGroup">
|
||||
<property name="toolTip">
|
||||
<string>Create new dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Add group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="renameGroup">
|
||||
<property name="toolTip">
|
||||
<string>Rename current dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Re&name group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeGroup">
|
||||
<property name="toolTip">
|
||||
<string>Remove current dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Remove group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeAllGroups">
|
||||
<property name="toolTip">
|
||||
<string>Remove all dictionary groups</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove all groups</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Drag&drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>DictListWidget</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>groups_widgets.hh</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>DictGroupsWidget</class>
|
||||
<extends>QTabWidget</extends>
|
||||
<header>groups_widgets.hh</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Groups</class>
|
||||
<widget class="QWidget" name="Groups">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>662</width>
|
||||
<height>319</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Groups</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Dictionaries available:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DictListWidget" name="dictionaries"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addDictsToGroup">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add selected dictionaries to group (Ins)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ins</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeDictsFromGroup">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove selected dictionaries from group (Del)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Del</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Groups:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DictGroupsWidget" name="groups">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="elideMode">
|
||||
<enum>Qt::ElideRight</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addGroup">
|
||||
<property name="toolTip">
|
||||
<string>Create new dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Add group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="autoGroups">
|
||||
<property name="toolTip">
|
||||
<string>Create language-based groups</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto groups</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="renameGroup">
|
||||
<property name="toolTip">
|
||||
<string>Rename current dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Re&name group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeGroup">
|
||||
<property name="toolTip">
|
||||
<string>Remove current dictionary group</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Remove group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeAllGroups">
|
||||
<property name="toolTip">
|
||||
<string>Remove all dictionary groups</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove all groups</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Drag&drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>DictListWidget</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>groups_widgets.hh</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>DictGroupsWidget</class>
|
||||
<extends>QTabWidget</extends>
|
||||
<header>groups_widgets.hh</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>dictionaries</tabstop>
|
||||
<tabstop>addDictsToGroup</tabstop>
|
||||
<tabstop>removeDictsFromGroup</tabstop>
|
||||
<tabstop>groups</tabstop>
|
||||
<tabstop>addGroup</tabstop>
|
||||
<tabstop>autoGroups</tabstop>
|
||||
<tabstop>renameGroup</tabstop>
|
||||
<tabstop>removeGroup</tabstop>
|
||||
<tabstop>removeAllGroups</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "langcoder.hh"
|
||||
#include "language.hh"
|
||||
|
||||
//#include "initializing.hh"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
|
@ -224,6 +226,19 @@ bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
|
|||
return true;
|
||||
}
|
||||
|
||||
void DictListModel::addRow(const QModelIndex & parent, sptr< Dictionary::Class > dict)
|
||||
{
|
||||
for (int i = 0; i < dictionaries.size(); i++)
|
||||
{
|
||||
if (dictionaries[i]->getId() == dict->getId())
|
||||
return;
|
||||
}
|
||||
|
||||
beginInsertRows( parent, dictionaries.size(), dictionaries.size()+1 );
|
||||
dictionaries.push_back(dict);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
bool DictListModel::removeRows( int row, int count,
|
||||
const QModelIndex & parent )
|
||||
{
|
||||
|
@ -547,6 +562,65 @@ void DictGroupsWidget::addNewGroup( QString const & name )
|
|||
setCurrentIndex( idx );
|
||||
}
|
||||
|
||||
void DictGroupsWidget::addAutoGroups()
|
||||
{
|
||||
if ( !allDicts )
|
||||
return;
|
||||
|
||||
QMap< QPair<quint32,quint32>, int > tabMap;
|
||||
|
||||
// ::Initializing init( this, true );
|
||||
// QApplication::processEvents();
|
||||
|
||||
for ( int i = 0; i < allDicts->size(); i++ )
|
||||
{
|
||||
sptr<Dictionary::Class> dict = allDicts->at( i );
|
||||
|
||||
quint32 idfrom = dict->getLangFrom();
|
||||
quint32 idto = dict->getLangTo();
|
||||
QPair<quint32,quint32> key(idfrom, idto);
|
||||
|
||||
if (tabMap.contains(key))
|
||||
{
|
||||
setCurrentIndex(tabMap[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString lfrom = LangCoder::intToCode2( idfrom );
|
||||
QString lto = LangCoder::intToCode2( idto );
|
||||
QString name("Unassigned");
|
||||
if (lfrom.isEmpty() == false && lto.isEmpty() == false)
|
||||
name = lfrom + " - " + lto;
|
||||
|
||||
// search for the language group
|
||||
bool found = false;
|
||||
for (int j = 0; j < count(); j++)
|
||||
{
|
||||
if (tabText(j) == name)
|
||||
{
|
||||
found = true;
|
||||
setCurrentIndex(j);
|
||||
tabMap[key] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// group not found - add it
|
||||
if (!found)
|
||||
{
|
||||
addNewGroup(name);
|
||||
int j = currentIndex();
|
||||
tabMap[key] = j;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// add dictionary into the current group
|
||||
DictListModel *model = getCurrentModel();
|
||||
model->addRow(QModelIndex(), dict);
|
||||
}
|
||||
}
|
||||
|
||||
QString DictGroupsWidget::getCurrentGroupName() const
|
||||
{
|
||||
int current = currentIndex();
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
bool removeRows( int row, int count, const QModelIndex & parent );
|
||||
bool setData( QModelIndex const & index, const QVariant & value, int role );
|
||||
|
||||
void addRow(const QModelIndex & parent, sptr< Dictionary::Class > dict);
|
||||
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
|
||||
void filterDuplicates();
|
||||
|
@ -136,6 +138,8 @@ public:
|
|||
/// Creates new empty group with the given name
|
||||
void addNewGroup( QString const & );
|
||||
|
||||
void addAutoGroups();
|
||||
|
||||
/// Returns currently chosen group's name
|
||||
QString getCurrentGroupName() const;
|
||||
|
||||
|
|
|
@ -31,14 +31,7 @@ QIcon LangCoder::icon(quint32 code)
|
|||
if (langCoder.codeMap.contains(code))
|
||||
{
|
||||
const LangCode &lc = LangCodes[ langCoder.codeMap[ code ] ];
|
||||
// QString flag_id( lc.code );
|
||||
// if (flag_id == "en")
|
||||
// flag_id = "gb";
|
||||
// else
|
||||
// if (flag_id == "uk")
|
||||
// flag_id = "ua";
|
||||
|
||||
return QIcon( ":/flags/" + QString( lc.code) + ".png" );
|
||||
return QIcon( ":/flags/" + QString(lc.code) + ".png" );
|
||||
}
|
||||
|
||||
return QIcon();
|
||||
|
|
Loading…
Reference in a new issue