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 */
|
|
|
|
|
|
|
|
#include "mainwindow.hh"
|
2009-04-30 15:29:03 +00:00
|
|
|
#include "editdictionaries.hh"
|
|
|
|
#include "loaddictionaries.hh"
|
2009-02-05 20:55:00 +00:00
|
|
|
#include "preferences.hh"
|
2010-11-14 16:28:50 +00:00
|
|
|
#include "about.hh"
|
2009-04-10 12:48:40 +00:00
|
|
|
#include <limits.h>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QToolBar>
|
2009-02-05 20:55:00 +00:00
|
|
|
#include <QCloseEvent>
|
2009-02-08 14:02:27 +00:00
|
|
|
#include <QDesktopServices>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2011-06-19 18:50:11 +00:00
|
|
|
#include "dprintf.hh"
|
2011-06-27 18:54:15 +00:00
|
|
|
#include <QDebug>
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
using std::set;
|
|
|
|
using std::wstring;
|
|
|
|
using std::map;
|
|
|
|
using std::pair;
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
MainWindow::MainWindow( Config::Class & cfg_ ):
|
2010-06-28 15:14:07 +00:00
|
|
|
commitDataCompleted( false ),
|
2012-02-16 14:56:25 +00:00
|
|
|
showHistory( false ),
|
2009-02-05 20:55:00 +00:00
|
|
|
trayIcon( 0 ),
|
2009-04-20 14:13:39 +00:00
|
|
|
groupLabel( &searchPaneTitleBar ),
|
|
|
|
groupList( &searchPaneTitleBar ),
|
2011-06-05 11:49:50 +00:00
|
|
|
foundInDictsLabel( &dictsPaneTitleBar ),
|
2010-04-27 07:49:37 +00:00
|
|
|
escAction( this ),
|
2011-06-29 19:12:46 +00:00
|
|
|
f3Action( this ),
|
|
|
|
shiftF3Action( this ),
|
2009-04-12 22:36:47 +00:00
|
|
|
focusTranslateLineAction( this ),
|
2009-04-09 22:11:38 +00:00
|
|
|
addTabAction( this ),
|
|
|
|
closeCurrentTabAction( this ),
|
2010-09-16 18:52:40 +00:00
|
|
|
closeAllTabAction( this ),
|
|
|
|
closeRestTabAction( this ),
|
2009-04-09 22:11:38 +00:00
|
|
|
switchToNextTabAction( this ),
|
|
|
|
switchToPrevTabAction( this ),
|
2009-10-12 12:41:20 +00:00
|
|
|
showDictBarNamesAction( tr( "Show Names in Dictionary Bar" ), this ),
|
2011-05-22 02:42:05 +00:00
|
|
|
useSmallIconsInToolbarsAction( tr( "Show Small Icons in Toolbars" ), this ),
|
2011-06-26 11:53:28 +00:00
|
|
|
toggleMenuBarAction( tr( "&Menubar" ), this ),
|
2009-02-08 20:20:02 +00:00
|
|
|
trayIconMenu( this ),
|
2009-01-28 20:55:45 +00:00
|
|
|
addTab( this ),
|
2009-04-12 20:46:25 +00:00
|
|
|
cfg( cfg_ ),
|
2012-02-16 14:56:25 +00:00
|
|
|
history( History::Load(), cfg_.preferences.maxStringsInHistory ),
|
2009-09-21 17:50:03 +00:00
|
|
|
dictionaryBar( this, cfg.mutedDictionaries, configEvents ),
|
2009-05-11 11:03:36 +00:00
|
|
|
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle ),
|
2009-08-31 12:18:08 +00:00
|
|
|
articleNetMgr( this, dictionaries, articleMaker,
|
|
|
|
cfg.preferences.disallowContentFromOtherSites ),
|
2009-03-26 19:00:08 +00:00
|
|
|
dictNetMgr( this ),
|
2009-01-29 19:16:25 +00:00
|
|
|
wordFinder( this ),
|
2009-04-20 19:54:34 +00:00
|
|
|
newReleaseCheckTimer( this )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-05-16 18:04:21 +00:00
|
|
|
applyQtStyleSheet( cfg.preferences.displayStyle );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
ui.setupUi( this );
|
|
|
|
|
2011-06-27 18:54:15 +00:00
|
|
|
// use our own, cutsom statusbar
|
|
|
|
setStatusBar(0);
|
|
|
|
mainStatusBar = new MainStatusBar( this );
|
|
|
|
|
2010-07-02 11:19:02 +00:00
|
|
|
wordListDefaultFont = ui.wordList->font();
|
|
|
|
translateLineDefaultFont = ui.translateLine->font();
|
|
|
|
|
2011-06-28 15:55:41 +00:00
|
|
|
ui.wordList->setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
// Make the search pane's titlebar
|
|
|
|
|
|
|
|
groupLabel.setText( tr( "Look up in:" ) );
|
2011-06-28 15:55:41 +00:00
|
|
|
groupList.setFocusPolicy(Qt::ClickFocus);
|
2009-04-20 14:13:39 +00:00
|
|
|
|
2009-04-23 16:21:40 +00:00
|
|
|
searchPaneTitleBarLayout.setContentsMargins( 8, 5, 8, 4 );
|
2009-04-20 14:13:39 +00:00
|
|
|
searchPaneTitleBarLayout.addWidget( &groupLabel );
|
|
|
|
searchPaneTitleBarLayout.addWidget( &groupList );
|
|
|
|
searchPaneTitleBarLayout.addStretch();
|
|
|
|
|
|
|
|
searchPaneTitleBar.setLayout( &searchPaneTitleBarLayout );
|
|
|
|
|
|
|
|
ui.searchPane->setTitleBarWidget( &searchPaneTitleBar );
|
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
// Make the dictionaries pane's titlebar
|
|
|
|
foundInDictsLabel.setText( tr( "Found in Dictionaries:" ) );
|
|
|
|
dictsPaneTitleBarLayout.addWidget( &foundInDictsLabel );
|
|
|
|
dictsPaneTitleBar.setLayout( &dictsPaneTitleBarLayout );
|
|
|
|
ui.dictsPane->setTitleBarWidget( &dictsPaneTitleBar );
|
|
|
|
|
|
|
|
connect( ui.dictsPane, SIGNAL( visibilityChanged( bool ) ),
|
|
|
|
this, SLOT( dictsPaneVisibilityChanged ( bool ) ) );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
// Make the toolbar
|
|
|
|
navToolbar = addToolBar( tr( "Navigation" ) );
|
2009-04-03 21:24:07 +00:00
|
|
|
navToolbar->setObjectName( "navToolbar" );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
navBack = navToolbar->addAction( QIcon( ":/icons/previous.png" ), tr( "Back" ) );
|
|
|
|
navForward = navToolbar->addAction( QIcon( ":/icons/next.png" ), tr( "Forward" ) );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-05-02 21:46:43 +00:00
|
|
|
navToolbar->addSeparator();
|
2009-05-01 12:20:33 +00:00
|
|
|
navToolbar->addAction( ui.print );
|
2009-05-01 11:17:29 +00:00
|
|
|
navToolbar->addAction( ui.saveArticle );
|
|
|
|
|
2011-05-31 03:35:43 +00:00
|
|
|
scanPopupSeparator = navToolbar->addSeparator();
|
|
|
|
scanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
enableScanPopup = navToolbar->addAction( QIcon( ":/icons/wizard.png" ), tr( "Scan Popup" ) );
|
|
|
|
enableScanPopup->setCheckable( true );
|
|
|
|
enableScanPopup->setVisible( cfg.preferences.enableScanPopup );
|
|
|
|
if ( cfg.preferences.enableScanPopup && cfg.preferences.startWithScanPopupOn )
|
|
|
|
enableScanPopup->setChecked( true );
|
|
|
|
|
|
|
|
connect( enableScanPopup, SIGNAL( toggled( bool ) ),
|
|
|
|
this, SLOT( scanEnableToggled( bool ) ) );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
navToolbar->addSeparator();
|
2009-05-14 19:46:25 +00:00
|
|
|
navPronounce = navToolbar->addAction( QIcon( ":/icons/playsound.png" ), tr( "Pronounce Word (Alt+S)" ) );
|
|
|
|
navPronounce->setShortcut( QKeySequence( "Alt+S" ) );
|
2009-04-10 21:07:03 +00:00
|
|
|
navPronounce->setEnabled( false );
|
|
|
|
|
|
|
|
connect( navPronounce, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( pronounce() ) );
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
// zooming
|
|
|
|
navToolbar->addSeparator();
|
2009-05-01 20:10:47 +00:00
|
|
|
zoomIn = navToolbar->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Zoom In" ) );
|
2010-07-02 11:19:02 +00:00
|
|
|
zoomIn->setShortcut( QKeySequence::ZoomIn );
|
2009-05-01 20:10:47 +00:00
|
|
|
zoomOut = navToolbar->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Zoom Out" ) );
|
2010-07-02 11:19:02 +00:00
|
|
|
zoomOut->setShortcut( QKeySequence::ZoomOut );
|
2009-05-01 20:10:47 +00:00
|
|
|
zoomBase = navToolbar->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Normal Size" ) );
|
2010-07-02 11:19:02 +00:00
|
|
|
zoomBase->setShortcut( QKeySequence( "Ctrl+0" ) );
|
2009-04-30 19:57:25 +00:00
|
|
|
|
|
|
|
connect( zoomIn, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( zoomin() ) );
|
|
|
|
connect( zoomOut, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( zoomout() ) );
|
|
|
|
connect( zoomBase, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( unzoom() ) );
|
|
|
|
|
2010-07-02 11:19:02 +00:00
|
|
|
ui.menuZoom->addAction( zoomIn );
|
|
|
|
ui.menuZoom->addAction( zoomOut );
|
|
|
|
ui.menuZoom->addAction( zoomBase );
|
|
|
|
|
|
|
|
ui.menuZoom->addSeparator();
|
|
|
|
|
|
|
|
wordsZoomIn = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Words Zoom In" ) );
|
|
|
|
wordsZoomIn->setShortcut( QKeySequence( "Alt++" ) );
|
|
|
|
wordsZoomOut = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Words Zoom Out" ) );
|
|
|
|
wordsZoomOut->setShortcut( QKeySequence( "Alt+-" ) );
|
|
|
|
wordsZoomBase = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Words Normal Size" ) );
|
|
|
|
wordsZoomBase->setShortcut( QKeySequence( "Alt+0" ) );
|
|
|
|
|
|
|
|
connect( wordsZoomIn, SIGNAL(triggered()), this, SLOT(doWordsZoomIn()) );
|
|
|
|
connect( wordsZoomOut, SIGNAL(triggered()), this, SLOT(doWordsZoomOut()) );
|
|
|
|
connect( wordsZoomBase, SIGNAL(triggered()), this, SLOT(doWordsZoomBase()) );
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
// tray icon
|
2009-02-08 20:20:02 +00:00
|
|
|
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( activated() ),
|
|
|
|
this, SLOT( showMainWindow() ) );
|
|
|
|
trayIconMenu.addAction( enableScanPopup );
|
|
|
|
trayIconMenu.addSeparator();
|
|
|
|
connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( activated() ),
|
|
|
|
qApp, SLOT( quit() ) );
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2010-04-27 07:49:37 +00:00
|
|
|
escAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
escAction.setShortcut( QKeySequence( "Esc" ) );
|
|
|
|
connect( &escAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( handleEsc() ) );
|
|
|
|
|
2011-06-29 19:12:46 +00:00
|
|
|
f3Action.setShortcutContext( Qt::ApplicationShortcut );
|
|
|
|
f3Action.setShortcut( QKeySequence( "F3" ) );
|
|
|
|
connect( &f3Action, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( handleF3() ) );
|
|
|
|
|
|
|
|
addAction( &f3Action );
|
|
|
|
|
|
|
|
shiftF3Action.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
shiftF3Action.setShortcut( QKeySequence( "Shift+F3" ) );
|
|
|
|
connect( &shiftF3Action, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( handleShiftF3() ) );
|
|
|
|
|
|
|
|
addAction( &shiftF3Action );
|
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
focusTranslateLineAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
2010-01-13 18:04:39 +00:00
|
|
|
focusTranslateLineAction.setShortcuts( QList< QKeySequence >() <<
|
|
|
|
QKeySequence( "Alt+D" ) <<
|
|
|
|
QKeySequence( "Ctrl+L" ) );
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
connect( &focusTranslateLineAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( focusTranslateLine() ) );
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2010-04-27 07:49:37 +00:00
|
|
|
ui.centralWidget->addAction( &escAction );
|
2011-06-05 11:49:50 +00:00
|
|
|
ui.dictsPane->addAction( &escAction );
|
2010-04-27 07:49:37 +00:00
|
|
|
ui.searchPaneWidget->addAction( &escAction );
|
|
|
|
groupList.addAction( &escAction );
|
2011-06-05 11:49:50 +00:00
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
ui.centralWidget->addAction( &focusTranslateLineAction );
|
2011-06-05 11:49:50 +00:00
|
|
|
ui.dictsPane->addAction( &focusTranslateLineAction );
|
2009-04-20 13:24:55 +00:00
|
|
|
ui.searchPaneWidget->addAction( &focusTranslateLineAction );
|
2009-04-22 22:47:44 +00:00
|
|
|
groupList.addAction( &focusTranslateLineAction );
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2009-04-09 22:11:38 +00:00
|
|
|
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
// Tab management
|
|
|
|
|
2009-04-09 22:11:38 +00:00
|
|
|
connect( &addTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( addNewTab() ) );
|
|
|
|
|
2009-04-29 23:55:41 +00:00
|
|
|
addAction( &addTabAction );
|
2009-04-09 22:11:38 +00:00
|
|
|
|
|
|
|
closeCurrentTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
closeCurrentTabAction.setShortcut( QKeySequence( "Ctrl+W" ) );
|
2010-09-16 18:52:40 +00:00
|
|
|
closeCurrentTabAction.setText( tr("Close current tab") );
|
|
|
|
closeCurrentTabAction.setIcon( QIcon(":/icons/closetab.png") );
|
2009-04-09 22:11:38 +00:00
|
|
|
|
|
|
|
connect( &closeCurrentTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( closeCurrentTab() ) );
|
|
|
|
|
2009-04-29 23:55:41 +00:00
|
|
|
addAction( &closeCurrentTabAction );
|
2009-04-09 22:11:38 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
closeAllTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
closeAllTabAction.setShortcut( QKeySequence( "Ctrl+Shift+W" ) );
|
|
|
|
closeAllTabAction.setText( tr("Close all tabs") );
|
|
|
|
|
|
|
|
connect( &closeAllTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( closeAllTabs() ) );
|
|
|
|
|
|
|
|
addAction( &closeAllTabAction );
|
|
|
|
|
|
|
|
closeRestTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
closeRestTabAction.setText( tr("Close all tabs except current") );
|
|
|
|
|
|
|
|
connect( &closeRestTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( closeRestTabs() ) );
|
|
|
|
|
|
|
|
addAction( &closeRestTabAction );
|
|
|
|
|
2009-04-09 22:11:38 +00:00
|
|
|
switchToNextTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
switchToNextTabAction.setShortcut( QKeySequence( "Ctrl+PgDown" ) );
|
|
|
|
|
|
|
|
connect( &switchToNextTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( switchToNextTab() ) );
|
|
|
|
|
2009-04-29 23:55:41 +00:00
|
|
|
addAction( &switchToNextTabAction );
|
2009-04-09 22:11:38 +00:00
|
|
|
|
|
|
|
switchToPrevTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
switchToPrevTabAction.setShortcut( QKeySequence( "Ctrl+PgUp" ) );
|
|
|
|
|
|
|
|
connect( &switchToPrevTabAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( switchToPrevTab() ) );
|
|
|
|
|
2009-04-29 23:55:41 +00:00
|
|
|
addAction( &switchToPrevTabAction );
|
2009-04-09 22:11:38 +00:00
|
|
|
|
2009-10-12 12:41:20 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
tabMenu = new QMenu(this);
|
|
|
|
tabMenu->addAction( &closeCurrentTabAction );
|
|
|
|
tabMenu->addAction( &closeRestTabAction );
|
|
|
|
tabMenu->addSeparator();
|
|
|
|
tabMenu->addAction( &closeAllTabAction );
|
|
|
|
|
|
|
|
// Dictionary bar names
|
|
|
|
|
2009-10-12 12:41:20 +00:00
|
|
|
showDictBarNamesAction.setCheckable( true );
|
|
|
|
showDictBarNamesAction.setChecked( cfg.showingDictBarNames );
|
|
|
|
|
|
|
|
connect( &showDictBarNamesAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( showDictBarNamesTriggered() ) );
|
|
|
|
|
2011-05-22 02:42:05 +00:00
|
|
|
// Use small icons in toolbars
|
|
|
|
|
|
|
|
useSmallIconsInToolbarsAction.setCheckable( true );
|
|
|
|
useSmallIconsInToolbarsAction.setChecked( cfg.usingSmallIconsInToolbars );
|
|
|
|
|
|
|
|
connect( &useSmallIconsInToolbarsAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( useSmallIconsInToolbarsTriggered() ) );
|
|
|
|
|
2011-06-26 11:53:28 +00:00
|
|
|
// Toggle Menubar
|
|
|
|
toggleMenuBarAction.setCheckable( true );
|
|
|
|
toggleMenuBarAction.setChecked( true );
|
|
|
|
toggleMenuBarAction.setShortcut( QKeySequence( "Ctrl+M" ) );
|
|
|
|
|
|
|
|
connect( &toggleMenuBarAction, SIGNAL( triggered() ),
|
|
|
|
this, SLOT( toggleMenuBarTriggered() ) );
|
|
|
|
|
2011-05-22 02:42:05 +00:00
|
|
|
// Populate 'View' menu
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2011-06-26 11:53:28 +00:00
|
|
|
ui.menuView->addAction( &toggleMenuBarAction );
|
2009-09-23 18:44:38 +00:00
|
|
|
ui.menuView->addAction( ui.searchPane->toggleViewAction() );
|
2011-06-05 11:49:50 +00:00
|
|
|
ui.menuView->addAction( ui.dictsPane->toggleViewAction() );
|
2009-09-23 18:44:38 +00:00
|
|
|
ui.menuView->addSeparator();
|
|
|
|
ui.menuView->addAction( dictionaryBar.toggleViewAction() );
|
|
|
|
ui.menuView->addAction( navToolbar->toggleViewAction() );
|
2009-10-12 12:41:20 +00:00
|
|
|
ui.menuView->addSeparator();
|
|
|
|
ui.menuView->addAction( &showDictBarNamesAction );
|
2011-05-22 02:42:05 +00:00
|
|
|
ui.menuView->addAction( &useSmallIconsInToolbarsAction );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
// Dictionary bar
|
|
|
|
|
2009-10-12 12:41:20 +00:00
|
|
|
showDictBarNamesTriggered(); // Make update its state according to initial
|
|
|
|
// setting
|
|
|
|
|
2011-05-22 02:42:05 +00:00
|
|
|
useSmallIconsInToolbarsTriggered();
|
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
addToolBar( &dictionaryBar );
|
|
|
|
|
2009-09-24 12:20:20 +00:00
|
|
|
connect( dictionaryBar.toggleViewAction(), SIGNAL(triggered(bool)),
|
|
|
|
this, SLOT(dictionaryBarToggled(bool)) );
|
|
|
|
// This one will be disconnected once the slot is activated. It exists
|
|
|
|
// only to handle the initial appearance of the dictionary bar.
|
2009-09-23 18:44:38 +00:00
|
|
|
connect( dictionaryBar.toggleViewAction(), SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(dictionaryBarToggled(bool)) );
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
connect( &dictionaryBar, SIGNAL(editGroupRequested()),
|
|
|
|
this, SLOT(editCurrentGroup()) );
|
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
// History
|
2012-02-16 14:56:25 +00:00
|
|
|
/*
|
2009-10-21 19:37:07 +00:00
|
|
|
connect( &history, SIGNAL( itemsChanged() ),
|
|
|
|
this, SLOT( historyChanged() ) );
|
|
|
|
|
2009-11-01 16:20:26 +00:00
|
|
|
connect( ui.menuHistory, SIGNAL(triggered(QAction*)),
|
|
|
|
this, SLOT(menuHistoryTriggered(QAction*)), Qt::QueuedConnection );
|
2012-02-16 14:56:25 +00:00
|
|
|
*/
|
2009-11-01 16:20:26 +00:00
|
|
|
|
2009-10-09 21:03:55 +00:00
|
|
|
// Show tray icon early so the user would be happy. It won't be functional
|
|
|
|
// though until the program inits fully.
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-10-09 21:03:55 +00:00
|
|
|
if ( cfg.preferences.enableTrayIcon )
|
|
|
|
{
|
|
|
|
trayIcon = new QSystemTrayIcon( QIcon( ":/icons/programicon.png" ), this );
|
2009-02-08 20:20:02 +00:00
|
|
|
trayIcon->setToolTip( tr( "Loading..." ) );
|
2009-10-09 21:03:55 +00:00
|
|
|
trayIcon->show();
|
|
|
|
}
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
connect( navBack, SIGNAL( activated() ),
|
|
|
|
this, SLOT( backClicked() ) );
|
|
|
|
connect( navForward, SIGNAL( activated() ),
|
|
|
|
this, SLOT( forwardClicked() ) );
|
|
|
|
|
|
|
|
addTab.setAutoRaise( true );
|
2011-07-10 10:29:52 +00:00
|
|
|
addTab.setToolTip( tr( "New Tab" ) );
|
2011-06-28 15:55:41 +00:00
|
|
|
addTab.setFocusPolicy(Qt::ClickFocus);
|
2009-01-28 20:55:45 +00:00
|
|
|
addTab.setIcon( QIcon( ":/icons/addtab.png" ) );
|
|
|
|
|
2011-06-23 14:17:09 +00:00
|
|
|
ui.tabWidget->setHideSingleTab(cfg.preferences.hideSingleTab);
|
2009-01-28 20:55:45 +00:00
|
|
|
ui.tabWidget->clear();
|
|
|
|
|
|
|
|
ui.tabWidget->setCornerWidget( &addTab, Qt::TopLeftCorner );
|
|
|
|
//ui.tabWidget->setCornerWidget( &closeTab, Qt::TopRightCorner );
|
|
|
|
|
2009-04-29 23:18:26 +00:00
|
|
|
#if QT_VERSION >= 0x040500
|
2009-01-28 20:55:45 +00:00
|
|
|
ui.tabWidget->setMovable( true );
|
2009-04-29 23:18:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef Q_OS_WIN32
|
2009-01-28 20:55:45 +00:00
|
|
|
ui.tabWidget->setDocumentMode( true );
|
2009-04-29 23:18:26 +00:00
|
|
|
#endif
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
ui.tabWidget->setContextMenuPolicy( Qt::CustomContextMenu );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
connect( &addTab, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( addNewTab() ) );
|
|
|
|
|
2011-07-19 10:03:13 +00:00
|
|
|
connect( ui.tabWidget, SIGNAL( doubleClicked() ),
|
|
|
|
this, SLOT( addNewTab() ) );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
connect( ui.tabWidget, SIGNAL( tabCloseRequested( int ) ),
|
|
|
|
this, SLOT( tabCloseRequested( int ) ) );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
connect( ui.tabWidget, SIGNAL( currentChanged( int ) ),
|
|
|
|
this, SLOT( tabSwitched( int ) ) );
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
connect( ui.tabWidget, SIGNAL( customContextMenuRequested(QPoint)) ,
|
|
|
|
this, SLOT( tabMenuRequested(QPoint)) );
|
|
|
|
|
2009-04-29 23:18:26 +00:00
|
|
|
#if QT_VERSION >= 0x040500
|
2009-01-28 20:55:45 +00:00
|
|
|
ui.tabWidget->setTabsClosable( true );
|
2009-04-29 23:18:26 +00:00
|
|
|
#endif
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
connect( ui.quit, SIGNAL( activated() ),
|
|
|
|
qApp, SLOT( quit() ) );
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
connect( ui.dictionaries, SIGNAL( activated() ),
|
|
|
|
this, SLOT( editDictionaries() ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
connect( ui.preferences, SIGNAL( activated() ),
|
|
|
|
this, SLOT( editPreferences() ) );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
connect( ui.visitHomepage, SIGNAL( activated() ),
|
|
|
|
this, SLOT( visitHomepage() ) );
|
|
|
|
connect( ui.visitForum, SIGNAL( activated() ),
|
|
|
|
this, SLOT( visitForum() ) );
|
2011-07-10 07:36:43 +00:00
|
|
|
connect( ui.openConfigFolder, SIGNAL( activated() ),
|
|
|
|
this, SLOT( openConfigFolder() ) );
|
2009-02-08 14:02:27 +00:00
|
|
|
connect( ui.about, SIGNAL( activated() ),
|
|
|
|
this, SLOT( showAbout() ) );
|
2009-02-05 20:55:00 +00:00
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
connect( &groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
2009-02-06 17:04:11 +00:00
|
|
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
|
|
|
|
this, SLOT( translateInputChanged( QString const & ) ) );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
connect( ui.translateLine, SIGNAL( returnPressed() ),
|
|
|
|
this, SLOT( translateInputFinished() ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
connect( ui.wordList, SIGNAL( itemSelectionChanged() ),
|
|
|
|
this, SLOT( wordListSelectionChanged() ) );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
connect( ui.dictsList, SIGNAL( itemSelectionChanged() ),
|
|
|
|
this, SLOT( dictsListSelectionChanged() ) );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
connect( &wordFinder, SIGNAL( updated() ),
|
|
|
|
this, SLOT( prefixMatchUpdated() ) );
|
|
|
|
connect( &wordFinder, SIGNAL( finished() ),
|
|
|
|
this, SLOT( prefixMatchFinished() ) );
|
2009-01-29 19:16:25 +00:00
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
connect( &configEvents, SIGNAL( mutedDictionariesChanged() ),
|
|
|
|
this, SLOT( mutedDictionariesChanged() ) );
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
ui.translateLine->installEventFilter( this );
|
|
|
|
ui.wordList->installEventFilter( this );
|
2011-06-07 08:26:49 +00:00
|
|
|
ui.wordList->viewport()->installEventFilter( this );
|
|
|
|
ui.dictsList->installEventFilter( this );
|
|
|
|
ui.dictsList->viewport()->installEventFilter( this );
|
2009-03-29 17:38:54 +00:00
|
|
|
|
2009-04-03 21:24:07 +00:00
|
|
|
if ( cfg.mainWindowGeometry.size() )
|
|
|
|
restoreGeometry( cfg.mainWindowGeometry );
|
|
|
|
|
|
|
|
if ( cfg.mainWindowState.size() )
|
2009-04-20 13:24:55 +00:00
|
|
|
restoreState( cfg.mainWindowState, 1 );
|
2009-04-03 21:24:07 +00:00
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
applyProxySettings();
|
2011-05-08 21:19:08 +00:00
|
|
|
applyWebSettings();
|
2009-04-03 17:10:27 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
makeDictionaries();
|
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
// After we have dictionaries and groups, we can populate history
|
2012-02-16 14:56:25 +00:00
|
|
|
// historyChanged();
|
2009-10-21 19:37:07 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
addNewTab();
|
2009-01-29 19:16:25 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
// Create tab list menu
|
|
|
|
createTabList();
|
|
|
|
|
2009-02-08 18:35:29 +00:00
|
|
|
// Show the initial welcome text
|
|
|
|
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-02-08 18:35:29 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->showDefinition( tr( "Welcome!" ), Instances::Group::HelpGroupId );
|
2009-02-08 18:35:29 +00:00
|
|
|
}
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
ui.translateLine->setFocus();
|
2009-02-05 20:55:00 +00:00
|
|
|
|
2009-10-09 21:03:55 +00:00
|
|
|
if ( trayIcon )
|
|
|
|
{
|
|
|
|
// Upgrade existing dummy tray icon into a full-functional one
|
|
|
|
|
|
|
|
trayIcon->setContextMenu( &trayIconMenu );
|
|
|
|
trayIcon->show();
|
|
|
|
|
|
|
|
connect( trayIcon, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ),
|
|
|
|
this, SLOT( trayIconActivated( QSystemTrayIcon::ActivationReason ) ) );
|
|
|
|
}
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
updateTrayIcon();
|
|
|
|
|
2009-04-30 22:09:04 +00:00
|
|
|
// Update zoomers
|
|
|
|
applyZoomFactor();
|
2010-07-02 11:19:02 +00:00
|
|
|
applyWordsZoomLevel();
|
2009-04-30 22:09:04 +00:00
|
|
|
|
2009-04-18 18:47:01 +00:00
|
|
|
// Update autostart info
|
|
|
|
setAutostart(cfg.preferences.autoStart);
|
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
// Initialize global hotkeys
|
2009-04-21 18:27:26 +00:00
|
|
|
installHotKeys();
|
2009-04-19 21:32:18 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
// Only show window initially if it wasn't configured differently
|
|
|
|
if ( !cfg.preferences.enableTrayIcon || !cfg.preferences.startToTray )
|
2009-05-13 13:47:51 +00:00
|
|
|
{
|
2009-02-05 20:55:00 +00:00
|
|
|
show();
|
2009-05-13 13:47:51 +00:00
|
|
|
focusTranslateLine();
|
|
|
|
}
|
2009-04-20 19:54:34 +00:00
|
|
|
|
|
|
|
connect( &newReleaseCheckTimer, SIGNAL( timeout() ),
|
|
|
|
this, SLOT( checkForNewRelease() ) );
|
|
|
|
|
2011-06-26 11:53:28 +00:00
|
|
|
if ( cfg.preferences.hideMenubar )
|
|
|
|
{
|
|
|
|
toggleMenuBarTriggered( false );
|
|
|
|
}
|
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
prepareNewReleaseChecks();
|
2009-05-17 22:02:54 +00:00
|
|
|
|
|
|
|
// makeDictionaries() didn't do deferred init - we do it here, at the end.
|
|
|
|
doDeferredInit( dictionaries );
|
2011-06-27 18:54:15 +00:00
|
|
|
|
|
|
|
updateStatusLine();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 11:40:54 +00:00
|
|
|
void MainWindow::mousePressEvent( QMouseEvent *event)
|
|
|
|
{
|
2011-06-07 08:26:49 +00:00
|
|
|
|
|
|
|
if (handleBackForwardMouseButtons( event ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
if (event->button() != Qt::MidButton)
|
|
|
|
return QMainWindow::mousePressEvent(event);
|
2011-06-07 08:26:49 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
// middle clicked
|
2011-06-07 08:26:49 +00:00
|
|
|
QString subtype = "plain";
|
2010-09-16 18:52:40 +00:00
|
|
|
|
|
|
|
QString str = QApplication::clipboard()->text(subtype,
|
|
|
|
QClipboard::Selection);
|
|
|
|
ui.translateLine->setText(str);
|
2009-07-31 11:40:54 +00:00
|
|
|
|
2011-06-09 07:29:21 +00:00
|
|
|
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Enter,
|
2010-09-16 18:52:40 +00:00
|
|
|
Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(ui.translateLine, &ev);
|
2009-07-31 11:40:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2010-06-28 15:14:07 +00:00
|
|
|
commitData();
|
2009-05-23 14:19:57 +00:00
|
|
|
|
|
|
|
// Close all tabs -- they should be destroyed before network managers
|
|
|
|
// do.
|
|
|
|
while( ui.tabWidget->count() )
|
|
|
|
{
|
|
|
|
QWidget * w = ui.tabWidget->widget( 0 );
|
|
|
|
|
|
|
|
ui.tabWidget->removeTab( 0 );
|
|
|
|
|
|
|
|
delete w;
|
|
|
|
}
|
2012-02-16 14:56:25 +00:00
|
|
|
|
|
|
|
history.save();
|
2009-02-06 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:14:07 +00:00
|
|
|
void MainWindow::commitData( QSessionManager & )
|
|
|
|
{
|
|
|
|
commitData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::commitData()
|
|
|
|
{
|
|
|
|
if ( !commitDataCompleted )
|
|
|
|
{
|
|
|
|
commitDataCompleted = true;
|
|
|
|
|
|
|
|
// Save MainWindow state and geometry
|
|
|
|
cfg.mainWindowState = saveState( 1 );
|
|
|
|
cfg.mainWindowGeometry = saveGeometry();
|
|
|
|
|
|
|
|
// Close the popup, so it would save its geometry to config
|
|
|
|
|
|
|
|
scanPopup.reset();
|
|
|
|
|
|
|
|
// Save any changes in last chosen groups etc
|
|
|
|
Config::save( cfg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-11 09:40:32 +00:00
|
|
|
QPrinter & MainWindow::getPrinter()
|
|
|
|
{
|
|
|
|
if ( printer.get() )
|
|
|
|
return *printer;
|
|
|
|
|
|
|
|
printer = new QPrinter( QPrinter::HighResolution );
|
|
|
|
|
|
|
|
return *printer;
|
|
|
|
}
|
|
|
|
|
2009-05-11 11:03:36 +00:00
|
|
|
void MainWindow::applyQtStyleSheet( QString const & displayStyle )
|
|
|
|
{
|
|
|
|
QFile builtInCssFile( ":/qt-style.css" );
|
|
|
|
builtInCssFile.open( QFile::ReadOnly );
|
|
|
|
QByteArray css = builtInCssFile.readAll();
|
|
|
|
|
|
|
|
if ( displayStyle.size() )
|
|
|
|
{
|
|
|
|
// Load an additional stylesheet
|
|
|
|
QFile builtInCssFile( QString( ":/qt-style-st-%1.css" ).arg( displayStyle ) );
|
|
|
|
builtInCssFile.open( QFile::ReadOnly );
|
|
|
|
css += builtInCssFile.readAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try loading a style sheet if there's one
|
|
|
|
QFile cssFile( Config::getUserQtCssFileName() );
|
|
|
|
|
|
|
|
if ( cssFile.open( QFile::ReadOnly ) )
|
|
|
|
css += cssFile.readAll();
|
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
setStyleSheet( css );
|
2009-05-11 11:03:36 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
void MainWindow::updateTrayIcon()
|
|
|
|
{
|
|
|
|
if ( !trayIcon && cfg.preferences.enableTrayIcon )
|
|
|
|
{
|
|
|
|
// Need to show it
|
|
|
|
trayIcon = new QSystemTrayIcon( QIcon( ":/icons/programicon.png" ), this );
|
2009-02-08 20:20:02 +00:00
|
|
|
trayIcon->setContextMenu( &trayIconMenu );
|
2009-02-05 20:55:00 +00:00
|
|
|
trayIcon->show();
|
|
|
|
|
|
|
|
connect( trayIcon, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ),
|
|
|
|
this, SLOT( trayIconActivated( QSystemTrayIcon::ActivationReason ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( trayIcon && !cfg.preferences.enableTrayIcon )
|
|
|
|
{
|
|
|
|
// Need to hide it
|
|
|
|
delete trayIcon;
|
|
|
|
|
|
|
|
trayIcon = 0;
|
|
|
|
}
|
|
|
|
if ( trayIcon )
|
2009-02-08 20:20:02 +00:00
|
|
|
{
|
|
|
|
// Update the icon to reflect the scanning mode
|
|
|
|
trayIcon->setIcon( QIcon(
|
|
|
|
enableScanPopup->isChecked() ?
|
|
|
|
":/icons/programicon_scan.png" :
|
|
|
|
":/icons/programicon.png" ) );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
trayIcon->setToolTip( "GoldenDict" );
|
2009-02-08 20:20:02 +00:00
|
|
|
}
|
2009-04-20 12:25:26 +00:00
|
|
|
|
|
|
|
// The 'Close to tray' action is associated with the tray icon, so we hide
|
|
|
|
// or show it here.
|
|
|
|
ui.actionCloseToTray->setVisible( cfg.preferences.enableTrayIcon );
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeEvent( QCloseEvent * ev )
|
|
|
|
{
|
|
|
|
if ( cfg.preferences.enableTrayIcon && cfg.preferences.closeToTray )
|
|
|
|
{
|
|
|
|
ev->ignore();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
else
|
2010-05-08 13:57:41 +00:00
|
|
|
{
|
2009-02-05 20:55:00 +00:00
|
|
|
ev->accept();
|
2010-05-08 13:57:41 +00:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
void MainWindow::applyProxySettings()
|
|
|
|
{
|
2009-04-13 17:31:05 +00:00
|
|
|
QNetworkProxy::ProxyType type = QNetworkProxy::NoProxy;
|
2009-04-03 17:10:27 +00:00
|
|
|
|
2009-04-13 17:31:05 +00:00
|
|
|
if ( cfg.preferences.proxyServer.enabled )
|
|
|
|
{
|
|
|
|
switch( cfg.preferences.proxyServer.type )
|
|
|
|
{
|
|
|
|
case Config::ProxyServer::Socks5:
|
|
|
|
type = QNetworkProxy::Socks5Proxy;
|
|
|
|
break;
|
|
|
|
case Config::ProxyServer::HttpConnect:
|
|
|
|
type = QNetworkProxy::HttpProxy;
|
|
|
|
break;
|
|
|
|
case Config::ProxyServer::HttpGet:
|
|
|
|
type = QNetworkProxy::HttpCachingProxy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkProxy proxy( type );
|
|
|
|
|
|
|
|
if ( cfg.preferences.proxyServer.enabled )
|
|
|
|
{
|
2009-04-03 17:10:27 +00:00
|
|
|
proxy.setHostName( cfg.preferences.proxyServer.host );
|
|
|
|
proxy.setPort( cfg.preferences.proxyServer.port );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
if ( cfg.preferences.proxyServer.user.size() )
|
|
|
|
proxy.setUser( cfg.preferences.proxyServer.user );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
if ( cfg.preferences.proxyServer.password.size() )
|
|
|
|
proxy.setPassword( cfg.preferences.proxyServer.password );
|
2009-04-13 17:31:05 +00:00
|
|
|
}
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-04-13 17:31:05 +00:00
|
|
|
QNetworkProxy::setApplicationProxy( proxy );
|
2009-04-03 17:10:27 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 21:19:08 +00:00
|
|
|
void MainWindow::applyWebSettings()
|
|
|
|
{
|
|
|
|
QWebSettings *defaultSettings = QWebSettings::globalSettings();
|
|
|
|
defaultSettings->setAttribute(QWebSettings::PluginsEnabled, cfg.preferences.enableWebPlugins);
|
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void MainWindow::makeDictionaries()
|
|
|
|
{
|
2009-03-26 19:00:08 +00:00
|
|
|
scanPopup.reset();
|
|
|
|
|
|
|
|
wordFinder.clear();
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
dictionariesUnmuted.clear();
|
|
|
|
|
2009-05-17 22:02:54 +00:00
|
|
|
loadDictionaries( this, isVisible(), cfg, dictionaries, dictNetMgr, false );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
updateStatusLine();
|
|
|
|
updateGroupList();
|
2009-02-01 00:08:08 +00:00
|
|
|
makeScanPopup();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateStatusLine()
|
|
|
|
{
|
|
|
|
unsigned articleCount = 0, wordCount = 0;
|
|
|
|
|
|
|
|
for( unsigned x = dictionaries.size(); x--; )
|
|
|
|
{
|
|
|
|
articleCount += dictionaries[ x ]->getArticleCount();
|
|
|
|
wordCount += dictionaries[ x ]->getWordCount();
|
|
|
|
}
|
|
|
|
|
2011-06-27 18:54:15 +00:00
|
|
|
mainStatusBar->showMessage( tr( "%1 dictionaries, %2 articles, %3 words" ).
|
2009-01-28 20:55:45 +00:00
|
|
|
arg( dictionaries.size() ).arg( articleCount ).
|
2011-06-27 18:54:15 +00:00
|
|
|
arg( wordCount ), 10000 );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateGroupList()
|
|
|
|
{
|
|
|
|
bool haveGroups = cfg.groups.size();
|
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
groupList.setVisible( haveGroups );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
groupLabel.setText( haveGroups ? tr( "Look up in:" ) : tr( "Look up:" ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
// currentIndexChanged() signal is very trigger-happy. To avoid triggering
|
|
|
|
// it, we disconnect it while we're clearing and filling back groups.
|
2009-04-20 14:13:39 +00:00
|
|
|
disconnect( &groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
2009-02-06 17:04:11 +00:00
|
|
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
groupInstances.clear();
|
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
// Add dictionaryOrder first, as the 'All' group.
|
2009-04-01 12:00:28 +00:00
|
|
|
{
|
2009-05-18 18:01:50 +00:00
|
|
|
Instances::Group g( cfg.dictionaryOrder, dictionaries );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
// Add any missing entries to dictionary order
|
|
|
|
Instances::complementDictionaryOrder( g,
|
|
|
|
Instances::Group( cfg.inactiveDictionaries, dictionaries ),
|
|
|
|
dictionaries );
|
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
g.name = tr( "All" );
|
2010-05-08 14:01:59 +00:00
|
|
|
g.id = Instances::Group::AllGroupId;
|
2009-05-18 18:01:50 +00:00
|
|
|
g.icon = "folder.png";
|
|
|
|
|
|
|
|
groupInstances.push_back( g );
|
2009-04-01 12:00:28 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
for( unsigned x = 0; x < cfg.groups.size(); ++x )
|
|
|
|
groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictionaries ) );
|
|
|
|
|
|
|
|
// Update names for dictionaries that are present, so that they could be
|
|
|
|
// found in case they got moved.
|
|
|
|
Instances::updateNames( cfg, dictionaries );
|
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
groupList.fill( groupInstances );
|
|
|
|
groupList.setCurrentGroup( cfg.lastMainGroupId );
|
2010-11-15 15:22:35 +00:00
|
|
|
updateCurrentGroupProperty();
|
2009-02-06 17:04:11 +00:00
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
updateDictionaryBar();
|
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
connect( &groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
2009-02-06 17:04:11 +00:00
|
|
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
2009-02-01 00:08:08 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
void MainWindow::updateDictionaryBar()
|
|
|
|
{
|
2009-09-23 18:44:38 +00:00
|
|
|
if ( !dictionaryBar.toggleViewAction()->isChecked() )
|
|
|
|
return; // It's not enabled, therefore hidden -- don't waste time
|
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
Instances::Group * grp =
|
|
|
|
groupInstances.findGroup( groupList.getCurrentGroup() );
|
|
|
|
|
2011-05-22 02:42:05 +00:00
|
|
|
if ( grp ) { // Should always be !0, but check as a safeguard
|
2009-09-21 17:50:03 +00:00
|
|
|
dictionaryBar.setDictionaries( grp->dictionaries );
|
2011-05-22 02:42:05 +00:00
|
|
|
|
|
|
|
if ( useSmallIconsInToolbarsAction.isChecked() ) {
|
|
|
|
int extent = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
|
|
|
dictionaryBar.setIconSize( QSize( extent, extent ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
}
|
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
void MainWindow::makeScanPopup()
|
|
|
|
{
|
|
|
|
scanPopup.reset();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
if ( !cfg.preferences.enableScanPopup &&
|
|
|
|
!cfg.preferences.enableClipboardHotkey )
|
2009-02-08 20:20:02 +00:00
|
|
|
return;
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
scanPopup = new ScanPopup( 0, cfg, articleNetMgr, dictionaries, groupInstances,
|
|
|
|
history );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
scanPopup->setStyleSheet( styleSheet() );
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
if ( cfg.preferences.enableScanPopup && enableScanPopup->isChecked() )
|
2009-02-08 20:20:02 +00:00
|
|
|
scanPopup->enableScanning();
|
2010-05-08 14:01:59 +00:00
|
|
|
|
|
|
|
connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned )),
|
|
|
|
this,SLOT(editDictionaries( unsigned )), Qt::QueuedConnection );
|
2011-11-16 12:52:25 +00:00
|
|
|
connect( scanPopup.get(), SIGNAL(sendWordToMainWindow( QString const & )),
|
|
|
|
this,SLOT(wordReceived( QString const & )), Qt::QueuedConnection );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts()
|
2010-09-16 18:52:40 +00:00
|
|
|
{
|
2009-05-18 18:01:50 +00:00
|
|
|
if ( groupInstances.empty() )
|
2009-01-28 20:55:45 +00:00
|
|
|
return dictionaries;
|
|
|
|
|
2009-04-20 14:13:39 +00:00
|
|
|
int current = groupList.currentIndex();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
if ( current < 0 || current >= (int) groupInstances.size() )
|
|
|
|
{
|
|
|
|
// This shouldn't ever happen
|
|
|
|
return dictionaries;
|
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
if ( !dictionaryBar.toggleViewAction()->isChecked() )
|
|
|
|
return groupInstances[ current ].dictionaries;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector< sptr< Dictionary::Class > > const & activeDicts =
|
|
|
|
groupInstances[ current ].dictionaries;
|
|
|
|
|
|
|
|
// Populate the special dictionariesUnmuted array with only unmuted
|
|
|
|
// dictionaries
|
|
|
|
|
|
|
|
dictionariesUnmuted.clear();
|
|
|
|
dictionariesUnmuted.reserve( activeDicts.size() );
|
|
|
|
|
|
|
|
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
|
|
|
if ( !cfg.mutedDictionaries.contains(
|
|
|
|
QString::fromStdString( activeDicts[ x ]->getId() ) ) )
|
|
|
|
dictionariesUnmuted.push_back( activeDicts[ x ] );
|
|
|
|
|
|
|
|
return dictionariesUnmuted;
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
|
|
|
|
void MainWindow::createTabList()
|
|
|
|
{
|
|
|
|
tabListMenu = new QMenu(tr("Opened tabs"), ui.tabWidget);
|
|
|
|
tabListMenu->setIcon(QIcon(":/icons/windows-list.png"));
|
|
|
|
connect(tabListMenu, SIGNAL(aboutToShow()), this, SLOT(fillWindowsMenu()));
|
|
|
|
connect(tabListMenu, SIGNAL(triggered(QAction*)), this, SLOT(switchToWindow(QAction*)));
|
|
|
|
|
|
|
|
tabListButton = new QToolButton(ui.tabWidget);
|
|
|
|
tabListButton->setAutoRaise(true);
|
|
|
|
tabListButton->setIcon(tabListMenu->icon());
|
|
|
|
tabListButton->setMenu(tabListMenu);
|
2011-07-10 10:29:52 +00:00
|
|
|
tabListButton->setToolTip( tr( "Open Tabs List" ) );
|
2010-09-16 18:52:40 +00:00
|
|
|
tabListButton->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
ui.tabWidget->setCornerWidget(tabListButton);
|
2011-06-28 15:55:41 +00:00
|
|
|
tabListButton->setFocusPolicy(Qt::ClickFocus);
|
2010-09-16 18:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::fillWindowsMenu()
|
|
|
|
{
|
|
|
|
tabListMenu->clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < ui.tabWidget->count(); i++)
|
|
|
|
{
|
2010-11-15 18:04:16 +00:00
|
|
|
QAction *act = tabListMenu->addAction( ui.tabWidget->tabIcon( i ),
|
|
|
|
ui.tabWidget->tabText( i ) );
|
|
|
|
act->setData( i );
|
2010-09-16 18:52:40 +00:00
|
|
|
if (ui.tabWidget->currentIndex() == i)
|
|
|
|
{
|
2010-11-15 18:04:16 +00:00
|
|
|
QFont f( act->font() );
|
|
|
|
f.setBold( true );
|
|
|
|
act->setFont( f );
|
2010-09-16 18:52:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::switchToWindow(QAction *act)
|
|
|
|
{
|
|
|
|
int idx = act->data().toInt();
|
|
|
|
ui.tabWidget->setCurrentIndex(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void MainWindow::addNewTab()
|
2009-04-13 12:51:25 +00:00
|
|
|
{
|
|
|
|
createNewTab( true, tr( "(untitled)" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
ArticleView * MainWindow::createNewTab( bool switchToIt,
|
|
|
|
QString const & name )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-04-12 16:22:42 +00:00
|
|
|
ArticleView * view = new ArticleView( this, articleNetMgr, dictionaries,
|
2009-09-23 18:44:38 +00:00
|
|
|
groupInstances, false, cfg,
|
|
|
|
dictionaryBar.toggleViewAction(),
|
2010-03-30 20:15:55 +00:00
|
|
|
&cfg.mutedDictionaries,
|
2009-09-23 18:44:38 +00:00
|
|
|
&groupList );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
connect( view, SIGNAL( titleChanged( ArticleView *, QString const & ) ),
|
|
|
|
this, SLOT( titleChanged( ArticleView *, QString const & ) ) );
|
|
|
|
|
|
|
|
connect( view, SIGNAL( iconChanged( ArticleView *, QIcon const & ) ),
|
|
|
|
this, SLOT( iconChanged( ArticleView *, QIcon const & ) ) );
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
connect( view, SIGNAL( pageLoaded( ArticleView * ) ),
|
|
|
|
this, SLOT( pageLoaded( ArticleView * ) ) );
|
2009-04-10 21:07:03 +00:00
|
|
|
|
2009-05-29 19:48:50 +00:00
|
|
|
connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const &, QString const &, ArticleView::Contexts const & ) ),
|
|
|
|
this, SLOT( openLinkInNewTab( QUrl const &, QUrl const &, QString const &, ArticleView::Contexts const & ) ) );
|
2009-04-13 12:51:25 +00:00
|
|
|
|
2009-05-29 19:48:50 +00:00
|
|
|
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const &, ArticleView::Contexts const & ) ),
|
|
|
|
this, SLOT( showDefinitionInNewTab( QString const &, unsigned, QString const &, ArticleView::Contexts const & ) ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-12 13:25:18 +00:00
|
|
|
connect( view, SIGNAL( typingEvent( QString const & ) ),
|
|
|
|
this, SLOT( typingEvent( QString const & ) ) );
|
|
|
|
|
2011-07-03 12:27:08 +00:00
|
|
|
connect( view, SIGNAL( activeArticleChanged( const QString & ) ),
|
|
|
|
this, SLOT( activeArticleChanged( const QString & ) ) );
|
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
connect( view, SIGNAL( statusBarMessage( QString const &, int, QPixmap const & ) ),
|
|
|
|
this, SLOT( showStatusBarMessage( QString const &, int, QPixmap const & ) ) );
|
2011-07-02 13:04:49 +00:00
|
|
|
|
2011-07-31 00:11:07 +00:00
|
|
|
connect( view, SIGNAL( showDictsPane( ) ), this, SLOT( showDictsPane( ) ) );
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
|
|
|
|
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
|
|
|
|
|
|
|
|
QString escaped = name;
|
|
|
|
escaped.replace( "&", "&&" );
|
|
|
|
|
|
|
|
ui.tabWidget->insertTab( index, view, escaped );
|
|
|
|
|
|
|
|
if ( switchToIt )
|
|
|
|
ui.tabWidget->setCurrentIndex( index );
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
view->setZoomFactor( cfg.preferences.zoomFactor );
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
return view;
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void MainWindow::tabCloseRequested( int x )
|
|
|
|
{
|
2010-09-16 18:52:40 +00:00
|
|
|
// if ( ui.tabWidget->count() < 2 )
|
|
|
|
// return; // We should always have at least one open tab
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
QWidget * w = ui.tabWidget->widget( x );
|
|
|
|
|
|
|
|
ui.tabWidget->removeTab( x );
|
|
|
|
|
|
|
|
delete w;
|
2010-09-16 18:52:40 +00:00
|
|
|
|
|
|
|
// if everything is closed, add new tab
|
|
|
|
if ( ui.tabWidget->count() == 0 )
|
|
|
|
addNewTab();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 22:11:38 +00:00
|
|
|
void MainWindow::closeCurrentTab()
|
|
|
|
{
|
|
|
|
tabCloseRequested( ui.tabWidget->currentIndex() );
|
|
|
|
}
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
void MainWindow::closeAllTabs()
|
|
|
|
{
|
|
|
|
while (ui.tabWidget->count() > 1)
|
|
|
|
closeCurrentTab();
|
|
|
|
|
|
|
|
// close last tab
|
|
|
|
closeCurrentTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeRestTabs()
|
|
|
|
{
|
|
|
|
if ( ui.tabWidget->count() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int idx = ui.tabWidget->currentIndex();
|
|
|
|
|
|
|
|
for (int i = 0; i < idx; i++)
|
|
|
|
tabCloseRequested(0);
|
|
|
|
|
|
|
|
ui.tabWidget->setCurrentIndex(0);
|
|
|
|
|
|
|
|
while (ui.tabWidget->count() > 1)
|
|
|
|
tabCloseRequested(1);
|
|
|
|
}
|
|
|
|
|
2009-04-09 22:11:38 +00:00
|
|
|
void MainWindow::switchToNextTab()
|
|
|
|
{
|
|
|
|
if ( ui.tabWidget->count() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui.tabWidget->setCurrentIndex( ( ui.tabWidget->currentIndex() + 1 ) % ui.tabWidget->count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::switchToPrevTab()
|
|
|
|
{
|
|
|
|
if ( ui.tabWidget->count() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( !ui.tabWidget->currentIndex() )
|
|
|
|
ui.tabWidget->setCurrentIndex( ui.tabWidget->count() - 1 );
|
|
|
|
else
|
|
|
|
ui.tabWidget->setCurrentIndex( ui.tabWidget->currentIndex() - 1 );
|
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void MainWindow::backClicked()
|
|
|
|
{
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "Back\n" );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->back();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::forwardClicked()
|
|
|
|
{
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "Forward\n" );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->forward();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::titleChanged( ArticleView * view, QString const & title )
|
|
|
|
{
|
2009-04-10 21:37:16 +00:00
|
|
|
QString escaped = title;
|
|
|
|
escaped.replace( "&", "&&" );
|
|
|
|
|
|
|
|
ui.tabWidget->setTabText( ui.tabWidget->indexOf( view ), escaped );
|
2011-06-25 07:53:45 +00:00
|
|
|
updateWindowTitle();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::iconChanged( ArticleView * view, QIcon const & icon )
|
|
|
|
{
|
2009-05-18 18:01:50 +00:00
|
|
|
ui.tabWidget->setTabIcon( ui.tabWidget->indexOf( view ), groupInstances.size() > 1 ? icon : QIcon() );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 07:53:45 +00:00
|
|
|
void MainWindow::updateWindowTitle()
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
|
|
|
if ( view )
|
|
|
|
{
|
|
|
|
setWindowTitle( tr( "%1 - %2" ).arg( view->getTitle(), tr ( "GoldenDict" ) ) );
|
|
|
|
}
|
2011-06-25 07:53:45 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
void MainWindow::pageLoaded( ArticleView * view )
|
2009-04-10 21:07:03 +00:00
|
|
|
{
|
2011-06-07 11:27:19 +00:00
|
|
|
updateBackForwardButtons();
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
updatePronounceAvailability();
|
|
|
|
|
|
|
|
if ( cfg.preferences.pronounceOnLoadMain )
|
2009-05-14 19:27:19 +00:00
|
|
|
pronounce( view );
|
2011-06-05 11:49:50 +00:00
|
|
|
|
|
|
|
updateFoundInDictsList();
|
2009-04-10 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 20:11:57 +00:00
|
|
|
void MainWindow::showStatusBarMessage( QString const & message, int timeout, QPixmap const & icon )
|
2011-07-02 13:04:49 +00:00
|
|
|
{
|
2011-07-14 20:11:57 +00:00
|
|
|
mainStatusBar->showMessage( message, timeout, icon );
|
2011-07-02 13:04:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void MainWindow::tabSwitched( int )
|
|
|
|
{
|
2011-06-07 11:27:19 +00:00
|
|
|
updateBackForwardButtons();
|
2009-04-10 21:07:03 +00:00
|
|
|
updatePronounceAvailability();
|
2011-06-05 11:49:50 +00:00
|
|
|
updateFoundInDictsList();
|
2011-06-25 07:53:45 +00:00
|
|
|
updateWindowTitle();
|
2009-04-10 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
void MainWindow::tabMenuRequested(QPoint pos)
|
|
|
|
{
|
|
|
|
// // dont show this menu for single tab
|
|
|
|
// if ( ui.tabWidget->count() < 2 )
|
|
|
|
// return;
|
|
|
|
|
|
|
|
tabMenu->popup(ui.tabWidget->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void MainWindow::dictionaryBarToggled( bool )
|
|
|
|
{
|
2009-09-24 12:20:20 +00:00
|
|
|
// From now on, only the triggered() signal is interesting to us
|
|
|
|
disconnect( dictionaryBar.toggleViewAction(), SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(dictionaryBarToggled(bool)) );
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
updateDictionaryBar(); // Updates dictionary bar contents if it's shown
|
|
|
|
applyMutedDictionariesState(); // Visibility change affects searches and results
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
void MainWindow::pronounce( ArticleView * view )
|
2009-04-10 21:07:03 +00:00
|
|
|
{
|
2009-05-14 19:27:19 +00:00
|
|
|
if ( view )
|
|
|
|
view->playSound();
|
|
|
|
else
|
2011-07-01 19:22:40 +00:00
|
|
|
getCurrentArticleView()->playSound();
|
2009-04-10 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 00:11:07 +00:00
|
|
|
void MainWindow::showDictsPane( )
|
|
|
|
{
|
|
|
|
if( !ui.dictsPane->isVisible() )
|
|
|
|
ui.dictsPane->show();
|
|
|
|
}
|
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
void MainWindow::dictsPaneVisibilityChanged( bool visible )
|
|
|
|
{
|
|
|
|
if (visible) {
|
|
|
|
updateFoundInDictsList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateFoundInDictsList()
|
|
|
|
{
|
|
|
|
if (!ui.dictsList->isVisible())
|
|
|
|
{
|
|
|
|
// nothing to do, the list is not visible
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.dictsList->clear();
|
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2011-06-05 11:49:50 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
if ( view )
|
|
|
|
{
|
|
|
|
QStringList ids = view->getArticlesList();
|
2011-07-03 12:27:08 +00:00
|
|
|
QString activeId = view->getActiveArticleId();
|
2011-06-05 11:49:50 +00:00
|
|
|
|
|
|
|
for( QStringList::const_iterator i = ids.constBegin(); i != ids.constEnd(); ++i)
|
|
|
|
{
|
|
|
|
// Find this dictionary
|
|
|
|
|
|
|
|
for( unsigned x = dictionaries.size(); x--; )
|
|
|
|
{
|
|
|
|
if ( dictionaries[ x ]->getId() == i->toUtf8().data() )
|
|
|
|
{
|
|
|
|
QString dictName = QString::fromUtf8( dictionaries[ x ]->getName().c_str() );
|
2011-07-03 12:27:08 +00:00
|
|
|
QString dictId = QString::fromUtf8( dictionaries[ x ]->getId().c_str() );
|
2011-06-05 11:49:50 +00:00
|
|
|
QListWidgetItem * item =
|
|
|
|
new QListWidgetItem(
|
2011-07-15 12:11:08 +00:00
|
|
|
dictionaries[ x ]->getIcon().pixmap(32).scaledToHeight( 21, Qt::SmoothTransformation ),
|
2011-06-05 11:49:50 +00:00
|
|
|
dictName,
|
|
|
|
ui.dictsList, QListWidgetItem::Type );
|
2011-07-03 12:27:08 +00:00
|
|
|
item->setData(Qt::UserRole, QVariant( dictId ) );
|
2011-06-05 11:49:50 +00:00
|
|
|
item->setToolTip(dictName);
|
|
|
|
|
|
|
|
ui.dictsList->addItem( item );
|
2011-07-03 12:27:08 +00:00
|
|
|
if (dictId == activeId)
|
|
|
|
{
|
|
|
|
ui.dictsList->setCurrentItem(item);
|
|
|
|
}
|
2011-06-05 11:49:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 11:27:19 +00:00
|
|
|
void MainWindow::updateBackForwardButtons()
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
|
|
|
|
|
|
|
if ( view )
|
2011-06-07 11:27:19 +00:00
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
navBack->setEnabled(view->canGoBack());
|
|
|
|
navForward->setEnabled(view->canGoForward());
|
2011-06-07 11:27:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void MainWindow::updatePronounceAvailability()
|
|
|
|
{
|
2009-04-18 18:47:01 +00:00
|
|
|
bool pronounceEnabled = ui.tabWidget->count() > 0 &&
|
2011-07-01 19:22:40 +00:00
|
|
|
getCurrentArticleView()->hasSound();
|
2009-04-10 21:07:03 +00:00
|
|
|
|
|
|
|
navPronounce->setEnabled( pronounceEnabled );
|
|
|
|
}
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
void MainWindow::editDictionaries( unsigned editDictionaryGroup )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-04-30 15:29:03 +00:00
|
|
|
hotkeyWrapper.reset(); // No hotkeys while we're editing dictionaries
|
|
|
|
scanPopup.reset(); // No scan popup either. No one should use dictionaries.
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
wordFinder.clear();
|
|
|
|
dictionariesUnmuted.clear();
|
|
|
|
|
2009-05-15 12:15:08 +00:00
|
|
|
EditDictionaries dicts( this, cfg, dictionaries, groupInstances, dictNetMgr );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
if ( editDictionaryGroup != Instances::Group::NoGroupId )
|
|
|
|
dicts.editGroup( editDictionaryGroup );
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
dicts.exec();
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
if ( dicts.areDictionariesChanged() || dicts.areGroupsChanged() )
|
2009-03-26 19:00:08 +00:00
|
|
|
{
|
2009-04-30 15:29:03 +00:00
|
|
|
updateGroupList();
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
Config::save( cfg );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
makeScanPopup();
|
2009-04-30 15:29:03 +00:00
|
|
|
installHotKeys();
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
void MainWindow::editCurrentGroup()
|
|
|
|
{
|
|
|
|
editDictionaries( groupList.getCurrentGroup() );
|
|
|
|
}
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
void MainWindow::editPreferences()
|
|
|
|
{
|
2009-04-21 18:27:26 +00:00
|
|
|
hotkeyWrapper.reset(); // So we could use the keys it hooks
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
Preferences preferences( this, cfg.preferences );
|
|
|
|
|
|
|
|
preferences.show();
|
|
|
|
|
|
|
|
if ( preferences.exec() == QDialog::Accepted )
|
|
|
|
{
|
2009-05-11 11:03:36 +00:00
|
|
|
Config::Preferences p = preferences.getPreferences();
|
|
|
|
|
|
|
|
// See if we need to reapply stylesheets
|
|
|
|
if ( cfg.preferences.displayStyle != p.displayStyle )
|
|
|
|
{
|
|
|
|
applyQtStyleSheet( p.displayStyle );
|
|
|
|
articleMaker.setDisplayStyle( p.displayStyle );
|
|
|
|
|
|
|
|
for( int x = 0; x < ui.tabWidget->count(); ++x )
|
|
|
|
{
|
|
|
|
ArticleView & view =
|
|
|
|
dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) );
|
|
|
|
|
|
|
|
view.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.preferences = p;
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2011-05-31 03:35:43 +00:00
|
|
|
scanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
|
2009-02-08 20:20:02 +00:00
|
|
|
enableScanPopup->setVisible( cfg.preferences.enableScanPopup );
|
|
|
|
|
|
|
|
if ( !cfg.preferences.enableScanPopup )
|
|
|
|
enableScanPopup->setChecked( false );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
updateTrayIcon();
|
2009-04-03 17:10:27 +00:00
|
|
|
applyProxySettings();
|
2011-05-08 21:19:08 +00:00
|
|
|
applyWebSettings();
|
2009-02-08 20:20:02 +00:00
|
|
|
makeScanPopup();
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2011-06-23 14:17:09 +00:00
|
|
|
ui.tabWidget->setHideSingleTab(cfg.preferences.hideSingleTab);
|
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
setAutostart( cfg.preferences.autoStart );
|
|
|
|
|
|
|
|
prepareNewReleaseChecks();
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
Config::save( cfg );
|
|
|
|
}
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
installHotKeys();
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
void MainWindow::currentGroupChanged( QString const & )
|
2009-02-06 17:04:11 +00:00
|
|
|
{
|
2009-04-20 14:13:39 +00:00
|
|
|
cfg.lastMainGroupId = groupList.getCurrentGroup();
|
2009-02-06 17:04:11 +00:00
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
updateDictionaryBar();
|
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
// Update word search results
|
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
if( !showHistory )
|
|
|
|
translateInputChanged( ui.translateLine->text() );
|
2010-11-15 15:22:35 +00:00
|
|
|
|
|
|
|
updateCurrentGroupProperty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateCurrentGroupProperty()
|
|
|
|
{
|
|
|
|
// We maintain currentGroup property so styles could use that to change
|
|
|
|
// fonts based on group names
|
|
|
|
Instances::Group * grp =
|
|
|
|
groupInstances.findGroup( groupList.getCurrentGroup() );
|
|
|
|
|
|
|
|
if ( grp && ui.translateLine->property( "currentGroup" ).toString() !=
|
|
|
|
grp->name )
|
|
|
|
{
|
|
|
|
ui.translateLine->setProperty( "currentGroup", grp->name );
|
|
|
|
ui.wordList->setProperty( "currentGroup", grp->name );
|
|
|
|
QString ss = styleSheet();
|
|
|
|
|
|
|
|
// Only update stylesheet if it mentions currentGroup, as updating the
|
|
|
|
// stylesheet is a slow operation
|
|
|
|
if ( ss.contains("currentGroup") )
|
|
|
|
setStyleSheet( ss );
|
|
|
|
}
|
2009-02-06 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
void MainWindow::translateInputChanged( QString const & newValue )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-03-26 19:00:08 +00:00
|
|
|
// If there's some status bar message present, clear it since it may be
|
|
|
|
// about the previous search that has failed.
|
2011-06-27 18:54:15 +00:00
|
|
|
if ( !mainStatusBar->currentMessage().isEmpty() )
|
|
|
|
{
|
|
|
|
mainStatusBar->clearMessage();
|
|
|
|
}
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2009-10-21 20:23:03 +00:00
|
|
|
// If some word is selected in the word list, unselect it. This prevents
|
|
|
|
// triggering a set of spurious activation signals when the list changes.
|
|
|
|
|
|
|
|
if ( ui.wordList->selectionModel()->hasSelection() )
|
|
|
|
ui.wordList->setCurrentItem( 0, QItemSelectionModel::Clear );
|
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
QString req = newValue.trimmed();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
if ( !req.size() )
|
|
|
|
{
|
|
|
|
// An empty request always results in an empty result
|
2009-03-26 19:00:08 +00:00
|
|
|
wordFinder.cancel();
|
|
|
|
ui.wordList->clear();
|
|
|
|
ui.wordList->unsetCursor();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
// Reset the noResults mark if it's on right now
|
|
|
|
if ( ui.translateLine->property( "noResults" ).toBool() )
|
|
|
|
{
|
|
|
|
ui.translateLine->setProperty( "noResults", false );
|
2009-05-16 18:04:21 +00:00
|
|
|
setStyleSheet( styleSheet() );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
return;
|
2009-01-29 19:16:25 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
ui.wordList->setCursor( Qt::WaitCursor );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
wordFinder.prefixMatch( req, getActiveDicts() );
|
2009-01-29 19:16:25 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void MainWindow::translateInputFinished()
|
|
|
|
{
|
2009-03-29 17:38:54 +00:00
|
|
|
QString word = ui.translateLine->text();
|
|
|
|
|
|
|
|
if ( word.size() )
|
2009-05-05 20:12:20 +00:00
|
|
|
{
|
|
|
|
Qt::KeyboardModifiers mods = QApplication::keyboardModifiers();
|
2011-05-02 00:37:56 +00:00
|
|
|
if ( mods & (Qt::ControlModifier | Qt::ShiftModifier) )
|
2009-05-05 20:12:20 +00:00
|
|
|
addNewTab();
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
showTranslationFor( word );
|
2009-05-12 13:25:18 +00:00
|
|
|
|
2009-05-13 13:47:51 +00:00
|
|
|
if ( ui.searchPane->isFloating() )
|
|
|
|
activateWindow();
|
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
getCurrentArticleView()->focus();
|
2009-05-05 20:12:20 +00:00
|
|
|
}
|
2009-02-08 14:02:27 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 07:49:37 +00:00
|
|
|
void MainWindow::handleEsc()
|
2009-04-08 22:25:46 +00:00
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
|
|
|
if ( view && view->closeSearch() )
|
2009-05-16 11:14:43 +00:00
|
|
|
return;
|
|
|
|
|
2011-05-07 13:42:49 +00:00
|
|
|
if( cfg.preferences.escKeyHidesMainWindow )
|
2011-05-30 00:44:12 +00:00
|
|
|
{
|
2011-06-24 19:03:03 +00:00
|
|
|
toggleMainWindow();
|
2011-05-30 00:44:12 +00:00
|
|
|
}
|
2011-05-07 13:42:49 +00:00
|
|
|
else
|
|
|
|
focusTranslateLine();
|
2010-04-27 07:49:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-29 19:12:46 +00:00
|
|
|
void MainWindow::handleF3()
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2011-06-29 19:12:46 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
if( view && view->isSearchOpened() )
|
|
|
|
view->on_searchNext_clicked();
|
2011-06-29 19:12:46 +00:00
|
|
|
else
|
|
|
|
editDictionaries();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::handleShiftF3()
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2011-06-29 19:12:46 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
if( view && view->isSearchOpened() )
|
|
|
|
view->on_searchPrevious_clicked();
|
2011-06-29 19:12:46 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 07:49:37 +00:00
|
|
|
void MainWindow::focusTranslateLine()
|
|
|
|
{
|
2009-05-13 13:47:51 +00:00
|
|
|
if ( ui.searchPane->isFloating() )
|
|
|
|
ui.searchPane->activateWindow();
|
|
|
|
|
2009-04-08 22:25:46 +00:00
|
|
|
ui.translateLine->setFocus();
|
2009-04-12 22:36:47 +00:00
|
|
|
ui.translateLine->selectAll();
|
2009-04-08 22:25:46 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void MainWindow::prefixMatchUpdated()
|
2009-01-29 19:16:25 +00:00
|
|
|
{
|
2009-03-26 19:00:08 +00:00
|
|
|
updateMatchResults( false );
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void MainWindow::prefixMatchFinished()
|
|
|
|
{
|
|
|
|
updateMatchResults( true );
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void MainWindow::updateMatchResults( bool finished )
|
|
|
|
{
|
2009-04-17 13:51:50 +00:00
|
|
|
WordFinder::SearchResults const & results = wordFinder.getResults();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
ui.wordList->setUpdatesEnabled( false );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
for( unsigned x = 0; x < results.size(); ++x )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-01-29 19:16:25 +00:00
|
|
|
QListWidgetItem * i = ui.wordList->item( x );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
if ( !i )
|
2009-04-09 15:27:34 +00:00
|
|
|
{
|
|
|
|
i = new QListWidgetItem( results[ x ].first, ui.wordList );
|
|
|
|
|
|
|
|
if ( results[ x ].second )
|
|
|
|
{
|
|
|
|
QFont f = i->font();
|
|
|
|
f.setItalic( true );
|
|
|
|
i->setFont( f );
|
|
|
|
}
|
|
|
|
ui.wordList->addItem( i );
|
|
|
|
}
|
2009-01-29 19:16:25 +00:00
|
|
|
else
|
2009-04-09 15:27:34 +00:00
|
|
|
{
|
|
|
|
if ( i->text() != results[ x ].first )
|
|
|
|
i->setText( results[ x ].first );
|
|
|
|
|
|
|
|
QFont f = i->font();
|
|
|
|
if ( f.italic() != results[ x ].second )
|
|
|
|
{
|
|
|
|
f.setItalic( results[ x ].second );
|
|
|
|
i->setFont( f );
|
|
|
|
}
|
|
|
|
}
|
2009-12-27 12:08:11 +00:00
|
|
|
if (i->text().at(0).direction() == QChar::DirR)
|
|
|
|
i->setTextAlignment(Qt::AlignRight);
|
|
|
|
if (i->text().at(0).direction() == QChar::DirL)
|
|
|
|
i->setTextAlignment(Qt::AlignLeft);
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
while ( ui.wordList->count() > (int) results.size() )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-01-29 19:16:25 +00:00
|
|
|
// Chop off any extra items that were there
|
|
|
|
QListWidgetItem * i = ui.wordList->takeItem( ui.wordList->count() - 1 );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
if ( i )
|
|
|
|
delete i;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
if ( ui.wordList->count() )
|
2009-02-06 17:04:11 +00:00
|
|
|
{
|
2009-01-29 19:16:25 +00:00
|
|
|
ui.wordList->scrollToItem( ui.wordList->item( 0 ), QAbstractItemView::PositionAtTop );
|
2009-02-06 17:04:11 +00:00
|
|
|
ui.wordList->setCurrentItem( 0, QItemSelectionModel::Clear );
|
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
ui.wordList->setUpdatesEnabled( true );
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
if ( finished )
|
|
|
|
{
|
|
|
|
ui.wordList->unsetCursor();
|
|
|
|
|
|
|
|
// Visually mark the input line to mark if there's no results
|
|
|
|
|
2010-06-22 12:43:11 +00:00
|
|
|
bool setMark = results.empty() && !wordFinder.wasSearchUncertain();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
if ( ui.translateLine->property( "noResults" ).toBool() != setMark )
|
|
|
|
{
|
|
|
|
ui.translateLine->setProperty( "noResults", setMark );
|
2009-05-16 18:04:21 +00:00
|
|
|
setStyleSheet( styleSheet() );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !wordFinder.getErrorString().isEmpty() )
|
2011-07-15 12:42:40 +00:00
|
|
|
mainStatusBar->showMessage( tr( "WARNING: %1" ).arg( wordFinder.getErrorString() ),
|
|
|
|
20000 , QPixmap( ":/icons/error.png" ) );
|
2009-03-26 19:00:08 +00:00
|
|
|
}
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void MainWindow::applyMutedDictionariesState()
|
|
|
|
{
|
|
|
|
// Redo the current search request
|
2012-02-16 14:56:25 +00:00
|
|
|
if( !showHistory )
|
|
|
|
translateInputChanged( ui.translateLine->text() );
|
2009-09-23 18:44:38 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
|
|
|
|
|
|
|
if ( view )
|
2011-06-11 04:50:19 +00:00
|
|
|
{
|
|
|
|
// Update active article view
|
2011-07-01 19:22:40 +00:00
|
|
|
view->updateMutedContents();
|
2011-06-11 04:50:19 +00:00
|
|
|
}
|
2009-09-23 18:44:38 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 08:26:49 +00:00
|
|
|
bool MainWindow::handleBackForwardMouseButtons ( QMouseEvent * event) {
|
|
|
|
if ( event->button() == Qt::XButton1 ) {
|
|
|
|
backClicked();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( event->button() == Qt::XButton2 ) {
|
|
|
|
forwardClicked();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
{
|
2011-06-07 08:26:49 +00:00
|
|
|
if ( ev->type() == QEvent::MouseButtonPress ) {
|
|
|
|
QMouseEvent * event = static_cast< QMouseEvent * >( ev );
|
|
|
|
return handleBackForwardMouseButtons( event );
|
|
|
|
}
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
if ( obj == ui.translateLine )
|
|
|
|
{
|
2011-06-09 07:29:21 +00:00
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2009-03-29 17:38:54 +00:00
|
|
|
{
|
|
|
|
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
if ( keyEvent->matches( QKeySequence::MoveToNextLine ) && ui.wordList->count() )
|
|
|
|
{
|
|
|
|
ui.wordList->setFocus( Qt::ShortcutFocusReason );
|
|
|
|
ui.wordList->setCurrentRow( 0, QItemSelectionModel::ClearAndSelect );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 10:31:03 +00:00
|
|
|
else
|
2011-06-09 07:29:21 +00:00
|
|
|
if ( ev->type() == QEvent::FocusIn ) {
|
2011-06-08 10:31:03 +00:00
|
|
|
QFocusEvent * focusEvent = static_cast< QFocusEvent * >( ev );
|
|
|
|
|
|
|
|
// select all on mouse click
|
|
|
|
if ( focusEvent->reason() == Qt::MouseFocusReason ) {
|
|
|
|
QTimer::singleShot(0, this, SLOT(focusTranslateLine()));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-29 17:38:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( obj == ui.wordList )
|
|
|
|
{
|
2011-06-09 07:29:21 +00:00
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2009-03-29 17:38:54 +00:00
|
|
|
{
|
|
|
|
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
|
|
|
|
|
|
|
if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) &&
|
|
|
|
!ui.wordList->currentRow() )
|
|
|
|
{
|
|
|
|
ui.wordList->setCurrentRow( 0, QItemSelectionModel::Clear );
|
|
|
|
ui.translateLine->setFocus( Qt::ShortcutFocusReason );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( keyEvent->matches( QKeySequence::InsertParagraphSeparator ) &&
|
|
|
|
ui.wordList->selectedItems().size() )
|
|
|
|
{
|
2009-05-13 13:47:51 +00:00
|
|
|
if ( ui.searchPane->isFloating() )
|
|
|
|
activateWindow();
|
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
getCurrentArticleView()->focus();
|
2009-03-29 17:38:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-29 23:18:26 +00:00
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
if( showHistory && keyEvent->matches( QKeySequence::Delete ) && ui.wordList->count() )
|
|
|
|
{
|
|
|
|
// Delete word from history
|
|
|
|
|
|
|
|
QList<QListWidgetItem *> selectedItems = ui.wordList->selectedItems();
|
|
|
|
|
|
|
|
if( selectedItems.size() )
|
|
|
|
{
|
|
|
|
int index = ui.wordList->row( selectedItems.at( 0 ) );
|
|
|
|
history.removeItem( index );
|
|
|
|
QListWidgetItem *item = ui.wordList->takeItem( index );
|
|
|
|
if( item )
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-13 17:15:34 +00:00
|
|
|
// Handle typing events used to initiate new lookups
|
2011-06-06 09:54:23 +00:00
|
|
|
// TODO: refactor to eliminate duplication (see below)
|
2009-12-13 17:15:34 +00:00
|
|
|
|
|
|
|
if ( keyEvent->modifiers() &
|
2011-06-05 11:49:50 +00:00
|
|
|
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
|
|
|
|
return false; // A non-typing modifier is pressed
|
|
|
|
|
|
|
|
if ( keyEvent->key() == Qt::Key_Space ||
|
|
|
|
keyEvent->key() == Qt::Key_Backspace ||
|
2011-07-04 08:35:56 +00:00
|
|
|
keyEvent->key() == Qt::Key_Tab ||
|
|
|
|
keyEvent->key() == Qt::Key_Backtab )
|
2011-06-05 11:49:50 +00:00
|
|
|
return false; // Those key have other uses than to start typing
|
|
|
|
// or don't make sense
|
|
|
|
|
|
|
|
QString text = keyEvent->text();
|
|
|
|
|
|
|
|
if ( text.size() )
|
|
|
|
{
|
|
|
|
typingEvent( text );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (obj == ui.dictsList) {
|
2011-06-09 07:29:21 +00:00
|
|
|
if ( ev->type() == QEvent::KeyPress )
|
2011-06-05 11:49:50 +00:00
|
|
|
{
|
|
|
|
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
|
|
|
|
|
|
|
// Handle typing events used to initiate new lookups
|
2011-06-06 09:54:23 +00:00
|
|
|
// TODO: refactor to eliminate duplication (see above)
|
2011-06-05 11:49:50 +00:00
|
|
|
|
|
|
|
if ( keyEvent->modifiers() &
|
|
|
|
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
|
2009-12-13 17:15:34 +00:00
|
|
|
return false; // A non-typing modifier is pressed
|
|
|
|
|
|
|
|
if ( keyEvent->key() == Qt::Key_Space ||
|
|
|
|
keyEvent->key() == Qt::Key_Backspace ||
|
2011-07-04 08:35:56 +00:00
|
|
|
keyEvent->key() == Qt::Key_Tab ||
|
|
|
|
keyEvent->key() == Qt::Key_Backtab )
|
2009-12-13 17:15:34 +00:00
|
|
|
return false; // Those key have other uses than to start typing
|
|
|
|
// or don't make sense
|
|
|
|
|
|
|
|
QString text = keyEvent->text();
|
|
|
|
|
|
|
|
if ( text.size() )
|
|
|
|
{
|
|
|
|
typingEvent( text );
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-29 17:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QMainWindow::eventFilter( obj, ev );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void MainWindow::wordListItemActivated( QListWidgetItem * item )
|
|
|
|
{
|
|
|
|
showTranslationFor( item->text() );
|
|
|
|
}
|
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void MainWindow::wordListSelectionChanged()
|
|
|
|
{
|
|
|
|
QList< QListWidgetItem * > selected = ui.wordList->selectedItems();
|
|
|
|
|
|
|
|
if ( selected.size() )
|
|
|
|
wordListItemActivated( selected.front() );
|
|
|
|
}
|
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
void MainWindow::dictsListItemActivated( QListWidgetItem * item )
|
|
|
|
{
|
2011-06-06 09:54:23 +00:00
|
|
|
QString id = item->data( Qt::UserRole ).toString();
|
2011-07-01 19:22:40 +00:00
|
|
|
getCurrentArticleView()->jumpToDictionary( id );
|
2011-06-05 11:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::dictsListSelectionChanged()
|
|
|
|
{
|
|
|
|
QList< QListWidgetItem * > selected = ui.dictsList->selectedItems();
|
|
|
|
|
|
|
|
if ( selected.size() )
|
|
|
|
dictsListItemActivated( selected.front() );
|
|
|
|
}
|
|
|
|
|
2009-02-08 15:49:17 +00:00
|
|
|
void MainWindow::openLinkInNewTab( QUrl const & url,
|
2009-05-11 19:14:28 +00:00
|
|
|
QUrl const & referrer,
|
2009-05-29 19:48:50 +00:00
|
|
|
QString const & fromArticle,
|
|
|
|
ArticleView::Contexts const & contexts )
|
2009-02-08 15:49:17 +00:00
|
|
|
{
|
2009-05-11 19:14:28 +00:00
|
|
|
createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->
|
2009-05-29 19:48:50 +00:00
|
|
|
openLink( url, referrer, fromArticle, contexts );
|
2009-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showDefinitionInNewTab( QString const & word,
|
2009-05-11 19:14:28 +00:00
|
|
|
unsigned group,
|
2009-05-29 19:48:50 +00:00
|
|
|
QString const & fromArticle,
|
|
|
|
ArticleView::Contexts const & contexts )
|
2009-02-08 15:49:17 +00:00
|
|
|
{
|
2009-05-11 19:14:28 +00:00
|
|
|
createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->
|
2009-05-29 19:48:50 +00:00
|
|
|
showDefinition( word, group, fromArticle, contexts );
|
2009-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:27:08 +00:00
|
|
|
void MainWindow::activeArticleChanged( QString const & id )
|
|
|
|
{
|
|
|
|
// select the row with the corresponding id
|
|
|
|
for (int i = 0; i < ui.dictsList->count(); ++i) {
|
|
|
|
QListWidgetItem * w = ui.dictsList->item( i );
|
|
|
|
QString dictId = w->data( Qt::UserRole ).toString();
|
|
|
|
|
|
|
|
if ( dictId == id )
|
|
|
|
{
|
|
|
|
// update the current row, but only if necessary
|
|
|
|
if ( i != ui.dictsList->currentRow() )
|
|
|
|
{
|
|
|
|
ui.dictsList->setCurrentRow(i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-12 13:25:18 +00:00
|
|
|
void MainWindow::typingEvent( QString const & t )
|
|
|
|
{
|
2009-05-12 15:54:37 +00:00
|
|
|
if ( t == "\n" || t == "\r" )
|
2012-02-16 14:56:25 +00:00
|
|
|
{
|
|
|
|
if( ui.translateLine->isEnabled() )
|
|
|
|
focusTranslateLine();
|
|
|
|
}
|
2009-05-12 15:54:37 +00:00
|
|
|
else
|
|
|
|
{
|
2011-06-05 11:49:50 +00:00
|
|
|
if ( ui.searchPane->isFloating() || ui.dictsPane->isFloating() )
|
2009-05-13 13:47:51 +00:00
|
|
|
ui.searchPane->activateWindow();
|
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
if( ui.translateLine->isEnabled() )
|
|
|
|
{
|
|
|
|
ui.translateLine->setText( t );
|
|
|
|
ui.translateLine->setFocus();
|
|
|
|
ui.translateLine->setCursorPosition( t.size() );
|
|
|
|
}
|
2009-05-12 15:54:37 +00:00
|
|
|
}
|
2009-05-12 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void MainWindow::mutedDictionariesChanged()
|
|
|
|
{
|
|
|
|
if ( dictionaryBar.toggleViewAction()->isChecked() )
|
|
|
|
applyMutedDictionariesState();
|
|
|
|
}
|
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
void MainWindow::showTranslationFor( QString const & inWord,
|
2009-10-21 20:06:17 +00:00
|
|
|
unsigned inGroup )
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
navPronounce->setEnabled( false );
|
|
|
|
|
2009-10-21 20:06:17 +00:00
|
|
|
unsigned group = inGroup ? inGroup :
|
2009-10-21 19:37:07 +00:00
|
|
|
( groupInstances.empty() ? 0 :
|
2009-10-21 20:06:17 +00:00
|
|
|
groupInstances[ groupList.currentIndex() ].id );
|
2009-10-21 19:37:07 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->showDefinition( inWord, group );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
updatePronounceAvailability();
|
2011-06-05 11:49:50 +00:00
|
|
|
updateFoundInDictsList();
|
2009-04-10 21:07:03 +00:00
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
// Add to history
|
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
if( !showHistory )
|
|
|
|
{
|
|
|
|
history.addItem( History::Item( group, inWord.trimmed() ) );
|
|
|
|
// history.save();
|
|
|
|
}
|
2009-10-21 19:37:07 +00:00
|
|
|
|
2011-06-07 11:27:19 +00:00
|
|
|
updateBackForwardButtons();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
#if 0
|
|
|
|
QUrl req;
|
|
|
|
|
|
|
|
req.setScheme( "gdlookup" );
|
|
|
|
req.setHost( "localhost" );
|
|
|
|
req.addQueryItem( "word", inWord );
|
|
|
|
req.addQueryItem( "group",
|
|
|
|
cfg.groups.empty() ? "" :
|
2009-04-20 14:13:39 +00:00
|
|
|
groupInstances[ groupList.currentIndex() ].name );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
ui.definition->load( req );
|
|
|
|
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
wstring word = inWord.trimmed().toStdWString();
|
|
|
|
|
|
|
|
// Where to look?
|
|
|
|
|
|
|
|
vector< sptr< Dictionary::Class > > const & activeDicts = getActiveDicts();
|
|
|
|
|
|
|
|
// Accumulate main forms
|
|
|
|
|
|
|
|
vector< wstring > alts;
|
|
|
|
|
|
|
|
{
|
|
|
|
set< wstring > altsSet;
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
|
|
|
{
|
|
|
|
vector< wstring > found = activeDicts[ x ]->findHeadwordsForSynonym( word );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
altsSet.insert( found.begin(), found.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
alts.insert( alts.begin(), altsSet.begin(), altsSet.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned x = 0; x < alts.size(); ++x )
|
|
|
|
{
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "Alt: %ls\n", alts[ x ].c_str() );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string result =
|
|
|
|
"<html><head>"
|
|
|
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
|
|
|
|
|
|
|
|
QFile cssFile( Config::getUserCssFileName() );
|
|
|
|
|
|
|
|
if ( cssFile.open( QFile::ReadOnly ) )
|
|
|
|
{
|
|
|
|
result += "<style type=\"text/css\">\n";
|
|
|
|
result += cssFile.readAll().data();
|
|
|
|
result += "</style>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
result += "</head><body>";
|
|
|
|
|
|
|
|
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string body = activeDicts[ x ]->getArticle( word, alts );
|
|
|
|
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "From %s: %s\n", activeDicts[ x ]->getName().c_str(), body.c_str() );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
result += "<div class=\"gddictname\">From " + activeDicts[ x ]->getName() + "</div>" + body;
|
|
|
|
}
|
|
|
|
catch( Dictionary::exNoSuchWord & )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result += "</body></html>";
|
|
|
|
|
|
|
|
ArticleMaker am( dictionaries, groupInstances );
|
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
string result = am.makeDefinitionFor( inWord, "En" );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
ui.definition->setContent( result.c_str(), QString() );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//ui.tabWidget->setTabText( ui.tabWidget->indexOf(ui.tab), inWord.trimmed() );
|
|
|
|
}
|
2009-02-05 20:55:00 +00:00
|
|
|
|
2009-04-20 12:25:26 +00:00
|
|
|
void MainWindow::toggleMainWindow( bool onlyShow )
|
|
|
|
{
|
2010-04-27 07:49:37 +00:00
|
|
|
bool shown = false;
|
|
|
|
|
2009-04-20 12:25:26 +00:00
|
|
|
if ( !isVisible() )
|
2009-05-07 16:22:17 +00:00
|
|
|
{
|
2009-04-20 12:25:26 +00:00
|
|
|
show();
|
2009-05-07 16:22:17 +00:00
|
|
|
activateWindow();
|
|
|
|
raise();
|
2010-04-27 07:49:37 +00:00
|
|
|
shown = true;
|
2009-05-07 16:22:17 +00:00
|
|
|
}
|
2009-04-20 12:25:26 +00:00
|
|
|
else
|
|
|
|
if ( isMinimized() )
|
|
|
|
{
|
|
|
|
showNormal();
|
|
|
|
activateWindow();
|
|
|
|
raise();
|
2010-04-27 07:49:37 +00:00
|
|
|
shown = true;
|
2009-04-20 12:25:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( !isActiveWindow() )
|
|
|
|
{
|
|
|
|
activateWindow();
|
|
|
|
raise();
|
2010-04-27 07:49:37 +00:00
|
|
|
shown = true;
|
2009-04-20 12:25:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( !onlyShow )
|
2011-06-24 19:03:03 +00:00
|
|
|
{
|
|
|
|
if (cfg.preferences.enableTrayIcon)
|
|
|
|
hide();
|
|
|
|
else
|
|
|
|
showMinimized();
|
|
|
|
}
|
2010-04-27 07:49:37 +00:00
|
|
|
|
|
|
|
if ( shown )
|
|
|
|
focusTranslateLine();
|
2009-04-20 12:25:26 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
void MainWindow::installHotKeys()
|
|
|
|
{
|
|
|
|
hotkeyWrapper.reset(); // Remove the old one
|
|
|
|
|
|
|
|
if ( cfg.preferences.enableMainWindowHotkey ||
|
|
|
|
cfg.preferences.enableClipboardHotkey )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
hotkeyWrapper = new HotkeyWrapper( this );
|
|
|
|
}
|
|
|
|
catch( HotkeyWrapper::exInit & )
|
|
|
|
{
|
|
|
|
QMessageBox::critical( this, tr( "GoldenDict" ),
|
|
|
|
tr( "Failed to initialize hotkeys monitoring mechanism.<br>"
|
|
|
|
"Make sure your XServer has RECORD extension turned on." ) );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-19 14:17:45 +00:00
|
|
|
if ( cfg.preferences.enableMainWindowHotkey )
|
|
|
|
hotkeyWrapper->setGlobalKey( cfg.preferences.mainWindowHotkey.key1,
|
|
|
|
cfg.preferences.mainWindowHotkey.key2,
|
|
|
|
cfg.preferences.mainWindowHotkey.modifiers,
|
|
|
|
0 );
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
if ( cfg.preferences.enableClipboardHotkey && scanPopup.get() )
|
|
|
|
{
|
|
|
|
hotkeyWrapper->setGlobalKey( cfg.preferences.clipboardHotkey.key1,
|
|
|
|
cfg.preferences.clipboardHotkey.key2,
|
|
|
|
cfg.preferences.clipboardHotkey.modifiers,
|
|
|
|
1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
connect( hotkeyWrapper.get(), SIGNAL( hotkeyActivated( int ) ),
|
|
|
|
this, SLOT( hotKeyActivated( int ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::hotKeyActivated( int hk )
|
|
|
|
{
|
|
|
|
if ( !hk )
|
2011-06-24 19:03:03 +00:00
|
|
|
toggleMainWindow();
|
2009-04-21 18:27:26 +00:00
|
|
|
else
|
|
|
|
if ( scanPopup.get() )
|
|
|
|
scanPopup->translateWordFromClipboard();
|
|
|
|
}
|
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
void MainWindow::prepareNewReleaseChecks()
|
|
|
|
{
|
|
|
|
if ( cfg.preferences.checkForNewReleases )
|
|
|
|
{
|
|
|
|
QDateTime now = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
if ( !cfg.timeForNewReleaseCheck.isValid() ||
|
|
|
|
now.daysTo( cfg.timeForNewReleaseCheck ) > 2 )
|
|
|
|
{
|
|
|
|
// The date is invalid, or the check is set to happen more than 2 days
|
|
|
|
// in the future -- fix that.
|
|
|
|
cfg.timeForNewReleaseCheck = now.addDays( 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int secsToCheck = now.secsTo( cfg.timeForNewReleaseCheck );
|
|
|
|
|
|
|
|
if ( secsToCheck < 1 )
|
|
|
|
secsToCheck = 1;
|
|
|
|
|
|
|
|
newReleaseCheckTimer.setSingleShot( true );
|
|
|
|
newReleaseCheckTimer.start( secsToCheck * 1000 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newReleaseCheckTimer.stop(); // In case it was started before
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::checkForNewRelease()
|
|
|
|
{
|
|
|
|
latestReleaseReply.reset();
|
|
|
|
|
|
|
|
QNetworkRequest req(
|
2010-11-06 19:40:07 +00:00
|
|
|
QUrl( "http://goldendict.org/latest_release.php?current="
|
2009-04-20 20:59:50 +00:00
|
|
|
PROGRAM_VERSION "&platform="
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
"x11"
|
|
|
|
#endif
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
"mac"
|
|
|
|
#endif
|
|
|
|
#ifdef Q_WS_QWS
|
|
|
|
"qws"
|
|
|
|
#endif
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
"win"
|
|
|
|
#endif
|
|
|
|
) );
|
2009-04-20 19:54:34 +00:00
|
|
|
|
|
|
|
latestReleaseReply = articleNetMgr.get( req );
|
|
|
|
|
|
|
|
connect( latestReleaseReply.get(), SIGNAL( finished() ),
|
|
|
|
this, SLOT( latestReleaseReplyReady() ), Qt::QueuedConnection );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::latestReleaseReplyReady()
|
|
|
|
{
|
|
|
|
if ( !latestReleaseReply.get() )
|
|
|
|
return; // Some stray signal
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
QString latestVersion, downloadUrl;
|
|
|
|
|
|
|
|
// See if we succeeded
|
|
|
|
|
|
|
|
if ( latestReleaseReply->error() == QNetworkReply::NoError )
|
|
|
|
{
|
|
|
|
QString latestReleaseInfo = QString::fromUtf8( latestReleaseReply->readLine() ).trimmed();
|
|
|
|
QStringList parts = latestReleaseInfo.split( ' ' );
|
|
|
|
if ( parts.size() == 2 )
|
|
|
|
{
|
|
|
|
latestVersion = parts[ 0 ];
|
|
|
|
downloadUrl = parts[ 1 ];
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
latestReleaseReply.reset();
|
|
|
|
|
|
|
|
if ( !success )
|
|
|
|
{
|
|
|
|
// Failed -- reschedule to check in two hours
|
|
|
|
newReleaseCheckTimer.start( 2 * 60 * 60 * 1000 );
|
|
|
|
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "Failed to check program version, retry in two hours\n" );
|
2009-04-20 19:54:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Success -- reschedule for a normal check and save config
|
|
|
|
cfg.timeForNewReleaseCheck = QDateTime();
|
|
|
|
|
|
|
|
prepareNewReleaseChecks();
|
|
|
|
|
|
|
|
Config::save( cfg );
|
|
|
|
|
2011-06-19 18:50:11 +00:00
|
|
|
DPRINTF( "Program version's check successful, current version is %ls\n",
|
2009-04-20 19:54:34 +00:00
|
|
|
latestVersion.toStdWString().c_str() );
|
|
|
|
}
|
|
|
|
|
2009-05-14 17:59:49 +00:00
|
|
|
if ( success && latestVersion > PROGRAM_VERSION && latestVersion != cfg.skippedRelease )
|
2009-04-20 19:54:34 +00:00
|
|
|
{
|
|
|
|
QMessageBox msg( QMessageBox::Information,
|
|
|
|
tr( "New Release Available" ),
|
|
|
|
tr( "Version <b>%1</b> of GoldenDict is now available for download.<br>"
|
|
|
|
"Click <b>Download</b> to get to the download page." ).arg( latestVersion ),
|
|
|
|
QMessageBox::NoButton,
|
|
|
|
this );
|
|
|
|
|
|
|
|
QPushButton * dload = msg.addButton( tr( "Download" ), QMessageBox::AcceptRole );
|
2009-05-14 17:59:49 +00:00
|
|
|
QPushButton * skip = msg.addButton( tr( "Skip This Release" ), QMessageBox::DestructiveRole );
|
2009-04-20 19:54:34 +00:00
|
|
|
msg.addButton( QMessageBox::Cancel );
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
|
|
|
|
if ( msg.clickedButton() == dload )
|
|
|
|
QDesktopServices::openUrl( QUrl( downloadUrl ) );
|
2009-05-14 17:59:49 +00:00
|
|
|
else
|
|
|
|
if ( msg.clickedButton() == skip )
|
|
|
|
{
|
|
|
|
cfg.skippedRelease = latestVersion;
|
|
|
|
Config::save( cfg );
|
|
|
|
}
|
2009-04-20 19:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r )
|
|
|
|
{
|
2010-09-16 18:52:40 +00:00
|
|
|
switch(r) {
|
|
|
|
case QSystemTrayIcon::Trigger:
|
|
|
|
// Left click toggles the visibility of main window
|
|
|
|
toggleMainWindow();
|
|
|
|
break;
|
2009-07-31 11:40:54 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
case QSystemTrayIcon::MiddleClick:
|
|
|
|
// Middle mouse click on Tray translates selection
|
|
|
|
// it is functional like as stardict
|
|
|
|
if ( scanPopup.get() ) {
|
|
|
|
scanPopup->translateWordFromSelection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-07-31 11:40:54 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
}
|
2009-02-08 20:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::scanEnableToggled( bool on )
|
|
|
|
{
|
2009-04-21 18:27:26 +00:00
|
|
|
if ( !cfg.preferences.enableScanPopup )
|
|
|
|
return;
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
if ( scanPopup )
|
|
|
|
{
|
|
|
|
if ( on )
|
|
|
|
scanPopup->enableScanning();
|
|
|
|
else
|
|
|
|
scanPopup->disableScanning();
|
|
|
|
}
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
updateTrayIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showMainWindow()
|
2009-02-05 20:55:00 +00:00
|
|
|
{
|
2009-04-20 12:25:26 +00:00
|
|
|
toggleMainWindow( true );
|
2009-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void MainWindow::visitHomepage()
|
|
|
|
{
|
2010-11-06 19:40:07 +00:00
|
|
|
QDesktopServices::openUrl( QUrl( "http://goldendict.org/" ) );
|
2009-02-08 14:02:27 +00:00
|
|
|
}
|
|
|
|
|
2011-07-10 07:36:43 +00:00
|
|
|
void MainWindow::openConfigFolder()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl( QUrl::fromLocalFile( Config::getConfigDir() ) );
|
|
|
|
}
|
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void MainWindow::visitForum()
|
|
|
|
{
|
2010-11-06 19:40:07 +00:00
|
|
|
QDesktopServices::openUrl( QUrl( "http://goldendict.org/forum/" ) );
|
2009-02-08 14:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showAbout()
|
|
|
|
{
|
2010-11-14 16:28:50 +00:00
|
|
|
About about( this );
|
2009-04-12 22:02:15 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
about.show();
|
|
|
|
about.exec();
|
|
|
|
}
|
|
|
|
|
2009-10-12 12:41:20 +00:00
|
|
|
void MainWindow::showDictBarNamesTriggered()
|
|
|
|
{
|
|
|
|
bool show = showDictBarNamesAction.isChecked();
|
|
|
|
|
|
|
|
dictionaryBar.setToolButtonStyle( show ? Qt::ToolButtonTextBesideIcon :
|
|
|
|
Qt::ToolButtonIconOnly );
|
|
|
|
cfg.showingDictBarNames = show;
|
|
|
|
}
|
|
|
|
|
2011-05-22 02:42:05 +00:00
|
|
|
void MainWindow::useSmallIconsInToolbarsTriggered()
|
|
|
|
{
|
|
|
|
bool useSmallIcons = useSmallIconsInToolbarsAction.isChecked();
|
|
|
|
|
|
|
|
int extent = useSmallIcons ? QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) :
|
|
|
|
QApplication::style()->pixelMetric(QStyle::PM_ToolBarIconSize);
|
|
|
|
|
|
|
|
navToolbar->setIconSize( QSize( extent, extent ) );
|
|
|
|
|
|
|
|
updateDictionaryBar();
|
|
|
|
|
|
|
|
cfg.usingSmallIconsInToolbars = useSmallIcons;
|
|
|
|
}
|
|
|
|
|
2011-06-26 11:53:28 +00:00
|
|
|
void MainWindow::toggleMenuBarTriggered(bool announce)
|
|
|
|
{
|
|
|
|
cfg.preferences.hideMenubar = menuBar()->isVisible();
|
|
|
|
|
2011-06-27 18:54:15 +00:00
|
|
|
if ( announce )
|
2011-06-26 11:53:28 +00:00
|
|
|
{
|
2011-06-27 18:54:15 +00:00
|
|
|
if ( cfg.preferences.hideMenubar )
|
|
|
|
{
|
|
|
|
mainStatusBar->showMessage(
|
2011-07-09 11:55:44 +00:00
|
|
|
tr( "You have chosen to hide a menubar. Use %1 to show it back." )
|
|
|
|
.arg( QString( "<b>%1</b>" ) ).arg( tr( "Ctrl+M" ) ),
|
|
|
|
10000,
|
|
|
|
QPixmap( ":/icons/warning.png" ) );
|
2011-06-27 18:54:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mainStatusBar->clearMessage();
|
|
|
|
}
|
2011-06-26 11:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain from the menubar all the actions with shortcuts
|
|
|
|
// and either add them to the main window or remove them,
|
|
|
|
// depending on the menubar state.
|
|
|
|
|
|
|
|
QList<QMenu *> allMenus = menuBar()->findChildren<QMenu *>();
|
|
|
|
QListIterator<QMenu *> menuIter( allMenus );
|
|
|
|
while( menuIter.hasNext() )
|
|
|
|
{
|
|
|
|
QMenu * menu = menuIter.next();
|
|
|
|
QList<QAction *> allMenuActions = menu->actions();
|
|
|
|
QListIterator<QAction *> actionsIter( allMenuActions );
|
|
|
|
while( actionsIter.hasNext() )
|
|
|
|
{
|
|
|
|
QAction * action = actionsIter.next();
|
|
|
|
if ( !action->shortcut().isEmpty() )
|
|
|
|
{
|
|
|
|
if ( cfg.preferences.hideMenubar )
|
|
|
|
{
|
|
|
|
// add all menubar actions to the main window,
|
|
|
|
// before we hide the menubar
|
|
|
|
addAction( action );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// remove all menubar actions from the main window
|
|
|
|
removeAction( action );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menuBar()->setVisible( !cfg.preferences.hideMenubar );
|
|
|
|
}
|
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
/*
|
2009-10-21 19:37:07 +00:00
|
|
|
void MainWindow::historyChanged()
|
|
|
|
{
|
|
|
|
// Rebuild history menu
|
|
|
|
|
|
|
|
ui.menuHistory->clear();
|
|
|
|
|
|
|
|
QList< History::Item > const & items = history.getItems();
|
|
|
|
|
|
|
|
for( int x = 0; x < items.size(); ++x )
|
|
|
|
{
|
|
|
|
History::Item const * i = &items[ x ];
|
|
|
|
|
|
|
|
Instances::Group const * group = groupInstances.findGroup( i->groupId );
|
|
|
|
|
|
|
|
QIcon icon = group ? group->makeIcon() : QIcon();
|
|
|
|
|
|
|
|
QAction * action = ui.menuHistory->addAction( icon, i->word );
|
2011-06-12 16:37:45 +00:00
|
|
|
action->setIconVisibleInMenu( true );
|
2009-10-21 19:37:07 +00:00
|
|
|
|
|
|
|
action->setData( x );
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.menuHistory->addSeparator();
|
|
|
|
|
|
|
|
ui.menuHistory->addAction( ui.clearHistory );
|
|
|
|
|
|
|
|
ui.clearHistory->setEnabled( items.size() );
|
|
|
|
}
|
2012-02-16 14:56:25 +00:00
|
|
|
*/
|
2009-10-21 19:37:07 +00:00
|
|
|
|
2012-02-16 14:56:25 +00:00
|
|
|
/*
|
2009-11-01 16:20:26 +00:00
|
|
|
void MainWindow::menuHistoryTriggered( QAction * action )
|
2009-10-21 19:37:07 +00:00
|
|
|
{
|
|
|
|
if ( action->data().type() != QVariant::Int )
|
|
|
|
return; // Not the item we added
|
|
|
|
|
|
|
|
int index = action->data().toInt();
|
|
|
|
|
|
|
|
QList< History::Item > const & items = history.getItems();
|
|
|
|
|
|
|
|
if ( index < 0 || index >= items.size() )
|
|
|
|
return; // Something's not right
|
|
|
|
|
|
|
|
History::Item const & item = items[ index ];
|
|
|
|
|
|
|
|
showTranslationFor( item.word, item.groupId );
|
|
|
|
}
|
2012-02-16 14:56:25 +00:00
|
|
|
*/
|
2009-10-21 19:37:07 +00:00
|
|
|
|
|
|
|
void MainWindow::on_clearHistory_activated()
|
|
|
|
{
|
|
|
|
history.clear();
|
2011-03-30 04:47:55 +00:00
|
|
|
history.save();
|
2012-02-16 14:56:25 +00:00
|
|
|
|
|
|
|
if( showHistory )
|
|
|
|
ui.wordList->clear();
|
2009-10-21 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 07:34:28 +00:00
|
|
|
void MainWindow::on_newTab_activated()
|
|
|
|
{
|
|
|
|
addNewTab();
|
|
|
|
}
|
|
|
|
|
2009-04-18 18:47:01 +00:00
|
|
|
void MainWindow::setAutostart(bool autostart)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
|
|
QSettings::NativeFormat);
|
2009-04-19 21:32:18 +00:00
|
|
|
if (autostart) {
|
|
|
|
QString app_fname = QString("\"%1\"").arg( QCoreApplication::applicationFilePath() );
|
|
|
|
app_fname.replace("/", "\\");
|
|
|
|
reg.setValue(QCoreApplication::applicationName(), app_fname);
|
|
|
|
}
|
|
|
|
else {
|
2009-04-18 18:47:01 +00:00
|
|
|
reg.remove(QCoreApplication::applicationName());
|
2009-04-19 21:32:18 +00:00
|
|
|
}
|
2009-04-18 18:47:01 +00:00
|
|
|
reg.sync();
|
|
|
|
#else
|
|
|
|
// this is for KDE
|
|
|
|
QString app_fname = QFileInfo(QCoreApplication::applicationFilePath()).baseName();
|
|
|
|
QString lnk(QDir::homePath()+"/.kde/Autostart/"+app_fname);
|
|
|
|
if (autostart) {
|
|
|
|
QFile f(QCoreApplication::applicationFilePath());
|
|
|
|
f.link(lnk);
|
|
|
|
} else {
|
|
|
|
QFile::remove(lnk);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionCloseToTray_activated()
|
|
|
|
{
|
2009-04-20 12:25:26 +00:00
|
|
|
toggleMainWindow( !cfg.preferences.enableTrayIcon );
|
2009-04-18 18:47:01 +00:00
|
|
|
}
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-05-01 12:20:33 +00:00
|
|
|
void MainWindow::on_pageSetup_activated()
|
|
|
|
{
|
2009-11-11 09:40:32 +00:00
|
|
|
if ( getPrinter().isValid() )
|
2009-05-24 18:51:45 +00:00
|
|
|
{
|
2009-11-11 09:40:32 +00:00
|
|
|
QPageSetupDialog dialog( &getPrinter(), this );
|
2009-05-01 12:20:33 +00:00
|
|
|
|
2009-05-24 18:51:45 +00:00
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
QMessageBox::critical( this, tr( "Page Setup" ),
|
|
|
|
tr( "No printer is available. Please install one first." ) );
|
2009-05-01 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_printPreview_activated()
|
|
|
|
{
|
2009-11-11 09:40:32 +00:00
|
|
|
QPrintPreviewDialog dialog( &getPrinter(), this );
|
2009-05-01 12:20:33 +00:00
|
|
|
|
|
|
|
connect( &dialog, SIGNAL( paintRequested( QPrinter * ) ),
|
|
|
|
this, SLOT( printPreviewPaintRequested( QPrinter * ) ) );
|
|
|
|
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_print_activated()
|
|
|
|
{
|
2009-11-11 09:40:32 +00:00
|
|
|
QPrintDialog dialog( &getPrinter(), this );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-05-01 12:20:33 +00:00
|
|
|
dialog.setWindowTitle( tr( "Print Article") );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-05-01 12:20:33 +00:00
|
|
|
if ( dialog.exec() != QDialog::Accepted )
|
|
|
|
return;
|
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-05-01 12:20:33 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->print( &getPrinter() );
|
2009-05-01 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::printPreviewPaintRequested( QPrinter * printer )
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-05-01 12:20:33 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
view->print( printer );
|
2009-05-01 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 11:17:29 +00:00
|
|
|
void MainWindow::on_saveArticle_activated()
|
|
|
|
{
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView *view = getCurrentArticleView();
|
2009-05-01 11:17:29 +00:00
|
|
|
|
|
|
|
QFileDialog fileDialog( this, tr( "Save Article As" ), QString(), tr( "Html files (*.html *.htm)" ) );
|
|
|
|
|
|
|
|
fileDialog.setAcceptMode( QFileDialog::AcceptSave );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-05-01 11:17:29 +00:00
|
|
|
fileDialog.setDefaultSuffix( "html" );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
fileDialog.selectFile( view->getTitle() + ".html" );
|
2009-05-01 11:17:29 +00:00
|
|
|
|
|
|
|
if ( fileDialog.exec() && fileDialog.selectedFiles().size() == 1 )
|
|
|
|
{
|
|
|
|
QString fileName = fileDialog.selectedFiles().front();
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-05-01 11:17:29 +00:00
|
|
|
QFile file( fileName );
|
|
|
|
|
|
|
|
if ( !file.open( QIODevice::WriteOnly ) )
|
|
|
|
QMessageBox::critical( this, tr( "Error" ),
|
|
|
|
tr( "Can't save article: %1" ).arg( file.errorString() ) );
|
|
|
|
else
|
2011-07-01 19:22:40 +00:00
|
|
|
file.write( view->toHtml().toUtf8() );
|
2009-05-01 11:17:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-08 10:47:34 +00:00
|
|
|
void MainWindow::on_rescanFiles_activated()
|
|
|
|
{
|
|
|
|
hotkeyWrapper.reset(); // No hotkeys while we're editing dictionaries
|
|
|
|
scanPopup.reset(); // No scan popup either. No one should use dictionaries.
|
|
|
|
|
2009-05-15 12:15:08 +00:00
|
|
|
groupInstances.clear(); // Release all the dictionaries they hold
|
|
|
|
|
2009-05-08 10:47:34 +00:00
|
|
|
loadDictionaries( this, true, cfg, dictionaries, dictNetMgr );
|
2010-09-16 18:52:40 +00:00
|
|
|
|
2009-05-08 10:47:34 +00:00
|
|
|
updateGroupList();
|
|
|
|
|
|
|
|
makeScanPopup();
|
|
|
|
installHotKeys();
|
|
|
|
}
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
void MainWindow::zoomin()
|
|
|
|
{
|
|
|
|
cfg.preferences.zoomFactor += 0.1;
|
|
|
|
applyZoomFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::zoomout()
|
|
|
|
{
|
|
|
|
cfg.preferences.zoomFactor -= 0.1;
|
|
|
|
applyZoomFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::unzoom()
|
|
|
|
{
|
|
|
|
cfg.preferences.zoomFactor = 1;
|
|
|
|
applyZoomFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::applyZoomFactor()
|
|
|
|
{
|
2009-04-30 22:09:04 +00:00
|
|
|
if ( cfg.preferences.zoomFactor >= 3 )
|
|
|
|
cfg.preferences.zoomFactor = 3;
|
2009-05-02 17:12:52 +00:00
|
|
|
else if ( cfg.preferences.zoomFactor <= 0.7 )
|
|
|
|
cfg.preferences.zoomFactor = 0.7;
|
2009-04-30 22:09:04 +00:00
|
|
|
|
|
|
|
zoomIn->setEnabled( cfg.preferences.zoomFactor < 3 );
|
2009-05-02 17:12:52 +00:00
|
|
|
zoomOut->setEnabled( cfg.preferences.zoomFactor > 0.7 );
|
2009-04-30 22:09:04 +00:00
|
|
|
zoomBase->setEnabled( cfg.preferences.zoomFactor != 1.0 );
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
for ( int i = 0; i < ui.tabWidget->count(); i++ )
|
|
|
|
{
|
|
|
|
ArticleView & view =
|
|
|
|
dynamic_cast< ArticleView & >( *( ui.tabWidget->widget(i) ) );
|
|
|
|
view.setZoomFactor( cfg.preferences.zoomFactor );
|
|
|
|
}
|
2009-04-30 20:20:05 +00:00
|
|
|
|
|
|
|
if ( scanPopup.get() )
|
|
|
|
scanPopup->applyZoomFactor();
|
2009-04-30 19:57:25 +00:00
|
|
|
}
|
2010-07-02 11:19:02 +00:00
|
|
|
|
|
|
|
void MainWindow::doWordsZoomIn()
|
|
|
|
{
|
|
|
|
++cfg.preferences.wordsZoomLevel;
|
|
|
|
|
|
|
|
applyWordsZoomLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::doWordsZoomOut()
|
|
|
|
{
|
|
|
|
--cfg.preferences.wordsZoomLevel;
|
|
|
|
|
|
|
|
applyWordsZoomLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::doWordsZoomBase()
|
|
|
|
{
|
|
|
|
cfg.preferences.wordsZoomLevel = 0;
|
|
|
|
|
|
|
|
applyWordsZoomLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::applyWordsZoomLevel()
|
|
|
|
{
|
|
|
|
QFont font( wordListDefaultFont );
|
|
|
|
|
|
|
|
int ps = font.pointSize();
|
|
|
|
|
|
|
|
if ( cfg.preferences.wordsZoomLevel != 0 )
|
|
|
|
{
|
|
|
|
ps += cfg.preferences.wordsZoomLevel;
|
|
|
|
|
|
|
|
if ( ps < 1 )
|
|
|
|
ps = 1;
|
|
|
|
|
|
|
|
font.setPointSize( ps );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ui.wordList->font().pointSize() != ps )
|
|
|
|
ui.wordList->setFont( font );
|
|
|
|
|
|
|
|
font = translateLineDefaultFont;
|
|
|
|
|
|
|
|
ps = font.pointSize();
|
|
|
|
|
|
|
|
if ( cfg.preferences.wordsZoomLevel != 0 )
|
|
|
|
{
|
|
|
|
ps += cfg.preferences.wordsZoomLevel;
|
|
|
|
|
|
|
|
if ( ps < 1 )
|
|
|
|
ps = 1;
|
|
|
|
|
|
|
|
font.setPointSize( ps );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ui.translateLine->font().pointSize() != ps )
|
|
|
|
ui.translateLine->setFont( font );
|
|
|
|
|
|
|
|
wordsZoomBase->setEnabled( cfg.preferences.wordsZoomLevel != 0 );
|
|
|
|
}
|
2010-11-20 13:43:55 +00:00
|
|
|
|
|
|
|
void MainWindow::messageFromAnotherInstanceReceived( QString const & message )
|
|
|
|
{
|
|
|
|
if ( message == "bringToFront" )
|
2011-11-16 13:02:56 +00:00
|
|
|
{
|
2010-11-20 13:43:55 +00:00
|
|
|
toggleMainWindow( true );
|
2011-11-16 13:02:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( message.left( 15 ) == "translateWord: " )
|
|
|
|
{
|
|
|
|
if( scanPopup.get() )
|
|
|
|
scanPopup->translateWord( message.mid( 15 ) );
|
|
|
|
else
|
|
|
|
wordReceived( message.mid( 15 ) );
|
|
|
|
}
|
2010-11-20 13:43:55 +00:00
|
|
|
else
|
|
|
|
qWarning() << "Unknown message received from another instance: " << message;
|
|
|
|
}
|
2011-07-01 19:22:40 +00:00
|
|
|
|
|
|
|
ArticleView * MainWindow::getCurrentArticleView()
|
|
|
|
{
|
|
|
|
if ( QWidget * cw = ui.tabWidget->currentWidget() )
|
|
|
|
{
|
|
|
|
return &( dynamic_cast< ArticleView & >( *( cw ) ) );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-16 12:52:25 +00:00
|
|
|
|
|
|
|
void MainWindow::wordReceived( const QString & word)
|
|
|
|
{
|
2012-02-16 14:56:25 +00:00
|
|
|
if( showHistory )
|
|
|
|
return;
|
|
|
|
|
2011-11-16 12:52:25 +00:00
|
|
|
toggleMainWindow( true );
|
|
|
|
ui.translateLine->setText( word );
|
|
|
|
translateInputFinished();
|
|
|
|
}
|
2012-02-16 14:56:25 +00:00
|
|
|
|
|
|
|
void MainWindow::on_showHideHistory_activated()
|
|
|
|
{
|
|
|
|
static bool needHideSearchPane;
|
|
|
|
if( showHistory )
|
|
|
|
{
|
|
|
|
if( needHideSearchPane )
|
|
|
|
{
|
|
|
|
ui.searchPane->hide();
|
|
|
|
needHideSearchPane = false;
|
|
|
|
ui.searchPane->toggleViewAction()->setChecked( false );
|
|
|
|
}
|
|
|
|
ui.searchPane->toggleViewAction()->setEnabled( true );
|
|
|
|
|
|
|
|
ui.showHideHistory->setText( tr( "&Show" ) );
|
|
|
|
showHistory = false;
|
|
|
|
|
|
|
|
connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
|
|
|
|
this, SLOT( translateInputChanged( QString const & ) ) );
|
|
|
|
|
|
|
|
ui.translateLine->clear();
|
|
|
|
ui.translateLine->setEnabled( true );
|
|
|
|
ui.translateLine->setProperty( "noResults", false );
|
|
|
|
setStyleSheet( styleSheet() );
|
|
|
|
|
|
|
|
ui.wordList->clear();
|
|
|
|
|
|
|
|
history.enableAdd( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
history.enableAdd( false );
|
|
|
|
|
|
|
|
disconnect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
|
|
|
|
this, SLOT( translateInputChanged( QString const & ) ) );
|
|
|
|
|
|
|
|
if( !ui.searchPane->isVisible() )
|
|
|
|
{
|
|
|
|
ui.searchPane->show();
|
|
|
|
ui.searchPane->toggleViewAction()->setChecked( true );
|
|
|
|
needHideSearchPane = true;
|
|
|
|
}
|
|
|
|
ui.searchPane->toggleViewAction()->setEnabled( false );
|
|
|
|
|
|
|
|
ui.showHideHistory->setText( tr( "&Hide" ) );
|
|
|
|
showHistory = true;
|
|
|
|
|
|
|
|
ui.translateLine->setEnabled( false );
|
|
|
|
ui.translateLine->setText( tr( "History view mode" ) );
|
|
|
|
ui.translateLine->setProperty( "noResults", true );
|
|
|
|
setStyleSheet( styleSheet() );
|
|
|
|
|
|
|
|
ui.wordList->setUpdatesEnabled( false );
|
|
|
|
ui.wordList->clear();
|
|
|
|
|
|
|
|
QList< History::Item > const & items = history.getItems();
|
|
|
|
for( int x = 0; x < items.size(); ++x )
|
|
|
|
{
|
|
|
|
History::Item const * i = &items[ x ];
|
|
|
|
QListWidgetItem * s = new QListWidgetItem( i->word, ui.wordList );
|
|
|
|
if (s->text().at(0).direction() == QChar::DirR)
|
|
|
|
s->setTextAlignment(Qt::AlignRight);
|
|
|
|
if (s->text().at(0).direction() == QChar::DirL)
|
|
|
|
s->setTextAlignment(Qt::AlignLeft);
|
|
|
|
ui.wordList->addItem( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.wordList->setUpdatesEnabled( true );
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 12:01:52 +00:00
|
|
|
|
|
|
|
void MainWindow::on_exportHistory_activated()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getSaveFileName( this, tr( "Export history to file" ),
|
|
|
|
QDir::homePath(),
|
|
|
|
tr( "Text files (*.txt);;All files (*.*)" ) );
|
|
|
|
if( fileName.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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 history
|
|
|
|
QList< History::Item > const & items = history.getItems();
|
|
|
|
|
|
|
|
QList< History::Item >::const_iterator i;
|
|
|
|
for( i = items.constBegin(); i != items.constEnd(); ++i )
|
|
|
|
{
|
|
|
|
line = i->word.toUtf8();
|
|
|
|
|
|
|
|
line.replace( '\n', ' ' );
|
|
|
|
line.replace( '\r', ' ' );
|
|
|
|
|
|
|
|
line += "\n";
|
|
|
|
|
|
|
|
if ( file.write( line ) != line.size() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i != items.constEnd() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
mainStatusBar->showMessage( tr( "History export complete" ), 5000 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString errStr = QString( tr( "Export error: ") ) + file.errorString();
|
|
|
|
file.close();
|
|
|
|
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
|
|
|
|
}
|