diff --git a/groups.cc b/groups.cc index ac2dd066..91d30fda 100644 --- a/groups.cc +++ b/groups.cc @@ -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(); diff --git a/groups.hh b/groups.hh index 557a5b4b..5b34030d 100644 --- a/groups.hh +++ b/groups.hh @@ -45,6 +45,7 @@ private slots: void removeAll(); void addToGroup(); void removeFromGroup(); + void addAutoGroups(); }; #endif diff --git a/groups.ui b/groups.ui index 07e37854..c9bf34f8 100644 --- a/groups.ui +++ b/groups.ui @@ -1,208 +1,229 @@ - - - Groups - - - - 0 - 0 - 662 - 319 - - - - Groups - - - - - - - - Dictionaries available: - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - Add selected dictionaries to group (Ins) - - - > - - - Ins - - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - Remove selected dictionaries from group (Del) - - - < - - - Del - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Groups: - - - - - - - QTabWidget::North - - - Qt::ElideRight - - - - Tab 2 - - - - - - - - - - Create new dictionary group - - - &Add group - - - - - - - Rename current dictionary group - - - Re&name group - - - - - - - Remove current dictionary group - - - &Remove group - - - - - - - Remove all dictionary groups - - - Remove all groups - - - - - - - - - - - Drag&drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse. - - - true - - - - - - - - DictListWidget - QListWidget -
groups_widgets.hh
-
- - DictGroupsWidget - QTabWidget -
groups_widgets.hh
- 1 -
-
- - -
+ + + Groups + + + + 0 + 0 + 662 + 319 + + + + Groups + + + + + + + + Dictionaries available: + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + Add selected dictionaries to group (Ins) + + + > + + + Ins + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + Remove selected dictionaries from group (Del) + + + < + + + Del + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Groups: + + + + + + + QTabWidget::North + + + Qt::ElideRight + + + + Tab 2 + + + + + + + + + + Create new dictionary group + + + &Add group + + + + + + + Create language-based groups + + + Auto groups + + + + + + + Rename current dictionary group + + + Re&name group + + + + + + + Remove current dictionary group + + + &Remove group + + + + + + + Remove all dictionary groups + + + Remove all groups + + + + + + + + + + + Drag&drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse. + + + true + + + + + + + + DictListWidget + QListWidget +
groups_widgets.hh
+
+ + DictGroupsWidget + QTabWidget +
groups_widgets.hh
+ 1 +
+
+ + dictionaries + addDictsToGroup + removeDictsFromGroup + groups + addGroup + autoGroups + renameGroup + removeGroup + removeAllGroups + + + +
diff --git a/groups_widgets.cc b/groups_widgets.cc index 2a777c19..b5542d10 100644 --- a/groups_widgets.cc +++ b/groups_widgets.cc @@ -8,6 +8,8 @@ #include "langcoder.hh" #include "language.hh" +//#include "initializing.hh" + #include #include #include @@ -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, int > tabMap; + +// ::Initializing init( this, true ); +// QApplication::processEvents(); + + for ( int i = 0; i < allDicts->size(); i++ ) + { + sptr dict = allDicts->at( i ); + + quint32 idfrom = dict->getLangFrom(); + quint32 idto = dict->getLangTo(); + QPair 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(); diff --git a/groups_widgets.hh b/groups_widgets.hh index 7d4016d9..967b658f 100644 --- a/groups_widgets.hh +++ b/groups_widgets.hh @@ -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; diff --git a/langcoder.cc b/langcoder.cc index ce776024..6ec2c32a 100644 --- a/langcoder.cc +++ b/langcoder.cc @@ -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();