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
|
|
|
|
|
2009-04-27 09:49:40 +00:00
|
|
|
#include <QListWidget>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "config.hh"
|
|
|
|
#include "dictionary.hh"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/// 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();
|
2009-05-02 19:57:52 +00:00
|
|
|
bool sourceModel() const { return isSource; }
|
|
|
|
|
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 );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
Qt::ItemFlags flags( QModelIndex const &index ) const;
|
|
|
|
int rowCount( QModelIndex const & parent ) const;
|
|
|
|
QVariant data( QModelIndex const & index, int role ) const;
|
2009-05-03 19:24:25 +00:00
|
|
|
bool insertRows( int row, int count, const QModelIndex & parent );
|
|
|
|
bool removeRows( int row, int count, const QModelIndex & parent );
|
2009-01-28 20:55:45 +00:00
|
|
|
bool setData( QModelIndex const & index, const QVariant & value, int role );
|
|
|
|
|
2010-09-16 18:50:31 +00:00
|
|
|
void addRow(const QModelIndex & parent, sptr< Dictionary::Class > dict);
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
Qt::DropActions supportedDropActions() const;
|
|
|
|
|
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
|
|
|
|
public:
|
|
|
|
DictListWidget( QWidget * parent );
|
|
|
|
~DictListWidget();
|
|
|
|
|
|
|
|
/// 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()
|
|
|
|
{ return & model; }
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-02 19:57:52 +00:00
|
|
|
protected:
|
2009-05-24 14:24:13 +00:00
|
|
|
virtual void dropEvent( QDropEvent * event );
|
|
|
|
|
|
|
|
// We need these to to handle drag-and-drop focus issues
|
|
|
|
virtual void rowsInserted( QModelIndex const & parent, int start, int end );
|
|
|
|
virtual void rowsAboutToBeRemoved( QModelIndex const & parent, int start, int end );
|
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 & );
|
|
|
|
|
|
|
|
/// Makes the group's configuration out of the data currently held.
|
|
|
|
/// Since the group's name is not part of the widget by design right now
|
|
|
|
/// (it is known by the containing tab widget only), it is returned as empty.
|
|
|
|
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(); }
|
|
|
|
|
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;
|
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
|
|
|
|
void addNewGroup( QString const & );
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|