mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Add "Favorites" feature
This commit is contained in:
parent
8b98c86c74
commit
1e34de2dbc
13
config.cc
13
config.cc
|
@ -258,6 +258,7 @@ Group loadGroup( QDomElement grp, unsigned * nextId = 0 )
|
|||
|
||||
g.name = grp.attribute( "name" );
|
||||
g.icon = grp.attribute( "icon" );
|
||||
g.favoritesFolder = grp.attribute( "favoritesFolder" );
|
||||
|
||||
if ( !grp.attribute( "iconData" ).isEmpty() )
|
||||
g.iconData = QByteArray::fromBase64( grp.attribute( "iconData" ).toLatin1() );
|
||||
|
@ -1029,6 +1030,13 @@ void saveGroup( Group const & data, QDomElement & group )
|
|||
|
||||
group.setAttributeNode( name );
|
||||
|
||||
if( data.favoritesFolder.size() )
|
||||
{
|
||||
QDomAttr folder = dd.createAttribute( "favoritesFolder" );
|
||||
folder.setValue( data.favoritesFolder );
|
||||
group.setAttributeNode( folder );
|
||||
}
|
||||
|
||||
if ( data.icon.size() )
|
||||
{
|
||||
QDomAttr icon = dd.createAttribute( "icon" );
|
||||
|
@ -1996,6 +2004,11 @@ QString getHistoryFileName() throw( exError )
|
|||
return getHomeDir().filePath( "history" );
|
||||
}
|
||||
|
||||
QString getFavoritiesFileName() throw( exError )
|
||||
{
|
||||
return getHomeDir().filePath( "favorites" );
|
||||
}
|
||||
|
||||
QString getUserCssFileName() throw( exError )
|
||||
{
|
||||
return getHomeDir().filePath( "article-style.css" );
|
||||
|
|
|
@ -87,6 +87,7 @@ struct Group
|
|||
QString name, icon;
|
||||
QByteArray iconData;
|
||||
QKeySequence shortcut;
|
||||
QString favoritesFolder;
|
||||
QVector< DictionaryRef > dictionaries;
|
||||
Config::MutedDictionaries mutedDictionaries; // Disabled via dictionary bar
|
||||
Config::MutedDictionaries popupMutedDictionaries; // Disabled via dictionary bar in popup
|
||||
|
@ -95,6 +96,7 @@ struct Group
|
|||
|
||||
bool operator == ( Group const & other ) const
|
||||
{ return id == other.id && name == other.name && icon == other.icon &&
|
||||
favoritesFolder == other.favoritesFolder &&
|
||||
dictionaries == other.dictionaries && shortcut == other.shortcut &&
|
||||
mutedDictionaries == other.mutedDictionaries &&
|
||||
popupMutedDictionaries == other.popupMutedDictionaries &&
|
||||
|
@ -662,6 +664,9 @@ QString getPidFileName() throw( exError );
|
|||
/// Returns the filename of a history file which stores search history.
|
||||
QString getHistoryFileName() throw( exError );
|
||||
|
||||
/// Returns the filename of a favorities file.
|
||||
QString getFavoritiesFileName() throw( exError );
|
||||
|
||||
/// Returns the user .css file name.
|
||||
QString getUserCssFileName() throw( exError );
|
||||
|
||||
|
|
|
@ -14,18 +14,6 @@
|
|||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="DictListWidget" name="dictionaries"/>
|
||||
</item>
|
||||
|
@ -91,6 +79,20 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Favorites folder:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="favoritesFolder"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
|
1118
favoritespanewidget.cc
Normal file
1118
favoritespanewidget.cc
Normal file
File diff suppressed because it is too large
Load diff
236
favoritespanewidget.hh
Normal file
236
favoritespanewidget.hh
Normal file
|
@ -0,0 +1,236 @@
|
|||
/* This file is (c) 2017 Abs62
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#ifndef __FAVORITIESPANEWIDGET_HH__INCLUDED__
|
||||
#define __FAVORITIESPANEWIDGET_HH__INCLUDED__
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSize>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QTreeView>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QDomNode>
|
||||
#include <QList>
|
||||
|
||||
#include <config.hh>
|
||||
#include "delegate.hh"
|
||||
|
||||
class FavoritesModel;
|
||||
|
||||
class FavoritesPaneWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FavoritesPaneWidget( QWidget * parent = 0 ): QWidget( parent ),
|
||||
itemSelectionChanged( false )
|
||||
, listItemDelegate( 0 )
|
||||
, m_favoritesModel( 0 )
|
||||
{}
|
||||
|
||||
virtual ~FavoritesPaneWidget();
|
||||
|
||||
virtual QSize sizeHint() const
|
||||
{ return QSize( 204, 204 ); }
|
||||
|
||||
void setUp( Config::Class * cfg, QMenu * menu );
|
||||
|
||||
void addHeadword( QString const & path, QString const & headword );
|
||||
|
||||
// Export/import Favorites
|
||||
void getDataInXml( QByteArray & dataStr );
|
||||
void getDataInPlainText( QString & dataStr );
|
||||
bool setDataFromXml( QString const & dataStr );
|
||||
|
||||
signals:
|
||||
void favoritesItemRequested( QString const & word, QString const & faforitesFolder );
|
||||
|
||||
private slots:
|
||||
void emitFavoritesItemRequested(QModelIndex const &);
|
||||
void onSelectionChanged(QItemSelection const & selection);
|
||||
void onItemClicked(QModelIndex const & idx);
|
||||
void showCustomMenu(QPoint const & pos);
|
||||
void deleteSelectedItems();
|
||||
void copySelectedItems();
|
||||
void addFolder();
|
||||
|
||||
private:
|
||||
virtual bool eventFilter( QObject *, QEvent * );
|
||||
|
||||
Config::Class * m_cfg ;
|
||||
QTreeView * m_favoritesTree;
|
||||
QMenu * m_favoritesMenu;
|
||||
QAction * m_deleteSelectedAction;
|
||||
QAction * m_separator;
|
||||
QAction * m_copySelectedToClipboard;
|
||||
QAction * m_addFolder;
|
||||
|
||||
QWidget favoritesPaneTitleBar;
|
||||
QHBoxLayout favoritesPaneTitleBarLayout;
|
||||
QLabel favoritesLabel;
|
||||
|
||||
/// needed to avoid multiple notifications
|
||||
/// when selecting items via mouse and keyboard
|
||||
bool itemSelectionChanged;
|
||||
|
||||
WordListItemDelegate * listItemDelegate;
|
||||
FavoritesModel * m_favoritesModel;
|
||||
};
|
||||
|
||||
|
||||
class TreeItem
|
||||
{
|
||||
public:
|
||||
enum Type { Word, Folder, Root };
|
||||
|
||||
TreeItem( const QVariant &data, TreeItem *parent = 0, Type type_ = Word );
|
||||
~TreeItem();
|
||||
|
||||
void appendChild( TreeItem * child );
|
||||
|
||||
void insertChild( int row, TreeItem * item );
|
||||
|
||||
// Remove child from list and delete it
|
||||
void deleteChild( int row );
|
||||
|
||||
TreeItem * child( int row ) const;
|
||||
int childCount() const;
|
||||
QVariant data() const;
|
||||
void setData( const QVariant & newData );
|
||||
int row() const;
|
||||
TreeItem * parent();
|
||||
|
||||
Type type() const
|
||||
{ return m_type; }
|
||||
|
||||
Qt::ItemFlags flags() const;
|
||||
|
||||
void setExpanded( bool expanded )
|
||||
{ m_expanded = expanded; }
|
||||
|
||||
bool isExpanded() const
|
||||
{ return m_expanded; }
|
||||
|
||||
// Full path from root folder
|
||||
QString fullPath() const;
|
||||
|
||||
// Duplicate item with all childs
|
||||
TreeItem * duplicateItem( TreeItem * newParent ) const;
|
||||
|
||||
// Check if item is ancestor of this element
|
||||
bool haveAncestor( TreeItem * item );
|
||||
|
||||
// Check if same item already presented between childs
|
||||
bool haveSameItem( TreeItem * item, bool allowSelf );
|
||||
|
||||
// Retrieve text from all childs
|
||||
QStringList getTextFromAllChilds() const;
|
||||
|
||||
private:
|
||||
QList< TreeItem * > childItems;
|
||||
QVariant itemData;
|
||||
TreeItem *parentItem;
|
||||
Type m_type;
|
||||
bool m_expanded;
|
||||
};
|
||||
|
||||
class FavoritesModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FavoritesModel( QString favoritesFilename, QObject * parent = 0 );
|
||||
~FavoritesModel();
|
||||
|
||||
QVariant data( const QModelIndex &index, int role ) const;
|
||||
Qt::ItemFlags flags( const QModelIndex &index ) const;
|
||||
QVariant headerData( int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole ) const;
|
||||
QModelIndex index( int row, int column,
|
||||
const QModelIndex &parent = QModelIndex() ) const;
|
||||
QModelIndex parent( const QModelIndex &index ) const;
|
||||
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
|
||||
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
|
||||
bool removeRows( int row, int count, const QModelIndex &parent );
|
||||
bool setData( const QModelIndex &index, const QVariant &value, int role );
|
||||
|
||||
// Drag & drop support
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
QStringList mimeTypes() const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column, const QModelIndex &par);
|
||||
|
||||
// Restore nodes expanded state after data loading
|
||||
void checkNodeForExpand( const TreeItem * item, const QModelIndex &parent );
|
||||
void checkAllNodesForExpand();
|
||||
|
||||
// Retrieve text data for indexes
|
||||
QStringList getTextForIndexes( QModelIndexList const & idxList ) const;
|
||||
|
||||
// Delete items for indexes
|
||||
void removeItemsForIndexes( QModelIndexList const & idxList );
|
||||
|
||||
// Add new folder beside item and return its index
|
||||
// or empty index if fail
|
||||
QModelIndex addNewFolder( QModelIndex const & idx );
|
||||
|
||||
// Add new headword to given folder
|
||||
// return false if it already exists there
|
||||
bool addNewHeadword( QString const & path, QString const & headword );
|
||||
|
||||
// Return path in the tree to item
|
||||
QString pathToItem( QModelIndex const & idx );
|
||||
|
||||
TreeItem::Type itemType( QModelIndex const & idx )
|
||||
{ return getItem( idx )->type(); }
|
||||
|
||||
// Export/import Favorites
|
||||
void getDataInXml( QByteArray & dataStr );
|
||||
void getDataInPlainText( QString & dataStr );
|
||||
bool setDataFromXml( QString const & dataStr );
|
||||
|
||||
public slots:
|
||||
void itemCollapsed ( const QModelIndex & index );
|
||||
void itemExpanded ( const QModelIndex & index );
|
||||
|
||||
signals:
|
||||
void expandItem( const QModelIndex & index );
|
||||
|
||||
protected:
|
||||
void readData();
|
||||
void saveData();
|
||||
void addFolder( TreeItem * parent, QDomNode & node );
|
||||
void storeFolder( TreeItem * folder, QDomNode & node );
|
||||
|
||||
// Find item in folder
|
||||
QModelIndex findItemInFolder( QString const & itemName, int itemType,
|
||||
QModelIndex const & parentIdx );
|
||||
|
||||
// Find item by it params
|
||||
QModelIndex findItem( QString const & path,
|
||||
QString const & headword,
|
||||
int type );
|
||||
|
||||
// Create items list from mime "plait/text" data
|
||||
QList< QModelIndex > itemsListFromText( QString const & text );
|
||||
|
||||
TreeItem *getItem( const QModelIndex &index ) const;
|
||||
|
||||
// Find folder with given name or create it if folder not exist
|
||||
QModelIndex forceFolder( QString const & name, QModelIndex const & parentIdx );
|
||||
|
||||
// Add headword to given folder
|
||||
// return false if such headwordalready exists
|
||||
bool addHeadword( QString const & word, QModelIndex const & parentIdx );
|
||||
|
||||
// Return tree level for item
|
||||
int level( QModelIndex const & idx );
|
||||
|
||||
private:
|
||||
QString m_favoritesFilename;
|
||||
TreeItem * rootItem;
|
||||
QDomDocument dom;
|
||||
};
|
||||
|
||||
#endif // __FAVORITIESPANEWIDGET_HH__INCLUDED__
|
|
@ -356,7 +356,8 @@ HEADERS += folding.hh \
|
|||
slob.hh \
|
||||
ripemd.hh \
|
||||
gls.hh \
|
||||
splitfile.hh
|
||||
splitfile.hh \
|
||||
favoritespanewidget.hh
|
||||
|
||||
FORMS += groups.ui \
|
||||
dictgroupwidget.ui \
|
||||
|
@ -482,7 +483,8 @@ SOURCES += folding.cc \
|
|||
slob.cc \
|
||||
ripemd.cc \
|
||||
gls.cc \
|
||||
splitfile.cc
|
||||
splitfile.cc \
|
||||
favoritespanewidget.cc
|
||||
|
||||
win32 {
|
||||
FORMS += texttospeechsource.ui
|
||||
|
|
|
@ -63,6 +63,8 @@ DictGroupWidget::DictGroupWidget( QWidget * parent,
|
|||
|
||||
ui.shortcut->setHotKey( Config::HotKey( group.shortcut ) );
|
||||
|
||||
ui.favoritesFolder->setText( group.favoritesFolder );
|
||||
|
||||
connect( ui.groupIcon, SIGNAL(activated(int)),this,SLOT(groupIconActivated(int)),
|
||||
Qt::QueuedConnection );
|
||||
|
||||
|
@ -129,6 +131,8 @@ Config::Group DictGroupWidget::makeGroup() const
|
|||
|
||||
g.shortcut = ui.shortcut->getHotKey().toKeySequence();
|
||||
|
||||
g.favoritesFolder = ui.favoritesFolder->text().replace( '\\', '/' );
|
||||
|
||||
return g.makeConfigGroup();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
History::History( unsigned size, unsigned maxItemLength_ ): maxSize( size ),
|
||||
maxItemLength( maxItemLength_ ), addingEnabled( true )
|
||||
, dirty( false )
|
||||
, timerId ( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
BIN
icons/folder.png
Normal file
BIN
icons/folder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
icons/star.png
Normal file
BIN
icons/star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 724 B |
|
@ -15,6 +15,7 @@ Group::Group( Config::Group const & cfgGroup,
|
|||
id( cfgGroup.id ),
|
||||
name( cfgGroup.name ),
|
||||
icon( cfgGroup.icon ),
|
||||
favoritesFolder( cfgGroup.favoritesFolder ),
|
||||
shortcut( cfgGroup.shortcut )
|
||||
{
|
||||
if ( !cfgGroup.iconData.isEmpty() )
|
||||
|
@ -82,6 +83,7 @@ Config::Group Group::makeConfigGroup()
|
|||
result.name = name;
|
||||
result.icon = icon;
|
||||
result.shortcut = shortcut;
|
||||
result.favoritesFolder = favoritesFolder;
|
||||
|
||||
if ( !iconData.isNull() )
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ using std::vector;
|
|||
struct Group
|
||||
{
|
||||
unsigned id;
|
||||
QString name, icon;
|
||||
QString name, icon, favoritesFolder;
|
||||
QIcon iconData;
|
||||
QKeySequence shortcut;
|
||||
vector< sptr< Dictionary::Class > > dictionaries;
|
||||
|
|
224
mainwindow.cc
224
mainwindow.cc
|
@ -238,6 +238,14 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
navToolbar->addAction( ui.print );
|
||||
navToolbar->widgetForAction( ui.print )->setObjectName( "printButton" );
|
||||
|
||||
navToolbar->widgetForAction( navToolbar->addSeparator() )->setObjectName( "separatorBeforeAddToFavorites" );
|
||||
|
||||
addToFavorites = navToolbar->addAction( QIcon( ":/icons/star.png" ), tr( "Add current tab to Favorites" ) );
|
||||
navToolbar->widgetForAction( addToFavorites )->setObjectName( "addToFavoritesButton" );
|
||||
|
||||
connect( addToFavorites, SIGNAL( triggered() ), this, SLOT( addCurrentTabToFavorites() ) );
|
||||
connect( ui.actionAddToFavorites, SIGNAL( triggered() ), this, SLOT( addCurrentTabToFavorites() ) );
|
||||
|
||||
beforeOptionsSeparator = navToolbar->addSeparator();
|
||||
navToolbar->widgetForAction( beforeOptionsSeparator )->setObjectName( "beforeOptionsSeparator" );
|
||||
beforeOptionsSeparator->setVisible( cfg.preferences.hideMenubar);
|
||||
|
@ -246,6 +254,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
buttonMenu->addAction( ui.dictionaries );
|
||||
buttonMenu->addAction( ui.preferences );
|
||||
buttonMenu->addSeparator();
|
||||
buttonMenu->addMenu( ui.menuFavorites );
|
||||
buttonMenu->addMenu( ui.menuHistory );
|
||||
buttonMenu->addSeparator();
|
||||
buttonMenu->addMenu( ui.menuFile );
|
||||
|
@ -478,6 +487,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
ui.searchPane->toggleViewAction()->setShortcut( QKeySequence( "Ctrl+S" ) );
|
||||
ui.menuView->addAction( ui.dictsPane->toggleViewAction() );
|
||||
ui.dictsPane->toggleViewAction()->setShortcut( QKeySequence( "Ctrl+R" ) );
|
||||
ui.menuView->addAction( ui.favoritesPane->toggleViewAction() );
|
||||
ui.favoritesPane->toggleViewAction()->setShortcut( QKeySequence( "Ctrl+I" ) );
|
||||
ui.menuView->addAction( ui.historyPane->toggleViewAction() );
|
||||
ui.historyPane->toggleViewAction()->setShortcut( QKeySequence( "Ctrl+H" ) );
|
||||
ui.menuView->addSeparator();
|
||||
|
@ -536,6 +547,19 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
connect( &dictionaryBar, SIGNAL( openDictionaryFolder( QString const & ) ),
|
||||
this, SLOT( openDictionaryFolder( QString const & ) ) );
|
||||
|
||||
// Favorites
|
||||
|
||||
ui.favoritesPaneWidget->setUp( &cfg, ui.menuFavorites );
|
||||
|
||||
connect( ui.favoritesPane, SIGNAL( visibilityChanged( bool ) ),
|
||||
this, SLOT( updateFavoritesMenu() ) );
|
||||
|
||||
connect( ui.menuFavorites, SIGNAL( aboutToShow() ),
|
||||
this, SLOT( updateFavoritesMenu() ) );
|
||||
|
||||
connect( ui.favoritesPaneWidget, SIGNAL( favoritesItemRequested( QString, QString ) ),
|
||||
this, SLOT( headwordFromFavorites( QString, QString ) ) );
|
||||
|
||||
// History
|
||||
ui.historyPaneWidget->setUp( &cfg, &history, ui.menuHistory );
|
||||
history.enableAdd( cfg.preferences.storeHistory );
|
||||
|
@ -972,6 +996,7 @@ void MainWindow::addGlobalAction( QAction * action, const char * slot )
|
|||
ui.centralWidget->addAction( action );
|
||||
ui.dictsPane->addAction( action );
|
||||
ui.searchPaneWidget->addAction( action );
|
||||
ui.favoritesPane->addAction( action );
|
||||
ui.historyPane->addAction( action );
|
||||
groupList->addAction( action );
|
||||
translateBox->addAction( action );
|
||||
|
@ -2261,6 +2286,15 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
return true;
|
||||
}
|
||||
|
||||
// Handle Ctrl+I to show the Favorities Pane.
|
||||
if ( ke->key() == Qt::Key_I && ke->modifiers() == Qt::ControlModifier )
|
||||
{
|
||||
if( ev->type() == QEvent::KeyPress )
|
||||
on_showHideFavorites_triggered();
|
||||
ev->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle F3/Shift+F3 shortcuts
|
||||
if ( ke->key() == Qt::Key_F3 )
|
||||
{
|
||||
|
@ -3606,6 +3640,18 @@ void MainWindow::headwordReceived( const QString & word, const QString & ID )
|
|||
translateInputFinished( false, QString( "gdfrom-" )+ ID );
|
||||
}
|
||||
|
||||
void MainWindow::updateFavoritesMenu()
|
||||
{
|
||||
if ( ui.favoritesPane->toggleViewAction()->isChecked() )
|
||||
{
|
||||
ui.showHideFavorites->setText( tr( "&Hide" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.showHideFavorites->setText( tr( "&Show" ) );
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateHistoryMenu()
|
||||
{
|
||||
if ( ui.historyPane->toggleViewAction()->isChecked() )
|
||||
|
@ -3618,6 +3664,12 @@ void MainWindow::updateHistoryMenu()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_showHideFavorites_triggered()
|
||||
{
|
||||
ui.favoritesPane->toggleViewAction()->trigger();
|
||||
ui.favoritesPane->raise(); // useful when the Pane is tabbed.
|
||||
}
|
||||
|
||||
void MainWindow::on_showHideHistory_triggered()
|
||||
{
|
||||
ui.historyPane->toggleViewAction()->trigger();
|
||||
|
@ -3759,6 +3811,145 @@ void MainWindow::on_importHistory_triggered()
|
|||
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
|
||||
}
|
||||
|
||||
void MainWindow::on_exportFavorites_triggered()
|
||||
{
|
||||
QString exportPath;
|
||||
if( cfg.historyExportPath.isEmpty() )
|
||||
exportPath = QDir::homePath();
|
||||
else
|
||||
{
|
||||
exportPath = QDir::fromNativeSeparators( cfg.historyExportPath );
|
||||
if( !QDir( exportPath ).exists() )
|
||||
exportPath = QDir::homePath();
|
||||
}
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName( this, tr( "Export Favorites to file" ),
|
||||
exportPath,
|
||||
tr( "XML files (*.xml);;All files (*.*)" ) );
|
||||
if( fileName.size() == 0)
|
||||
return;
|
||||
|
||||
cfg.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
|
||||
QFile file( fileName );
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) )
|
||||
break;
|
||||
|
||||
QByteArray data;
|
||||
ui.favoritesPaneWidget->getDataInXml( data );
|
||||
|
||||
if( file.write( data ) != data.size() )
|
||||
break;
|
||||
|
||||
file.close();
|
||||
mainStatusBar->showMessage( tr( "Favorites export complete" ), 5000 );
|
||||
return;
|
||||
}
|
||||
QString errStr = QString( tr( "Export error: " ) ) + file.errorString();
|
||||
file.close();
|
||||
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
|
||||
}
|
||||
|
||||
void MainWindow::on_ExportFavoritesToList_triggered()
|
||||
{
|
||||
QString exportPath;
|
||||
if( cfg.historyExportPath.isEmpty() )
|
||||
exportPath = QDir::homePath();
|
||||
else
|
||||
{
|
||||
exportPath = QDir::fromNativeSeparators( cfg.historyExportPath );
|
||||
if( !QDir( exportPath ).exists() )
|
||||
exportPath = QDir::homePath();
|
||||
}
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName( this, tr( "Export Favorites to file as plain list" ),
|
||||
exportPath,
|
||||
tr( "Text files (*.txt);;All files (*.*)" ) );
|
||||
if( fileName.size() == 0)
|
||||
return;
|
||||
|
||||
cfg.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
|
||||
QFile file( fileName );
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) )
|
||||
break;
|
||||
|
||||
// Write UTF-8 BOM
|
||||
QByteArray line;
|
||||
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
|
||||
if ( file.write( line ) != line.size() )
|
||||
break;
|
||||
|
||||
// Write Favorites
|
||||
QString data;
|
||||
ui.favoritesPaneWidget->getDataInPlainText( data );
|
||||
|
||||
line = data.toUtf8();
|
||||
if( file.write( line ) != line.size() )
|
||||
break;
|
||||
|
||||
file.close();
|
||||
mainStatusBar->showMessage( tr( "Favorites export complete" ), 5000 );
|
||||
return;
|
||||
}
|
||||
QString errStr = QString( tr( "Export error: " ) ) + file.errorString();
|
||||
file.close();
|
||||
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
|
||||
}
|
||||
|
||||
void MainWindow::on_importFavorites_triggered()
|
||||
{
|
||||
QString importPath;
|
||||
if( cfg.historyExportPath.isEmpty() )
|
||||
importPath = QDir::homePath();
|
||||
else
|
||||
{
|
||||
importPath = QDir::fromNativeSeparators( cfg.historyExportPath );
|
||||
if( !QDir( importPath ).exists() )
|
||||
importPath = QDir::homePath();
|
||||
}
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName( this, tr( "Import Favorites from file" ),
|
||||
importPath,
|
||||
tr( "XML files (*.xml);;All files (*.*)" ) );
|
||||
if( fileName.size() == 0)
|
||||
return;
|
||||
|
||||
QFileInfo fileInfo( fileName );
|
||||
cfg.historyExportPath = QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() );
|
||||
QString errStr;
|
||||
QFile file( fileName );
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if ( !file.open( QFile::ReadOnly | QIODevice::Text ) )
|
||||
break;
|
||||
|
||||
if( file.error() != QFile::NoError )
|
||||
break;
|
||||
|
||||
QByteArray data = file.readAll();
|
||||
|
||||
if( !ui.favoritesPaneWidget->setDataFromXml( QString::fromUtf8( data.data(), data.size() ) ) )
|
||||
break;
|
||||
|
||||
file.close();
|
||||
mainStatusBar->showMessage( tr( "Favorites import complete" ), 5000 );
|
||||
return;
|
||||
}
|
||||
if( file.error() != QFile::NoError )
|
||||
errStr = QString( tr( "Import error: " ) ) + file.errorString();
|
||||
else
|
||||
errStr = QString( tr( "Data parsing error" ) );
|
||||
|
||||
file.close();
|
||||
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
|
||||
}
|
||||
|
||||
void MainWindow::fillWordListFromHistory()
|
||||
{
|
||||
ui.wordList->setUpdatesEnabled( false );
|
||||
|
@ -4240,6 +4431,18 @@ void MainWindow::showFTSIndexingName( QString const & name )
|
|||
mainStatusBar->setBackgroundMessage( tr( "Now indexing for full-text search: " ) + name );
|
||||
}
|
||||
|
||||
void MainWindow::addCurrentTabToFavorites()
|
||||
{
|
||||
QString folder;
|
||||
Instances::Group const * igrp = groupInstances.findGroup( cfg.lastMainGroupId );
|
||||
if( igrp )
|
||||
folder = igrp->favoritesFolder;
|
||||
|
||||
QString headword = ui.tabWidget->tabText( ui.tabWidget->currentIndex() );
|
||||
|
||||
ui.favoritesPaneWidget->addHeadword( folder, headword );
|
||||
}
|
||||
|
||||
void MainWindow::setGroupByName( QString const & name, bool main_window )
|
||||
{
|
||||
if( main_window )
|
||||
|
@ -4262,6 +4465,27 @@ void MainWindow::setGroupByName( QString const & name, bool main_window )
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::headwordFromFavorites( QString const & headword,
|
||||
QString const & favoritesFolder )
|
||||
{
|
||||
if( !favoritesFolder.isEmpty() )
|
||||
{
|
||||
// Find group by it Favorites folder
|
||||
for( Instances::Groups::size_type i = 0; i < groupInstances.size(); i++ )
|
||||
{
|
||||
if( groupInstances[ i ].favoritesFolder == favoritesFolder )
|
||||
{
|
||||
// Group found. Select it and stop search.
|
||||
if( groupList->currentIndex() != (int)i )
|
||||
groupList->setCurrentIndex( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wordReceived( headword );
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
||||
bool MainWindow::handleGDMessage( MSG * message, long * result )
|
||||
|
|
|
@ -84,6 +84,7 @@ public slots:
|
|||
void wordReceived( QString const & );
|
||||
void headwordReceived( QString const &, QString const & );
|
||||
void setExpandMode( bool expand );
|
||||
void headwordFromFavorites( QString const &, QString const & );
|
||||
|
||||
private:
|
||||
void addGlobalAction( QAction * action, const char * slot );
|
||||
|
@ -127,6 +128,7 @@ private:
|
|||
QAction * beforeScanPopupSeparator, * afterScanPopupSeparator, * beforeOptionsSeparator;
|
||||
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||
QAction * addToFavorites, * beforeAddToFavoritesSeparator;
|
||||
QMenu trayIconMenu;
|
||||
QMenu * tabMenu;
|
||||
QAction * menuButtonAction;
|
||||
|
@ -276,6 +278,8 @@ private slots:
|
|||
|
||||
void showFTSIndexingName( QString const & name );
|
||||
|
||||
void addCurrentTabToFavorites();
|
||||
|
||||
private slots:
|
||||
|
||||
// Executed in response to a user click on an 'add tab' tool button
|
||||
|
@ -412,14 +416,20 @@ private slots:
|
|||
|
||||
void on_rescanFiles_triggered();
|
||||
|
||||
void on_showHideFavorites_triggered();
|
||||
void on_showHideHistory_triggered();
|
||||
void on_exportHistory_triggered();
|
||||
void on_importHistory_triggered();
|
||||
void on_alwaysOnTop_triggered( bool checked );
|
||||
void focusWordList();
|
||||
|
||||
void on_exportFavorites_triggered();
|
||||
void on_importFavorites_triggered();
|
||||
void on_ExportFavoritesToList_triggered();
|
||||
|
||||
void updateSearchPaneAndBar( bool searchInDock );
|
||||
|
||||
void updateFavoritesMenu();
|
||||
void updateHistoryMenu();
|
||||
|
||||
/// Add word to history
|
||||
|
|
|
@ -138,11 +138,23 @@
|
|||
<addaction name="searchInPageAction"/>
|
||||
<addaction name="fullTextSearchAction"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuFavorites">
|
||||
<property name="title">
|
||||
<string>Fa&vorites</string>
|
||||
</property>
|
||||
<addaction name="showHideFavorites"/>
|
||||
<addaction name="exportFavorites"/>
|
||||
<addaction name="ExportFavoritesToList"/>
|
||||
<addaction name="importFavorites"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAddToFavorites"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuView"/>
|
||||
<addaction name="menu_Edit"/>
|
||||
<addaction name="menuSearch"/>
|
||||
<addaction name="menuHistory"/>
|
||||
<addaction name="menuFavorites"/>
|
||||
<addaction name="menu_Help"/>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="searchPane">
|
||||
|
@ -299,6 +311,33 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="favoritesPane">
|
||||
<property name="windowTitle">
|
||||
<string>Favor&ites Pane</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="FavoritesPaneWidget" name="favoritesPaneWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeView" name="favoritesTree"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="historyPane">
|
||||
<property name="windowTitle">
|
||||
<string>&History Pane</string>
|
||||
|
@ -307,7 +346,7 @@
|
|||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="HistoryPaneWidget" name="historyPaneWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
|
@ -594,6 +633,37 @@
|
|||
<string>F1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="showHideFavorites">
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string notr="true">Ctrl+I</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="exportFavorites">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="importFavorites">
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAddToFavorites">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Add current tab to Favorites</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="ExportFavoritesToList">
|
||||
<property name="text">
|
||||
<string>Export to list</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -625,6 +695,12 @@
|
|||
<extends>QListWidget</extends>
|
||||
<header>wordlist.hh</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>FavoritesPaneWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>favoritespanewidget.hh</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>translateLine</tabstop>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MainWindow #translateLine, ScanPopup #translateLine, MainWindow #searchPane #wordList, MainWindow #dictsPane #dictsList,
|
||||
MainWindow #historyPane #historyList
|
||||
MainWindow #historyPane #historyList, MainWindow #favoritesPane #favoritesTree
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ QMainWindow::separator {
|
|||
margin: 2px;
|
||||
}
|
||||
|
||||
MainWindow #historyPane #historyList {
|
||||
MainWindow #historyPane #historyList, MainWindow #favoritesPane #favoritesTree {
|
||||
background: #EAF0F8;
|
||||
color: #52627C;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MainWindow #translateLine, ScanPopup #translateLine, MainWindow #wordList, MainWindow #dictsPane #dictsList,
|
||||
MainWindow #historyPane #historyList
|
||||
MainWindow #historyPane #historyList, MainWindow #favoritesPane #favoritesTree
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MainWindow #translateLine, ScanPopup #translateLine, MainWindow #wordList, MainWindow #dictsPane #dictsList,
|
||||
MainWindow #historyPane #historyList
|
||||
MainWindow #historyPane #historyList, MainWindow #favoritesPane #favoritesTree
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
MainWindow #translateLine, ScanPopup #translateLine, MainWindow #wordList, MainWindow #dictsPane #dictsList, MainWindow #historyPane #historyList
|
||||
MainWindow #translateLine, ScanPopup #translateLine, MainWindow #wordList, MainWindow #dictsPane #dictsList, MainWindow #historyPane #historyList, MainWindow #favoritesPane #favoritesTree
|
||||
{
|
||||
background: #fefdeb;
|
||||
color: black;
|
||||
|
|
|
@ -80,5 +80,7 @@
|
|||
<file>icons/icon32_epwing.png</file>
|
||||
<file>icons/icon32_slob.png</file>
|
||||
<file>icons/icon32_gls.png</file>
|
||||
<file>icons/star.png</file>
|
||||
<file>icons/folder.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in a new issue