diff --git a/src/groups.cc b/src/groups.cc index a8b0896e..4158d18e 100644 --- a/src/groups.cc +++ b/src/groups.cc @@ -31,6 +31,10 @@ Groups::Groups( QWidget * parent, this, SLOT( removeCurrent() ) ); connect( ui.removeAllGroups, SIGNAL( clicked() ), this, SLOT( removeAll() ) ); + connect( ui.addDictsToGroup, SIGNAL( clicked() ), + this, SLOT( addToGroup() ) ); + connect( ui.removeDictsFromGroup, SIGNAL( clicked() ), + this, SLOT( removeFromGroup() ) ); countChanged(); } @@ -107,3 +111,22 @@ void Groups::removeAll() } } +void Groups::addToGroup() +{ + int current = ui.groups->currentIndex(); + + if ( current >= 0 ) + { + ui.groups->getCurrentModel()->addSelectedUniqueFromModel( ui.dictionaries->selectionModel() ); + } +} + +void Groups::removeFromGroup() +{ + int current = ui.groups->currentIndex(); + + if ( current >= 0 ) + { + ui.groups->getCurrentModel()->removeSelectedRows( ui.groups->getCurrentSelectionModel() ); + } +} diff --git a/src/groups.hh b/src/groups.hh index 8e4cd416..34231577 100644 --- a/src/groups.hh +++ b/src/groups.hh @@ -34,6 +34,8 @@ private slots: void renameCurrent(); void removeCurrent(); void removeAll(); + void addToGroup(); + void removeFromGroup(); }; #endif diff --git a/src/groups.ui b/src/groups.ui index 84c40920..07e37854 100644 --- a/src/groups.ui +++ b/src/groups.ui @@ -1,132 +1,208 @@ - - - Groups - - - - 0 - 0 - 724 - 535 - - - - Groups - - - - - - - - - - Dictionaries available: - - - - - - - - - - - - - - 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 + + + + + + + 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 +
+
+ + +
diff --git a/src/groups_widgets.cc b/src/groups_widgets.cc index 1b433a72..ebed608a 100644 --- a/src/groups_widgets.cc +++ b/src/groups_widgets.cc @@ -187,6 +187,69 @@ Qt::DropActions DictListModel::supportedDropActions() const return Qt::MoveAction; } + +void DictListModel::removeSelectedRows( QItemSelectionModel * source ) +{ + if ( !source ) + return; + + QModelIndexList rows = source->selectedRows(); + + if ( !rows.count() ) + return; + + for ( int i = rows.count()-1; i >= 0; --i ) + { + dictionaries.erase( dictionaries.begin() + rows.at( i ).row() ); + } + + reset(); +} + +void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source ) +{ + if ( !source ) + return; + + QModelIndexList rows = source->selectedRows(); + + if ( !rows.count() ) + return; + + const DictListModel * baseModel = dynamic_cast< const DictListModel * > ( source->model() ); + if ( !baseModel ) + return; + + QVector< std::string > list; + QVector< std::string > dicts; + for ( int i = 0; i < dictionaries.size(); i++ ) + dicts.append( dictionaries.at( i )->getId() ); + + for ( int i = 0; i < rows.count(); i++ ) + { + std::string id = baseModel->dictionaries.at( rows.at( i ).row() )->getId(); + + if ( !dicts.contains( id ) ) + list.append( id ); + } + + if ( list.empty() ) + return; + + for ( int i = 0; i < allDicts->size(); i++ ) + { + for ( int j = list.size(); j--; ) + { + if ( allDicts->at( i )->getId() == list.at( j ) ) + { + dictionaries.push_back( allDicts->at( i ) ); + } + } + } + + reset(); +} + /// DictListWidget DictListWidget::DictListWidget( QWidget * parent ): QListView( parent ), @@ -283,6 +346,33 @@ Config::Groups DictGroupsWidget::makeGroups() const return result; } +DictListModel * DictGroupsWidget::getCurrentModel() const +{ + int current = currentIndex(); + + if ( current >= 0 ) + { + DictGroupWidget * w = ( DictGroupWidget * ) widget( current ); + return w->getModel(); + } + + return 0; +} + +QItemSelectionModel * DictGroupsWidget::getCurrentSelectionModel() const +{ + int current = currentIndex(); + + if ( current >= 0 ) + { + DictGroupWidget * w = ( DictGroupWidget * ) widget( current ); + return w->getSelectionModel(); + } + + return 0; +} + + void DictGroupsWidget::addNewGroup( QString const & name ) { if ( !allDicts ) @@ -331,7 +421,6 @@ void DictGroupsWidget::removeCurrentGroup() } } - void DictGroupsWidget::removeAllGroups() { while ( count() ) diff --git a/src/groups_widgets.hh b/src/groups_widgets.hh index dd2a89cd..96ede64a 100644 --- a/src/groups_widgets.hh +++ b/src/groups_widgets.hh @@ -32,6 +32,9 @@ public: /// Returns the dictionaries the model currently has listed std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const; + void removeSelectedRows( QItemSelectionModel * source ); + void addSelectedUniqueFromModel( QItemSelectionModel * source ); + Qt::ItemFlags flags( QModelIndex const &index ) const; int rowCount( QModelIndex const & parent ) const; QVariant data( QModelIndex const & index, int role ) const; @@ -67,6 +70,8 @@ public: /// Returns the dictionaries the widget currently has listed std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const; + DictListModel * getModel() + { return & model; } private: @@ -90,6 +95,12 @@ public: /// (it is known by the containing tab widget only), it is returned as empty. Config::Group makeGroup() const; + DictListModel * getModel() const + { return ui.dictionaries->getModel(); } + + QItemSelectionModel * getSelectionModel() const + { return ui.dictionaries->selectionModel(); } + private: Ui::DictGroupWidget ui; unsigned groupId; @@ -126,6 +137,10 @@ public: /// Creates groups from what is currently set up Config::Groups makeGroups() const; + DictListModel * getCurrentModel() const; + + QItemSelectionModel * getCurrentSelectionModel() const; + private: unsigned nextId; diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 33e81cea..ebaf36c7 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -1307,11 +1307,11 @@ void MainWindow::applyZoomFactor() { if ( cfg.preferences.zoomFactor >= 3 ) cfg.preferences.zoomFactor = 3; - else if ( cfg.preferences.zoomFactor <= 0.8 ) - cfg.preferences.zoomFactor = 0.8; + else if ( cfg.preferences.zoomFactor <= 0.7 ) + cfg.preferences.zoomFactor = 0.7; zoomIn->setEnabled( cfg.preferences.zoomFactor < 3 ); - zoomOut->setEnabled( cfg.preferences.zoomFactor > 0.8 ); + zoomOut->setEnabled( cfg.preferences.zoomFactor > 0.7 ); zoomBase->setEnabled( cfg.preferences.zoomFactor != 1.0 ); for ( int i = 0; i < ui.tabWidget->count(); i++ )