2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __GROUPS_WIDGETS_HH_INCLUDED__
|
|
|
|
#define __GROUPS_WIDGETS_HH_INCLUDED__
|
|
|
|
|
|
|
|
// Various custom widgets used in the Groups dialog
|
|
|
|
|
2013-01-04 13:24:08 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-04-10 17:04:12 +00:00
|
|
|
#include <QAction>
|
2009-04-27 09:49:40 +00:00
|
|
|
#include <QListWidget>
|
2023-03-05 22:41:42 +00:00
|
|
|
#include <QLineEdit>
|
2013-01-04 13:24:08 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "config.hh"
|
2023-04-17 20:55:34 +00:00
|
|
|
#include "dict/dictionary.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// A model to be projected into the view, according to Qt's MVC model
|
2009-04-27 09:49:40 +00:00
|
|
|
class DictListModel: public QAbstractListModel
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DictListModel( QWidget * parent ):
|
2009-04-27 09:49:40 +00:00
|
|
|
QAbstractListModel( parent ),
|
|
|
|
isSource( false ),
|
|
|
|
allDicts( 0 )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Populates the current model with the given dictionaries. This is
|
|
|
|
/// ought to be part of construction process.
|
|
|
|
void populate( std::vector< sptr< Dictionary::Class > > const & active,
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & available );
|
2012-12-18 12:33:53 +00:00
|
|
|
void populate( std::vector< sptr< Dictionary::Class > > const & active );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Marks that this model is used as an immutable dictionary source
|
|
|
|
void setAsSource();
|
2023-06-23 01:25:15 +00:00
|
|
|
bool sourceModel() const
|
|
|
|
{
|
|
|
|
return isSource;
|
|
|
|
}
|
2009-05-02 19:57:52 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns the dictionaries the model currently has listed
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const;
|
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
void removeSelectedRows( QItemSelectionModel * source );
|
|
|
|
void addSelectedUniqueFromModel( QItemSelectionModel * source );
|
|
|
|
|
2023-06-23 01:25:15 +00:00
|
|
|
Qt::ItemFlags flags( QModelIndex const & index ) const override;
|
|
|
|
int rowCount( QModelIndex const & parent ) const override;
|
|
|
|
QVariant data( QModelIndex const & index, int role ) const override;
|
|
|
|
bool insertRows( int row, int count, const QModelIndex & parent ) override;
|
|
|
|
bool removeRows( int row, int count, const QModelIndex & parent ) override;
|
|
|
|
bool setData( QModelIndex const & index, const QVariant & value, int role ) override;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2023-06-23 01:25:15 +00:00
|
|
|
void addRow( const QModelIndex & parent, sptr< Dictionary::Class > dict );
|
2010-09-16 18:50:31 +00:00
|
|
|
|
2023-06-23 01:25:15 +00:00
|
|
|
Qt::DropActions supportedDropActions() const override;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-03 19:24:25 +00:00
|
|
|
void filterDuplicates();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
bool isSource;
|
|
|
|
std::vector< sptr< Dictionary::Class > > dictionaries;
|
|
|
|
std::vector< sptr< Dictionary::Class > > const * allDicts;
|
2012-12-21 20:20:54 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void contentChanged();
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This widget is for dictionaries' lists, it handles drag-n-drop operations
|
|
|
|
/// with them etc.
|
2009-04-27 09:49:40 +00:00
|
|
|
class DictListWidget: public QListView
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
public:
|
|
|
|
DictListWidget( QWidget * parent );
|
2023-06-23 01:25:15 +00:00
|
|
|
~DictListWidget() override = default;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Populates the current list with the given dictionaries.
|
|
|
|
void populate( std::vector< sptr< Dictionary::Class > > const & active,
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & available );
|
2012-12-18 12:33:53 +00:00
|
|
|
void populate( std::vector< sptr< Dictionary::Class > > const & active );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Marks that this widget is used as an immutable dictionary source
|
|
|
|
void setAsSource();
|
|
|
|
|
|
|
|
/// Returns the dictionaries the widget currently has listed
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const;
|
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
DictListModel * getModel()
|
2023-06-23 01:25:15 +00:00
|
|
|
{
|
|
|
|
return &model;
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2013-01-07 08:52:36 +00:00
|
|
|
signals:
|
|
|
|
void gotFocus();
|
|
|
|
|
2009-05-02 19:57:52 +00:00
|
|
|
protected:
|
2023-06-23 01:25:15 +00:00
|
|
|
void dropEvent( QDropEvent * event ) override;
|
|
|
|
void focusInEvent( QFocusEvent * ) override;
|
2009-05-24 14:24:13 +00:00
|
|
|
|
2023-06-23 01:25:15 +00:00
|
|
|
void rowsAboutToBeRemoved( QModelIndex const & parent, int start, int end ) override;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-02 19:57:52 +00:00
|
|
|
private:
|
2009-01-28 20:55:45 +00:00
|
|
|
DictListModel model;
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "ui_dictgroupwidget.h"
|
|
|
|
|
|
|
|
/// A widget that is placed into each tab in the Groups dialog.
|
|
|
|
class DictGroupWidget: public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
DictGroupWidget( QWidget * parent, std::vector< sptr< Dictionary::Class > > const &, Config::Group const & );
|
|
|
|
|
|
|
|
Config::Group makeGroup() const;
|
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
DictListModel * getModel() const
|
|
|
|
{
|
|
|
|
return ui.dictionaries->getModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
QItemSelectionModel * getSelectionModel() const
|
|
|
|
{
|
|
|
|
return ui.dictionaries->selectionModel();
|
|
|
|
}
|
|
|
|
|
2024-11-06 06:10:25 +00:00
|
|
|
QString name()
|
|
|
|
{
|
|
|
|
return groupName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setName( const QString & name )
|
|
|
|
{
|
|
|
|
groupName = name;
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:36:03 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void groupIconActivated( int );
|
2012-12-20 13:25:03 +00:00
|
|
|
void showDictInfo( const QPoint & pos );
|
2012-12-20 13:25:38 +00:00
|
|
|
void removeCurrentItem( QModelIndex const & );
|
2010-07-05 18:36:03 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
Ui::DictGroupWidget ui;
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned groupId;
|
2024-11-06 06:10:25 +00:00
|
|
|
QString groupName;
|
2012-12-20 13:25:03 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void showDictionaryInfo( QString const & id );
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// A tab widget with groups inside
|
|
|
|
class DictGroupsWidget: public QTabWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DictGroupsWidget( QWidget * parent );
|
|
|
|
|
|
|
|
/// Creates all the tabs with the groups
|
|
|
|
void populate( Config::Groups const &,
|
2012-12-18 12:35:11 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDicts,
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & activeDicts );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Creates new empty group with the given name
|
2023-06-13 00:07:54 +00:00
|
|
|
int addNewGroup( QString const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2012-12-21 11:48:41 +00:00
|
|
|
/// Creates new empty group with the given name if no such group
|
|
|
|
/// and return it index
|
|
|
|
int addUniqueGroup( QString const & name );
|
|
|
|
|
2010-09-16 18:50:31 +00:00
|
|
|
void addAutoGroups();
|
|
|
|
|
2023-04-21 00:45:38 +00:00
|
|
|
/// auto grouping by containning folder
|
|
|
|
void addAutoGroupsByFolders();
|
2023-04-29 06:59:19 +00:00
|
|
|
void addGroupBasedOnMap( const QMultiMap< QString, sptr< Dictionary::Class > > & groupToDicts );
|
|
|
|
|
|
|
|
void groupsByMetadata();
|
2023-04-21 00:45:38 +00:00
|
|
|
|
2009-04-10 21:37:16 +00:00
|
|
|
/// Returns currently chosen group's name
|
|
|
|
QString getCurrentGroupName() const;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Changes the name of the currently chosen group, if any, to the given one
|
|
|
|
void renameCurrentGroup( QString const & );
|
|
|
|
|
|
|
|
/// Removes the currently chosen group, if any
|
|
|
|
void removeCurrentGroup();
|
|
|
|
|
2009-04-29 23:32:42 +00:00
|
|
|
/// Removes all the groups
|
|
|
|
void removeAllGroups();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Creates groups from what is currently set up
|
|
|
|
Config::Groups makeGroups() const;
|
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
DictListModel * getCurrentModel() const;
|
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
DictListModel * getModelAt( int current ) const;
|
2023-06-22 08:30:41 +00:00
|
|
|
int getDictionaryCountAt( int current ) const;
|
|
|
|
std::vector< sptr< Dictionary::Class > > getDictionaryAt( int current ) const;
|
2023-06-13 00:07:54 +00:00
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
QItemSelectionModel * getCurrentSelectionModel() const;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
2012-12-21 16:46:17 +00:00
|
|
|
/// Add source group to target group
|
|
|
|
void combineGroups( int source, int target );
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned nextId;
|
2009-01-28 20:55:45 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const * allDicts;
|
2012-12-18 12:35:11 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const * activeDicts;
|
2012-12-20 13:25:03 +00:00
|
|
|
|
2012-12-21 11:48:41 +00:00
|
|
|
private slots:
|
|
|
|
void contextMenu( QPoint const & );
|
2012-12-21 20:20:54 +00:00
|
|
|
void tabDataChanged();
|
2012-12-21 11:48:41 +00:00
|
|
|
|
2012-12-20 13:25:03 +00:00
|
|
|
signals:
|
|
|
|
void showDictionaryInfo( QString const & id );
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
2023-03-05 22:41:42 +00:00
|
|
|
class QuickFilterLine: public QLineEdit
|
2013-01-04 13:24:08 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
QuickFilterLine( QWidget * parent );
|
2023-06-23 01:25:15 +00:00
|
|
|
~QuickFilterLine() override;
|
2013-01-04 13:24:08 +00:00
|
|
|
|
|
|
|
/// Sets the source view to filter
|
|
|
|
void applyTo( QAbstractItemView * source );
|
|
|
|
|
|
|
|
QAction * getFocusAction()
|
|
|
|
{
|
|
|
|
return &m_focusAction;
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2013-01-04 13:24:08 +00:00
|
|
|
QModelIndex mapToSource( QModelIndex const & idx );
|
|
|
|
|
2013-01-07 08:52:36 +00:00
|
|
|
protected:
|
2023-06-23 01:25:15 +00:00
|
|
|
void keyPressEvent( QKeyEvent * event ) override;
|
2013-01-07 08:52:36 +00:00
|
|
|
|
2013-01-04 13:24:08 +00:00
|
|
|
private:
|
|
|
|
QSortFilterProxyModel m_proxyModel;
|
|
|
|
QAction m_focusAction;
|
2013-01-07 08:52:36 +00:00
|
|
|
QAbstractItemView * m_source;
|
2013-01-04 13:24:08 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void filterChangedInternal();
|
|
|
|
void emitFilterChanged();
|
|
|
|
void focusFilterLine();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void filterChanged( QString const & filter );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|