mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Merge branch 'themighty1-mru-tab'
This commit is contained in:
commit
ba2ce47ae3
|
@ -85,6 +85,7 @@ Preferences::Preferences():
|
|||
newTabsOpenAfterCurrentOne( false ),
|
||||
newTabsOpenInBackground( true ),
|
||||
hideSingleTab( false ),
|
||||
mruTabOrder ( false ),
|
||||
hideMenubar( false ),
|
||||
enableTrayIcon( true ),
|
||||
startToTray( false ),
|
||||
|
@ -572,6 +573,7 @@ Class load() throw( exError )
|
|||
c.preferences.newTabsOpenAfterCurrentOne = ( preferences.namedItem( "newTabsOpenAfterCurrentOne" ).toElement().text() == "1" );
|
||||
c.preferences.newTabsOpenInBackground = ( preferences.namedItem( "newTabsOpenInBackground" ).toElement().text() == "1" );
|
||||
c.preferences.hideSingleTab = ( preferences.namedItem( "hideSingleTab" ).toElement().text() == "1" );
|
||||
c.preferences.mruTabOrder = ( preferences.namedItem( "mruTabOrder" ).toElement().text() == "1" );
|
||||
c.preferences.hideMenubar = ( preferences.namedItem( "hideMenubar" ).toElement().text() == "1" );
|
||||
c.preferences.enableTrayIcon = ( preferences.namedItem( "enableTrayIcon" ).toElement().text() == "1" );
|
||||
c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" );
|
||||
|
@ -1044,6 +1046,10 @@ void save( Class const & c ) throw( exError )
|
|||
opt.appendChild( dd.createTextNode( c.preferences.hideSingleTab ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "mruTabOrder" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.mruTabOrder ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "hideMenubar" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.hideMenubar ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -140,6 +140,7 @@ struct Preferences
|
|||
bool newTabsOpenAfterCurrentOne;
|
||||
bool newTabsOpenInBackground;
|
||||
bool hideSingleTab;
|
||||
bool mruTabOrder;
|
||||
bool hideMenubar;
|
||||
bool enableTrayIcon;
|
||||
bool startToTray;
|
||||
|
|
|
@ -195,7 +195,8 @@ HEADERS += folding.hh \
|
|||
xdxf.hh \
|
||||
sdict.hh \
|
||||
decompress.hh \
|
||||
aard.hh
|
||||
aard.hh \
|
||||
mruqmenu.hh
|
||||
FORMS += groups.ui \
|
||||
dictgroupwidget.ui \
|
||||
mainwindow.ui \
|
||||
|
@ -287,7 +288,8 @@ SOURCES += folding.cc \
|
|||
xdxf.cc \
|
||||
sdict.cc \
|
||||
decompress.cc \
|
||||
aard.cc
|
||||
aard.cc \
|
||||
mruqmenu.cc
|
||||
win32 {
|
||||
SOURCES += mouseover_win32/ThTypes.c \
|
||||
wordbyauto.cc \
|
||||
|
|
108
mainwindow.cc
108
mainwindow.cc
|
@ -6,10 +6,12 @@
|
|||
#include "loaddictionaries.hh"
|
||||
#include "preferences.hh"
|
||||
#include "about.hh"
|
||||
#include "mruqmenu.hh"
|
||||
#include <limits.h>
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QIcon>
|
||||
#include <QList>
|
||||
#include <QToolBar>
|
||||
#include <QCloseEvent>
|
||||
#include <QDesktopServices>
|
||||
|
@ -204,6 +206,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
|
||||
|
||||
// Tab management
|
||||
tabListMenu = new MRUQMenu(tr("Opened tabs"), ui.tabWidget);
|
||||
|
||||
connect (tabListMenu, SIGNAL(ctrlReleased()), this, SLOT(ctrlReleased()));
|
||||
|
||||
connect( &addTabAction, SIGNAL( triggered() ),
|
||||
this, SLOT( addNewTab() ) );
|
||||
|
@ -425,6 +430,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
ui.wordList->viewport()->installEventFilter( this );
|
||||
ui.dictsList->installEventFilter( this );
|
||||
ui.dictsList->viewport()->installEventFilter( this );
|
||||
//tabWidget doesn't propagate Ctrl+Tab to the parent widget unless event filter is installed
|
||||
ui.tabWidget->installEventFilter( this );
|
||||
|
||||
if ( cfg.mainWindowGeometry.size() )
|
||||
restoreGeometry( cfg.mainWindowGeometry );
|
||||
|
@ -501,6 +508,12 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
updateStatusLine();
|
||||
}
|
||||
|
||||
void MainWindow::ctrlTabPressed()
|
||||
{
|
||||
emit fillWindowsMenu();
|
||||
tabListButton->click();
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent( QMouseEvent *event)
|
||||
{
|
||||
|
||||
|
@ -852,7 +865,6 @@ 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*)));
|
||||
|
@ -871,18 +883,43 @@ void MainWindow::fillWindowsMenu()
|
|||
{
|
||||
tabListMenu->clear();
|
||||
|
||||
for (int i = 0; i < ui.tabWidget->count(); i++)
|
||||
if(cfg.preferences.mruTabOrder)
|
||||
{
|
||||
QAction *act = tabListMenu->addAction( ui.tabWidget->tabIcon( i ),
|
||||
ui.tabWidget->tabText( i ) );
|
||||
act->setData( i );
|
||||
if (ui.tabWidget->currentIndex() == i)
|
||||
for (int i = 0; i < mruList.count(); i++)
|
||||
{
|
||||
QFont f( act->font() );
|
||||
f.setBold( true );
|
||||
act->setFont( f );
|
||||
QAction *act = tabListMenu->addAction(ui.tabWidget->tabIcon(ui.tabWidget->indexOf(mruList.at(i))), ui.tabWidget->tabText(ui.tabWidget->indexOf(mruList.at(i))));
|
||||
|
||||
//remember the index of the Tab to be later used in ctrlReleased()
|
||||
act->setData(ui.tabWidget->indexOf(mruList.at(i)));
|
||||
|
||||
if (ui.tabWidget->currentIndex() == ui.tabWidget->indexOf(mruList.at(i)))
|
||||
{
|
||||
QFont f( act->font() );
|
||||
f.setBold( true );
|
||||
act->setFont( f );
|
||||
}
|
||||
}
|
||||
if (tabListMenu->actions().size() > 1)
|
||||
{
|
||||
tabListMenu->setActiveAction(tabListMenu->actions().at(1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ui.tabWidget->count(); i++)
|
||||
{
|
||||
QAction *act = tabListMenu->addAction( ui.tabWidget->tabIcon( i ),
|
||||
ui.tabWidget->tabText( i ) );
|
||||
act->setData( i );
|
||||
if (ui.tabWidget->currentIndex() == i)
|
||||
{
|
||||
QFont f( act->font() );
|
||||
f.setBold( true );
|
||||
act->setFont( f );
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::switchToWindow(QAction *act)
|
||||
|
@ -939,6 +976,7 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
|
|||
escaped.replace( "&", "&&" );
|
||||
|
||||
ui.tabWidget->insertTab( index, view, escaped );
|
||||
mruList.append(dynamic_cast<QWidget*>(view));
|
||||
|
||||
if ( switchToIt )
|
||||
ui.tabWidget->setCurrentIndex( index );
|
||||
|
@ -956,10 +994,31 @@ void MainWindow::tabCloseRequested( int x )
|
|||
|
||||
QWidget * w = ui.tabWidget->widget( x );
|
||||
|
||||
if (cfg.preferences.mruTabOrder)
|
||||
{
|
||||
//removeTab activates next tab and emits currentChannged SIGNAL
|
||||
//This is not what we want for MRU, so disable the signal for a moment
|
||||
|
||||
disconnect( ui.tabWidget, SIGNAL( currentChanged( int ) ),
|
||||
this, SLOT( tabSwitched( int ) ) );
|
||||
}
|
||||
|
||||
ui.tabWidget->removeTab( x );
|
||||
|
||||
if (cfg.preferences.mruTabOrder)
|
||||
{
|
||||
connect( ui.tabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( tabSwitched( int ) ) );
|
||||
}
|
||||
|
||||
mruList.removeOne(w);
|
||||
|
||||
delete w;
|
||||
|
||||
//activate a tab in accordance with MRU
|
||||
if ( mruList.size() > 0 ) {
|
||||
ui.tabWidget->setCurrentWidget(mruList.at(0));
|
||||
}
|
||||
|
||||
// if everything is closed, add new tab
|
||||
if ( ui.tabWidget->count() == 0 )
|
||||
addNewTab();
|
||||
|
@ -1014,6 +1073,16 @@ void MainWindow::switchToPrevTab()
|
|||
ui.tabWidget->setCurrentIndex( ui.tabWidget->currentIndex() - 1 );
|
||||
}
|
||||
|
||||
//emitted by tabListMenu when user releases Ctrl
|
||||
void MainWindow::ctrlReleased()
|
||||
{
|
||||
if (tabListMenu->actions().size() > 1)
|
||||
{
|
||||
ui.tabWidget->setCurrentIndex(tabListMenu->activeAction()->data().toInt());
|
||||
}
|
||||
tabListMenu->hide();
|
||||
}
|
||||
|
||||
void MainWindow::backClicked()
|
||||
{
|
||||
DPRINTF( "Back\n" );
|
||||
|
@ -1078,6 +1147,10 @@ void MainWindow::tabSwitched( int )
|
|||
updatePronounceAvailability();
|
||||
updateFoundInDictsList();
|
||||
updateWindowTitle();
|
||||
if (mruList.size() > 1)
|
||||
{
|
||||
mruList.move(mruList.indexOf(ui.tabWidget->widget(ui.tabWidget->currentIndex())),0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::tabMenuRequested(QPoint pos)
|
||||
|
@ -1527,7 +1600,21 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
return handleBackForwardMouseButtons( event );
|
||||
}
|
||||
|
||||
if ( obj == ui.translateLine )
|
||||
if (ev->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent *keyevent = static_cast<QKeyEvent*>(ev);
|
||||
if (keyevent->modifiers() == Qt::ControlModifier && keyevent->key() == Qt::Key_Tab)
|
||||
{
|
||||
if (cfg.preferences.mruTabOrder)
|
||||
{
|
||||
ctrlTabPressed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( obj == ui.translateLine )
|
||||
{
|
||||
if ( ev->type() == QEvent::KeyPress )
|
||||
{
|
||||
|
@ -1647,7 +1734,6 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return QMainWindow::eventFilter( obj, ev );
|
||||
|
||||
return false;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "history.hh"
|
||||
#include "hotkeywrapper.hh"
|
||||
#include "mainstatusbar.hh"
|
||||
#include "mruqmenu.hh"
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <fixx11h.h>
|
||||
|
@ -83,7 +84,10 @@ private:
|
|||
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||
QMenu trayIconMenu;
|
||||
QMenu *tabListMenu, *tabMenu;
|
||||
QMenu *tabMenu;
|
||||
MRUQMenu *tabListMenu;
|
||||
//List that contains indexes of tabs arranged in a most-recently-used order
|
||||
QList<QWidget*> mruList;
|
||||
QToolButton addTab, *tabListButton;
|
||||
Config::Class & cfg;
|
||||
Config::Events configEvents;
|
||||
|
@ -168,6 +172,7 @@ private:
|
|||
bool handleBackForwardMouseButtons(QMouseEvent *ev);
|
||||
|
||||
ArticleView * getCurrentArticleView();
|
||||
void ctrlTabPressed();
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -197,6 +202,7 @@ private slots:
|
|||
void closeRestTabs();
|
||||
void switchToNextTab();
|
||||
void switchToPrevTab();
|
||||
void ctrlReleased();
|
||||
|
||||
// Handling of active tab list
|
||||
void createTabList();
|
||||
|
|
20
mruqmenu.cc
Normal file
20
mruqmenu.cc
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "mruqmenu.hh"
|
||||
#include <QKeyEvent>
|
||||
|
||||
MRUQMenu::MRUQMenu(const QString title, QWidget *parent):
|
||||
QMenu(title,parent)
|
||||
{
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
bool MRUQMenu::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyRelease){
|
||||
QKeyEvent *keyevent = static_cast<QKeyEvent*>(event);
|
||||
if (keyevent->key() == Qt::Key_Control){
|
||||
emit ctrlReleased();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
25
mruqmenu.hh
Normal file
25
mruqmenu.hh
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef MRUQMENU_HH
|
||||
#define MRUQMENU_HH
|
||||
|
||||
#include <QMenu>
|
||||
#include <QEvent>
|
||||
|
||||
//The only difference between this class and QMenu is that this class emits
|
||||
//a signal when Ctrl button is released
|
||||
class MRUQMenu: public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MRUQMenu(const QString title, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
bool eventFilter (QObject*, QEvent*);
|
||||
|
||||
signals:
|
||||
void ctrlReleased();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MRUQMENU_HH
|
|
@ -90,6 +90,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
|||
ui.newTabsOpenAfterCurrentOne->setChecked( p.newTabsOpenAfterCurrentOne );
|
||||
ui.newTabsOpenInBackground->setChecked( p.newTabsOpenInBackground );
|
||||
ui.hideSingleTab->setChecked( p.hideSingleTab );
|
||||
ui.mruTabOrder->setChecked( p.mruTabOrder );
|
||||
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
|
||||
ui.startToTray->setChecked( p.startToTray );
|
||||
ui.closeToTray->setChecked( p.closeToTray );
|
||||
|
@ -205,6 +206,7 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.newTabsOpenAfterCurrentOne = ui.newTabsOpenAfterCurrentOne->isChecked();
|
||||
p.newTabsOpenInBackground = ui.newTabsOpenInBackground->isChecked();
|
||||
p.hideSingleTab = ui.hideSingleTab->isChecked();
|
||||
p.mruTabOrder = ui.mruTabOrder->isChecked();
|
||||
p.enableTrayIcon = ui.enableTrayIcon->isChecked();
|
||||
p.startToTray = ui.startToTray->isChecked();
|
||||
p.closeToTray = ui.closeToTray->isChecked();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>572</width>
|
||||
<height>357</height>
|
||||
<height>376</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -94,6 +94,13 @@ be the last ones.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="mruTabOrder">
|
||||
<property name="text">
|
||||
<string>Ctrl-Tab navigates tabs in MRU order</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue