2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
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-04-21 18:27:26 +00:00
|
|
|
#include "hotkeywrapper.hh"
|
2009-09-21 17:50:03 +00:00
|
|
|
#include "dictionarybar.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
class MainWindow: public QMainWindow
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
|
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;
|
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
QAction focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
2009-04-09 22:11:38 +00:00
|
|
|
switchToNextTabAction, switchToPrevTabAction;
|
2009-01-28 20:55:45 +00:00
|
|
|
QToolBar * navToolbar;
|
2009-04-10 21:07:03 +00:00
|
|
|
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
2009-04-30 19:57:25 +00:00
|
|
|
QAction * zoomIn, * zoomOut, * zoomBase;
|
2009-02-08 20:20:02 +00:00
|
|
|
QMenu trayIconMenu;
|
2009-01-28 20:55:45 +00:00
|
|
|
QToolButton addTab;
|
2009-04-12 20:46:25 +00:00
|
|
|
Config::Class & cfg;
|
2009-09-21 17:50:03 +00:00
|
|
|
Config::Events configEvents;
|
|
|
|
DictionaryBar dictionaryBar;
|
2009-01-28 20:55:45 +00:00
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
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-05-01 12:20:33 +00:00
|
|
|
QPrinter printer; // The printer we use for all printing operations
|
|
|
|
|
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();
|
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();
|
|
|
|
|
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 );
|
|
|
|
|
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();
|
|
|
|
void switchToNextTab();
|
|
|
|
void switchToPrevTab();
|
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 );
|
|
|
|
|
|
|
|
/// 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();
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
void editDictionaries();
|
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
|
|
|
|
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
|
|
|
|
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-01-28 20:55:45 +00:00
|
|
|
void showTranslationFor( QString const & );
|
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
|
|
|
|
|
|
|
void on_actionCloseToTray_activated();
|
2009-05-01 11:17:29 +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 * );
|
|
|
|
|
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
|