mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Groups & Dictionaries dialog: added buttons for managing dictionaries
This commit is contained in:
parent
7c1d89ec9d
commit
9d83a95a64
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ private slots:
|
|||
void renameCurrent();
|
||||
void removeCurrent();
|
||||
void removeAll();
|
||||
void addToGroup();
|
||||
void removeFromGroup();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
340
src/groups.ui
340
src/groups.ui
|
@ -1,132 +1,208 @@
|
|||
<?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>724</width>
|
||||
<height>535</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Groups</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<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>
|
||||
<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>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<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="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>
|
||||
|
|
|
@ -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() )
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++ )
|
||||
|
|
Loading…
Reference in a new issue