From aad0f9b4c1407af5e90f15396034dd94b1c61801 Mon Sep 17 00:00:00 2001 From: ars Date: Thu, 16 Sep 2010 20:52:40 +0200 Subject: [PATCH] added drop-down tab list --- icons/windows-list.png | Bin 0 -> 1364 bytes mainwindow.cc | 179 ++++++++++++++++++++++++++++++++++------- mainwindow.hh | 18 ++++- resources.qrc | 3 +- 4 files changed, 165 insertions(+), 35 deletions(-) create mode 100644 icons/windows-list.png diff --git a/icons/windows-list.png b/icons/windows-list.png new file mode 100644 index 0000000000000000000000000000000000000000..f60678d6825243e00e4b18e173f21b4c760d2a9c GIT binary patch literal 1364 zcmV-a1*`grP)#F}iR_@#hf(vmc zbmht}TnJW;t00&}h$%#93ns5=nkMOc^XAU=JLk>q%**5@h>LD|;hS^b+?n&^JKxMC z$~i}ma%tdk0grU$ymR!}m9M5=8~>mY*uXlX2(S^X_hY!IZNu1)084-qU#xQq))a5g zegAE6|LPTN-}8Bj#Uf2kPSE=LU0PmVP70WQ_0(IJzPM0XS))o6A_0Q6ytRPX1ff`e zo$M#)94xRov-I}*B3(uJ9{^GNz`$XuR;yI6-|1u^bgFgz4@*D(zC%VUaw!I^1qi-p z#3qc$?5CTVPWg_Ja5gqn9IPu8H2n9iq9YISOx^rWVUdV4zv5=L9@>ZPe;))&i zG{*uZzpf5Y;0$*y;N%k%uz=dh1$#VnfD)%tft^h=@vrDS&Qz{GM)C-%wX0&pI`n_%Ji$jS1|$DhC3u!s$n zI>%5LQIl@ooH>I)7gG#q5z@iEbK>rhBoV+*0vg`h3MmB9k(?*e8tt0`t7!;_;fDoS z(opgKlw)=2+@t++Q1H2-2GoB0)(Tl&kb4xf99rt_t-{wFP$djFjQ|JE-9r+>bQEK4 zBn4<9j3A^VPuJ*^OH&xF76C#Bcmb``wQI9-J+Dp%xXJ@Nj{xfE-rB@>41!Ns5VpzX z$ytqiHR#tUA`fdGKF%o-ask=o+0NM#+XPaCpgjWRL{HKVpAQ{V?;D79q%sU(vwP=R zD+ysc;dlg!_uImDa$d=`(133s%K)}fY_gFg-z~aq@-XzH;1Qq|qohNGi?89|yq`3d zWk97Ekc8Qn43P4DQf~#)vEfdgk*0hBUbKD$U}G;4%3d;aPUeNj2|BvBKB;E`uyUOt z?$~e|xd&VE2t2E_X903^-rzQk4Sq}+TnMXNOJNcaxnUJ75&#Z}9+L*hJPt%t zUmrSDeFO6=v_tx1I$3r^+2y?Y&GPc%JnRGITr!h=Ru3==^or{K|5CsaddAction( &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