2010-12-09 12:31:50 +00:00
|
|
|
/* This file is (c) 2008-2011 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __MAINWINDOW_HH_INCLUDED__
|
|
|
|
#define __MAINWINDOW_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QToolButton>
|
2009-02-05 20:55:00 +00:00
|
|
|
#include <QSystemTrayIcon>
|
2009-03-26 19:00:08 +00:00
|
|
|
#include <QNetworkAccessManager>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "folding.hh"
|
|
|
|
#include "config.hh"
|
|
|
|
#include "dictionary.hh"
|
|
|
|
#include "article_netmgr.hh"
|
|
|
|
#include "instances.hh"
|
|
|
|
#include "article_maker.hh"
|
|
|
|
#include "scanpopup.hh"
|
|
|
|
#include "articleview.hh"
|
2009-01-29 19:16:25 +00:00
|
|
|
#include "wordfinder.hh"
|
2009-09-21 17:50:03 +00:00
|
|
|
#include "dictionarybar.hh"
|
2009-10-21 19:37:07 +00:00
|
|
|
#include "history.hh"
|
2010-06-28 15:14:07 +00:00
|
|
|
#include "hotkeywrapper.hh"
|
2011-06-27 18:54:15 +00:00
|
|
|
#include "mainstatusbar.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-06-09 07:29:21 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#endif
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2010-06-28 15:14:07 +00:00
|
|
|
class MainWindow: public QMainWindow, public DataCommitter
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
MainWindow( Config::Class & cfg );
|
2009-02-06 17:04:11 +00:00
|
|
|
~MainWindow();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2010-06-28 15:14:07 +00:00
|
|
|
virtual void commitData( QSessionManager & );
|
|
|
|
|
2010-11-20 13:43:55 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
void messageFromAnotherInstanceReceived( QString const & );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
2010-06-28 15:14:07 +00:00
|
|
|
void commitData();
|
|
|
|
bool commitDataCompleted;
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
QSystemTrayIcon * trayIcon;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
Ui::MainWindow ui;
|
2009-04-20 14:13:39 +00:00
|
|
|
|
|
|
|
/// This widget is used as a title bar for the searchPane dock, and
|
|
|
|
/// incorporates the next three objects inside
|
|
|
|
QWidget searchPaneTitleBar;
|
|
|
|
QHBoxLayout searchPaneTitleBarLayout;
|
|
|
|
QLabel groupLabel;
|
|
|
|
GroupComboBox groupList;
|
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
QWidget dictsPaneTitleBar;
|
|
|
|
QHBoxLayout dictsPaneTitleBarLayout;
|
|
|
|
QLabel foundInDictsLabel;
|
|
|
|
|
2010-07-02 11:19:02 +00:00
|
|
|
/// Fonts saved before words zooming is in effect, so it could be reset back.
|
|
|
|
QFont wordListDefaultFont, translateLineDefaultFont;
|
|
|
|
|
2011-06-29 19:12:46 +00:00
|
|
|
QAction escAction, f3Action, shiftF3Action, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
2010-09-16 18:52:40 +00:00
|
|
|
closeAllTabAction, closeRestTabAction,
|
2011-06-26 11:53:28 +00:00
|
|
|
switchToNextTabAction, switchToPrevTabAction,
|
|
|
|
showDictBarNamesAction, useSmallIconsInToolbarsAction, toggleMenuBarAction;
|
2009-01-28 20:55:45 +00:00
|
|
|
QToolBar * navToolbar;
|
2011-06-27 18:54:15 +00:00
|
|
|
MainStatusBar * mainStatusBar;
|
2011-05-31 03:35:43 +00:00
|
|
|
QAction * navBack, * navForward, * navPronounce, * enableScanPopup, * scanPopupSeparator;
|
2009-04-30 19:57:25 +00:00
|
|
|
QAction * zoomIn, * zoomOut, * zoomBase;
|
2010-07-02 11:19:02 +00:00
|
|
|
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
2009-02-08 20:20:02 +00:00
|
|
|
QMenu trayIconMenu;
|
2010-09-16 18:52:40 +00:00
|
|
|
QMenu *tabListMenu, *tabMenu;
|
|
|
|
QToolButton addTab, *tabListButton;
|
2009-04-12 20:46:25 +00:00
|
|
|
Config::Class & cfg;
|
2009-09-21 17:50:03 +00:00
|
|
|
Config::Events configEvents;
|
2009-10-21 19:37:07 +00:00
|
|
|
History history;
|
2009-09-21 17:50:03 +00:00
|
|
|
DictionaryBar dictionaryBar;
|
2009-01-28 20:55:45 +00:00
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
2009-09-23 18:44:38 +00:00
|
|
|
/// Here we store unmuted dictionaries when the dictionary bar is active
|
|
|
|
vector< sptr< Dictionary::Class > > dictionariesUnmuted;
|
2009-05-14 19:27:19 +00:00
|
|
|
Instances::Groups groupInstances;
|
2009-01-28 20:55:45 +00:00
|
|
|
ArticleMaker articleMaker;
|
|
|
|
ArticleNetworkAccessManager articleNetMgr;
|
2009-03-26 19:00:08 +00:00
|
|
|
QNetworkAccessManager dictNetMgr; // We give dictionaries a separate manager,
|
|
|
|
// since their requests can be destroyed
|
|
|
|
// in a separate thread
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
WordFinder wordFinder;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
sptr< ScanPopup > scanPopup;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
sptr< HotkeyWrapper > hotkeyWrapper;
|
2009-04-19 21:32:18 +00:00
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
QTimer newReleaseCheckTimer; // Countdown to a check for the new program
|
|
|
|
// release, if enabled
|
|
|
|
sptr< QNetworkReply > latestReleaseReply;
|
|
|
|
|
2009-11-11 09:40:32 +00:00
|
|
|
sptr< QPrinter > printer; // The printer we use for all printing operations
|
2010-09-16 18:52:40 +00:00
|
|
|
|
2009-11-11 09:40:32 +00:00
|
|
|
QPrinter & getPrinter(); // Creates a printer if it's not there and returns it
|
|
|
|
|
2009-05-16 18:04:21 +00:00
|
|
|
/// Applies the qt's stylesheet, given the style's name.
|
|
|
|
void applyQtStyleSheet( QString const & displayStyle );
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
/// Creates, destroys or otherwise updates tray icon, according to the
|
|
|
|
/// current configuration and situation.
|
|
|
|
void updateTrayIcon();
|
|
|
|
|
|
|
|
void closeEvent( QCloseEvent * );
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
void applyProxySettings();
|
2011-05-08 21:19:08 +00:00
|
|
|
void applyWebSettings();
|
2009-01-28 20:55:45 +00:00
|
|
|
void makeDictionaries();
|
|
|
|
void updateStatusLine();
|
|
|
|
void updateGroupList();
|
2009-09-21 17:50:03 +00:00
|
|
|
void updateDictionaryBar();
|
2009-02-01 00:08:08 +00:00
|
|
|
void makeScanPopup();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void updateMatchResults( bool finished );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void updatePronounceAvailability();
|
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
void updateFoundInDictsList();
|
|
|
|
|
2011-06-07 11:27:19 +00:00
|
|
|
void updateBackForwardButtons();
|
|
|
|
|
2011-06-25 07:53:45 +00:00
|
|
|
void updateWindowTitle();
|
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
/// Updates word search request and active article view in response to
|
|
|
|
/// muting or unmuting dictionaries, or showing/hiding dictionary bar.
|
|
|
|
void applyMutedDictionariesState();
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
virtual bool eventFilter( QObject *, QEvent * );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns the reference to dictionaries stored in the currently active
|
|
|
|
/// group, or to all dictionaries if there are no groups.
|
|
|
|
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
|
|
|
|
2009-04-20 12:25:26 +00:00
|
|
|
/// Brings the main window to front if it's not currently, or hides it
|
|
|
|
/// otherwise. The hiding part is omitted if onlyShow is true.
|
|
|
|
void toggleMainWindow( bool onlyShow = false );
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
/// Creates hotkeyWrapper and hooks the currently set keys for it
|
|
|
|
void installHotKeys();
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
void applyZoomFactor();
|
|
|
|
|
2009-07-31 11:40:54 +00:00
|
|
|
void mousePressEvent ( QMouseEvent * event );
|
|
|
|
|
2010-11-15 15:22:35 +00:00
|
|
|
void updateCurrentGroupProperty();
|
|
|
|
|
2011-06-07 08:26:49 +00:00
|
|
|
/// Handles backward and forward mouse buttons and
|
|
|
|
/// returns true if the event is handled.
|
|
|
|
bool handleBackForwardMouseButtons(QMouseEvent *ev);
|
2010-11-15 15:22:35 +00:00
|
|
|
|
2011-07-01 19:22:40 +00:00
|
|
|
ArticleView * getCurrentArticleView();
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void hotKeyActivated( int );
|
|
|
|
|
2009-04-20 19:54:34 +00:00
|
|
|
/// If new release checks are on, santizies the next check time and starts
|
|
|
|
/// the timer. Does nothing otherwise.
|
|
|
|
void prepareNewReleaseChecks();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
/// Does the new release check.
|
|
|
|
void checkForNewRelease();
|
|
|
|
|
|
|
|
/// Signalled when the lastestReleaseReply is finished()
|
|
|
|
void latestReleaseReplyReady();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
// Executed in response to a user click on an 'add tab' tool button
|
|
|
|
void addNewTab();
|
|
|
|
// Executed in response to a user click on an 'close' button on a tab
|
|
|
|
void tabCloseRequested( int );
|
2009-04-09 22:11:38 +00:00
|
|
|
// Closes current tab.
|
|
|
|
void closeCurrentTab();
|
2010-09-16 18:52:40 +00:00
|
|
|
void closeAllTabs();
|
|
|
|
void closeRestTabs();
|
2009-04-09 22:11:38 +00:00
|
|
|
void switchToNextTab();
|
|
|
|
void switchToPrevTab();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2010-09-16 18:52:40 +00:00
|
|
|
// Handling of active tab list
|
|
|
|
void createTabList();
|
|
|
|
void fillWindowsMenu();
|
|
|
|
void switchToWindow(QAction *act);
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Triggered by the actions in the nav toolbar
|
|
|
|
void backClicked();
|
|
|
|
void forwardClicked();
|
|
|
|
|
|
|
|
/// ArticleView's title has changed
|
|
|
|
void titleChanged( ArticleView *, QString const & );
|
|
|
|
/// ArticleView's icon has changed
|
|
|
|
void iconChanged( ArticleView *, QIcon const & );
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
void pageLoaded( ArticleView * );
|
2009-04-10 21:07:03 +00:00
|
|
|
void tabSwitched( int );
|
2010-09-16 18:52:40 +00:00
|
|
|
void tabMenuRequested(QPoint pos);
|
2009-04-10 21:07:03 +00:00
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void dictionaryBarToggled( bool checked );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
/// Pronounces the currently displayed word by playing its first audio
|
|
|
|
/// reference, if it has any.
|
2009-05-14 19:27:19 +00:00
|
|
|
/// If view is 0, the operation is done for the currently open tab.
|
|
|
|
void pronounce( ArticleView * view = 0 );
|
2009-04-10 21:07:03 +00:00
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
void zoomin();
|
|
|
|
void zoomout();
|
|
|
|
void unzoom();
|
|
|
|
|
2010-07-02 11:19:02 +00:00
|
|
|
void doWordsZoomIn();
|
|
|
|
void doWordsZoomOut();
|
|
|
|
void doWordsZoomBase();
|
|
|
|
|
|
|
|
void applyWordsZoomLevel();
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
/// If editDictionaryGroup is specified, the dialog positions on that group
|
|
|
|
/// initially.
|
|
|
|
void editDictionaries( unsigned editDictionaryGroup = Instances::Group::NoGroupId );
|
|
|
|
/// Edits current group when triggered from the dictionary bar.
|
|
|
|
void editCurrentGroup();
|
2009-02-05 20:55:00 +00:00
|
|
|
void editPreferences();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
void currentGroupChanged( QString const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
void translateInputChanged( QString const & );
|
2009-02-08 14:02:27 +00:00
|
|
|
void translateInputFinished();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2011-05-07 13:42:49 +00:00
|
|
|
/// Closes any opened search in the article view, and focuses the translateLine/close main window to tray.
|
2010-04-27 07:49:37 +00:00
|
|
|
void handleEsc();
|
|
|
|
|
2011-06-29 19:12:46 +00:00
|
|
|
/// Either triggers Edit Dictionaries menu option or perform a Find Next action.
|
|
|
|
void handleF3();
|
|
|
|
void handleShiftF3();
|
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
/// Gives the keyboard focus to the translateLine and selects all the text
|
|
|
|
/// it has.
|
|
|
|
void focusTranslateLine();
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void prefixMatchUpdated();
|
|
|
|
void prefixMatchFinished();
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void wordListItemActivated( QListWidgetItem * );
|
2009-02-08 14:02:27 +00:00
|
|
|
void wordListSelectionChanged();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-06-05 11:49:50 +00:00
|
|
|
void dictsListItemActivated( QListWidgetItem * );
|
|
|
|
void dictsListSelectionChanged();
|
|
|
|
|
|
|
|
void dictsPaneVisibilityChanged ( bool );
|
|
|
|
|
2009-04-13 12:51:25 +00:00
|
|
|
/// Creates a new tab, which is to be populated then with some content.
|
|
|
|
ArticleView * createNewTab( bool switchToIt,
|
|
|
|
QString const & name );
|
|
|
|
|
2009-05-29 19:48:50 +00:00
|
|
|
void openLinkInNewTab( QUrl const &, QUrl const &, QString const &,
|
|
|
|
ArticleView::Contexts const & contexts );
|
2009-05-11 19:14:28 +00:00
|
|
|
void showDefinitionInNewTab( QString const & word, unsigned group,
|
2009-05-29 19:48:50 +00:00
|
|
|
QString const & fromArticle,
|
|
|
|
ArticleView::Contexts const & contexts );
|
2009-05-12 13:25:18 +00:00
|
|
|
void typingEvent( QString const & );
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-09-23 18:44:38 +00:00
|
|
|
void mutedDictionariesChanged();
|
|
|
|
|
2009-10-21 20:06:17 +00:00
|
|
|
void showTranslationFor( QString const &, unsigned inGroup = 0 );
|
2009-02-05 20:55:00 +00:00
|
|
|
|
|
|
|
void trayIconActivated( QSystemTrayIcon::ActivationReason );
|
2009-02-08 14:02:27 +00:00
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
void scanEnableToggled( bool );
|
|
|
|
|
2009-04-18 18:47:01 +00:00
|
|
|
void setAutostart( bool );
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
void showMainWindow();
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void visitHomepage();
|
|
|
|
void visitForum();
|
|
|
|
void showAbout();
|
2009-04-18 18:47:01 +00:00
|
|
|
|
2009-10-12 12:41:20 +00:00
|
|
|
void showDictBarNamesTriggered();
|
2011-05-22 02:42:05 +00:00
|
|
|
void useSmallIconsInToolbarsTriggered();
|
2011-06-26 11:53:28 +00:00
|
|
|
void toggleMenuBarTriggered( bool announce = true );
|
2009-10-12 12:41:20 +00:00
|
|
|
|
2009-10-21 19:37:07 +00:00
|
|
|
void historyChanged();
|
2009-11-01 16:20:26 +00:00
|
|
|
void menuHistoryTriggered( QAction * );
|
2009-10-21 19:37:07 +00:00
|
|
|
void on_clearHistory_activated();
|
|
|
|
|
2011-06-25 07:34:28 +00:00
|
|
|
void on_newTab_activated();
|
|
|
|
|
2009-04-18 18:47:01 +00:00
|
|
|
void on_actionCloseToTray_activated();
|
2010-09-16 18:52:40 +00:00
|
|
|
|
2009-05-01 12:20:33 +00:00
|
|
|
void on_pageSetup_activated();
|
|
|
|
void on_printPreview_activated();
|
|
|
|
void on_print_activated();
|
|
|
|
void printPreviewPaintRequested( QPrinter * );
|
2010-09-16 18:52:40 +00:00
|
|
|
|
2009-05-01 11:17:29 +00:00
|
|
|
void on_saveArticle_activated();
|
2009-05-08 10:47:34 +00:00
|
|
|
|
|
|
|
void on_rescanFiles_activated();
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|