diff --git a/icons/windows-list.png b/icons/windows-list.png new file mode 100644 index 00000000..f60678d6 Binary files /dev/null and b/icons/windows-list.png differ diff --git a/mainwindow.cc b/mainwindow.cc index 0244d5f0..c7e6bebf 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -30,6 +30,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ): focusTranslateLineAction( this ), addTabAction( this ), closeCurrentTabAction( this ), + closeAllTabAction( this ), + closeRestTabAction( this ), switchToNextTabAction( this ), switchToPrevTabAction( this ), showDictBarNamesAction( tr( "Show Names in Dictionary Bar" ), this ), @@ -158,6 +160,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ): addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) ); + // Tab management + connect( &addTabAction, SIGNAL( triggered() ), this, SLOT( addNewTab() ) ); @@ -165,12 +169,31 @@ MainWindow::MainWindow( Config::Class & cfg_ ): closeCurrentTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); closeCurrentTabAction.setShortcut( QKeySequence( "Ctrl+W" ) ); + closeCurrentTabAction.setText( tr("Close current tab") ); + closeCurrentTabAction.setIcon( QIcon(":/icons/closetab.png") ); connect( &closeCurrentTabAction, SIGNAL( triggered() ), this, SLOT( closeCurrentTab() ) ); addAction( &closeCurrentTabAction ); + 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 ); + switchToNextTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); switchToNextTabAction.setShortcut( QKeySequence( "Ctrl+PgDown" ) ); @@ -188,6 +211,14 @@ MainWindow::MainWindow( Config::Class & cfg_ ): addAction( &switchToPrevTabAction ); + tabMenu = new QMenu(this); + tabMenu->addAction( &closeCurrentTabAction ); + tabMenu->addAction( &closeRestTabAction ); + tabMenu->addSeparator(); + tabMenu->addAction( &closeAllTabAction ); + + // Dictionary bar names + showDictBarNamesAction.setCheckable( true ); showDictBarNamesAction.setChecked( cfg.showingDictBarNames ); @@ -259,6 +290,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ): ui.tabWidget->setDocumentMode( true ); #endif + ui.tabWidget->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( &addTab, SIGNAL( clicked() ), this, SLOT( addNewTab() ) ); @@ -268,6 +301,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ): connect( ui.tabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( tabSwitched( int ) ) ); + connect( ui.tabWidget, SIGNAL( customContextMenuRequested(QPoint)) , + this, SLOT( tabMenuRequested(QPoint)) ); + #if QT_VERSION >= 0x040500 ui.tabWidget->setTabsClosable( true ); #endif @@ -326,6 +362,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ): addNewTab(); + // Create tab list menu + createTabList(); + // Show the initial welcome text { @@ -378,18 +417,18 @@ MainWindow::MainWindow( Config::Class & cfg_ ): void MainWindow::mousePressEvent( QMouseEvent *event) { - if (event->button() != Qt::MidButton) - return QMainWindow::mousePressEvent(event); - // middle clicked - QString subtype = "plain"; + if (event->button() != Qt::MidButton) + return QMainWindow::mousePressEvent(event); + // middle clicked + QString subtype = "plain"; - QString str = QApplication::clipboard()->text(subtype, - QClipboard::Selection); - ui.translateLine->setText(str); - - QKeyEvent ev(QEvent::Type(6)/*QEvent::KeyPress*/, Qt::Key_Enter, - Qt::NoModifier); - QApplication::sendEvent(ui.translateLine, &ev); + QString str = QApplication::clipboard()->text(subtype, + QClipboard::Selection); + ui.translateLine->setText(str); + + QKeyEvent ev(QEvent::Type(6)/*QEvent::KeyPress*/, Qt::Key_Enter, + Qt::NoModifier); + QApplication::sendEvent(ui.translateLine, &ev); } MainWindow::~MainWindow() @@ -665,7 +704,7 @@ void MainWindow::makeScanPopup() } vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts() -{ +{ if ( groupInstances.empty() ) return dictionaries; @@ -699,6 +738,48 @@ vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts() } } + +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); + tabListButton->setPopupMode(QToolButton::InstantPopup); + ui.tabWidget->setCornerWidget(tabListButton); +} + +void MainWindow::fillWindowsMenu() +{ + tabListMenu->clear(); + + for (int i = 0; i < ui.tabWidget->count(); i++) + { + QAction *act = tabListMenu->addAction(ui.tabWidget->tabText(i)); + act->setData(i); + if (ui.tabWidget->currentIndex() == i) + { + QFont f(act->font()); + f.setBold(true); + act->setFont(f); + act->setCheckable(true); + act->setChecked(true); + } + } +} + +void MainWindow::switchToWindow(QAction *act) +{ + int idx = act->data().toInt(); + ui.tabWidget->setCurrentIndex(idx); +} + + void MainWindow::addNewTab() { createNewTab( true, tr( "(untitled)" ) ); @@ -750,14 +831,18 @@ ArticleView * MainWindow::createNewTab( bool switchToIt, void MainWindow::tabCloseRequested( int x ) { - if ( ui.tabWidget->count() < 2 ) - return; // We should always have at least one open tab +// if ( ui.tabWidget->count() < 2 ) +// return; // We should always have at least one open tab QWidget * w = ui.tabWidget->widget( x ); ui.tabWidget->removeTab( x ); delete w; + + // if everything is closed, add new tab + if ( ui.tabWidget->count() == 0 ) + addNewTab(); } void MainWindow::closeCurrentTab() @@ -765,6 +850,31 @@ void MainWindow::closeCurrentTab() tabCloseRequested( ui.tabWidget->currentIndex() ); } +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); +} + void MainWindow::switchToNextTab() { if ( ui.tabWidget->count() < 2 ) @@ -830,6 +940,15 @@ void MainWindow::tabSwitched( int ) updatePronounceAvailability(); } +void MainWindow::tabMenuRequested(QPoint pos) +{ +// // dont show this menu for single tab +// if ( ui.tabWidget->count() < 2 ) +// return; + + tabMenu->popup(ui.tabWidget->mapToGlobal(pos)); +} + void MainWindow::dictionaryBarToggled( bool ) { // From now on, only the triggered() signal is interesting to us @@ -1556,23 +1675,23 @@ void MainWindow::latestReleaseReplyReady() void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r ) { - switch(r) { - case QSystemTrayIcon::Trigger: - // Left click toggles the visibility of main window - toggleMainWindow(); - break; + switch(r) { + case QSystemTrayIcon::Trigger: + // Left click toggles the visibility of main window + toggleMainWindow(); + break; - case QSystemTrayIcon::MiddleClick: - // Middle mouse click on Tray translates selection - // it is functional like as stardict - if ( scanPopup.get() ) { - scanPopup->translateWordFromSelection(); - } - break; - default: - break; + case QSystemTrayIcon::MiddleClick: + // Middle mouse click on Tray translates selection + // it is functional like as stardict + if ( scanPopup.get() ) { + scanPopup->translateWordFromSelection(); + } + break; + default: + break; - } + } } void MainWindow::scanEnableToggled( bool on ) @@ -1798,7 +1917,7 @@ void MainWindow::on_rescanFiles_activated() groupInstances.clear(); // Release all the dictionaries they hold loadDictionaries( this, true, cfg, dictionaries, dictNetMgr ); - + updateGroupList(); makeScanPopup(); diff --git a/mainwindow.hh b/mainwindow.hh index 247d9dc2..b0fec016 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -58,13 +58,15 @@ private: QFont wordListDefaultFont, translateLineDefaultFont; QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction, + closeAllTabAction, closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction; QToolBar * navToolbar; QAction * navBack, * navForward, * navPronounce, * enableScanPopup; QAction * zoomIn, * zoomOut, * zoomBase; QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase; QMenu trayIconMenu; - QToolButton addTab; + QMenu *tabListMenu, *tabMenu; + QToolButton addTab, *tabListButton; Config::Class & cfg; Config::Events configEvents; History history; @@ -90,7 +92,7 @@ private: sptr< QNetworkReply > latestReleaseReply; sptr< QPrinter > printer; // The printer we use for all printing operations - + QPrinter & getPrinter(); // Creates a printer if it's not there and returns it /// Applies the qt's stylesheet, given the style's name. @@ -158,9 +160,16 @@ private slots: void tabCloseRequested( int ); // Closes current tab. void closeCurrentTab(); + void closeAllTabs(); + void closeRestTabs(); void switchToNextTab(); void switchToPrevTab(); + // Handling of active tab list + void createTabList(); + void fillWindowsMenu(); + void switchToWindow(QAction *act); + /// Triggered by the actions in the nav toolbar void backClicked(); void forwardClicked(); @@ -172,6 +181,7 @@ private slots: void pageLoaded( ArticleView * ); void tabSwitched( int ); + void tabMenuRequested(QPoint pos); void dictionaryBarToggled( bool checked ); @@ -248,12 +258,12 @@ private slots: void on_clearHistory_activated(); void on_actionCloseToTray_activated(); - + void on_pageSetup_activated(); void on_printPreview_activated(); void on_print_activated(); void printPreviewPaintRequested( QPrinter * ); - + void on_saveArticle_activated(); void on_rescanFiles_activated(); diff --git a/resources.qrc b/resources.qrc index b408048a..caa3ccf9 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,5 +1,5 @@ - + version.txt icons/print.png icons/arrow.png @@ -41,5 +41,6 @@ icons/internet.png icons/icon_dsl_native.png icons/forvo.png + icons/windows-list.png