New interface preference: Context menu dictionaries limit

Controls both context menus, in the dictionary bar and in the article view.
Can be adjusted in Preferences -> Interface -> Context menu dictionaries limit.
By default, it is set to 20.
This commit is contained in:
Tvangeste 2013-06-11 20:31:01 +02:00
parent 7599b8e33e
commit de2bf73e66
9 changed files with 222 additions and 138 deletions

View file

@ -1323,7 +1323,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
if ( allDictionaries[ x ]->getId() == i->toUtf8().data() ) if ( allDictionaries[ x ]->getId() == i->toUtf8().data() )
{ {
QAction * action = 0; QAction * action = 0;
if ( refsAdded == cfg.maxDictionaryRefsInContextMenu ) if ( refsAdded == cfg.preferences.maxDictionaryRefsInContextMenu )
{ {
// Enough! Or the menu would become too large. // Enough! Or the menu would become too large.
maxDictionaryRefsAction = new QAction( ".........", &menu ); maxDictionaryRefsAction = new QAction( ".........", &menu );

View file

@ -124,6 +124,7 @@ Preferences::Preferences():
, historyStoreInterval( 0 ) , historyStoreInterval( 0 )
, collapseBigArticles( false ) , collapseBigArticles( false )
, articleSizeLimit( 2000 ) , articleSizeLimit( 2000 )
, maxDictionaryRefsInContextMenu ( 20 )
{ {
} }
@ -733,6 +734,9 @@ Class load() throw( exError )
if ( !preferences.namedItem( "articleSizeLimit" ).isNull() ) if ( !preferences.namedItem( "articleSizeLimit" ).isNull() )
c.preferences.articleSizeLimit = preferences.namedItem( "articleSizeLimit" ).toElement().text().toUInt() ; c.preferences.articleSizeLimit = preferences.namedItem( "articleSizeLimit" ).toElement().text().toUInt() ;
if ( !preferences.namedItem( "maxDictionaryRefsInContextMenu" ).isNull() )
c.preferences.maxDictionaryRefsInContextMenu = preferences.namedItem( "maxDictionaryRefsInContextMenu" ).toElement().text().toUShort();
} }
c.lastMainGroupId = root.namedItem( "lastMainGroupId" ).toElement().text().toUInt(); c.lastMainGroupId = root.namedItem( "lastMainGroupId" ).toElement().text().toUInt();
@ -800,9 +804,6 @@ Class load() throw( exError )
c.usingSmallIconsInToolbars = ( root.namedItem( "usingSmallIconsInToolbars" ).toElement().text() == "1" ); c.usingSmallIconsInToolbars = ( root.namedItem( "usingSmallIconsInToolbars" ).toElement().text() == "1" );
if ( !root.namedItem( "maxDictionaryRefsInContextMenu" ).isNull() )
c.maxDictionaryRefsInContextMenu = root.namedItem( "maxDictionaryRefsInContextMenu" ).toElement().text().toUShort();
if ( !root.namedItem( "historyExportPath" ).isNull() ) if ( !root.namedItem( "historyExportPath" ).isNull() )
c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text(); c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text();
@ -1461,6 +1462,10 @@ void save( Class const & c ) throw( exError )
opt = dd.createElement( "articleSizeLimit" ); opt = dd.createElement( "articleSizeLimit" );
opt.appendChild( dd.createTextNode( QString::number( c.preferences.articleSizeLimit ) ) ); opt.appendChild( dd.createTextNode( QString::number( c.preferences.articleSizeLimit ) ) );
preferences.appendChild( opt );
opt = dd.createElement( "maxDictionaryRefsInContextMenu" );
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxDictionaryRefsInContextMenu ) ) );
preferences.appendChild( opt ); } preferences.appendChild( opt ); }
{ {
@ -1539,10 +1544,6 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( c.usingSmallIconsInToolbars ? "1" : "0" ) ); opt.appendChild( dd.createTextNode( c.usingSmallIconsInToolbars ? "1" : "0" ) );
root.appendChild( opt ); root.appendChild( opt );
opt = dd.createElement( "maxDictionaryRefsInContextMenu" );
opt.appendChild( dd.createTextNode( QString::number( c.maxDictionaryRefsInContextMenu ) ) );
root.appendChild( opt );
if( !c.historyExportPath.isEmpty() ) if( !c.historyExportPath.isEmpty() )
{ {
opt = dd.createElement( "historyExportPath" ); opt = dd.createElement( "historyExportPath" );

View file

@ -210,6 +210,8 @@ struct Preferences
bool collapseBigArticles; bool collapseBigArticles;
int articleSizeLimit; int articleSizeLimit;
unsigned short maxDictionaryRefsInContextMenu;
QString addonStyle; QString addonStyle;
Preferences(); Preferences();
@ -465,8 +467,6 @@ struct Class
bool usingSmallIconsInToolbars; bool usingSmallIconsInToolbars;
unsigned short maxDictionaryRefsInContextMenu;
int maxPictureWidth; // Maximum picture width int maxPictureWidth; // Maximum picture width
/// Maximum size for the headwords. /// Maximum size for the headwords.
@ -481,7 +481,7 @@ struct Class
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ), Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
pinPopupWindow( false ), showingDictBarNames( false ), pinPopupWindow( false ), showingDictBarNames( false ),
usingSmallIconsInToolbars( false ), maxDictionaryRefsInContextMenu( 20 ), usingSmallIconsInToolbars( false ),
maxPictureWidth( 0 ), maxHeadwordSize ( 256U ) maxPictureWidth( 0 ), maxHeadwordSize ( 256U )
{} {}
Group * getGroup( unsigned id ); Group * getGroup( unsigned id );

View file

@ -6,20 +6,24 @@
#include <QProcess> #include <QProcess>
#include "dprintf.hh" #include "dprintf.hh"
#include "fsencoding.hh" #include "fsencoding.hh"
#include <QDebug>
using std::vector; using std::vector;
DictionaryBar::DictionaryBar( QWidget * parent, DictionaryBar::DictionaryBar( QWidget * parent,
Config::Events & events, QString const & _editDictionaryCommand ): Config::Events & events, QString const & _editDictionaryCommand, unsigned short const & maxDictionaryRefsInContextMenu_ ):
QToolBar( tr( "&Dictionary Bar" ), parent ), QToolBar( tr( "&Dictionary Bar" ), parent ),
mutedDictionaries( 0 ), mutedDictionaries( 0 ),
configEvents( events ), configEvents( events ),
editDictionaryCommand( _editDictionaryCommand ), editDictionaryCommand( _editDictionaryCommand ),
maxDictionaryRefsInContextMenu(maxDictionaryRefsInContextMenu_),
use14x21( false ), use14x21( false ),
timerId( 0 ) timerId( 0 )
{ {
setObjectName( "dictionaryBar" ); setObjectName( "dictionaryBar" );
maxDictionaryRefsAction = new QAction( QIcon(":/icons/expand_opt.png"), tr( "Extended menu with all dictionaries..." ), this );
connect( &events, SIGNAL( mutedDictionariesChanged() ), connect( &events, SIGNAL( mutedDictionariesChanged() ),
this, SLOT( mutedDictionariesChanged() ) ); this, SLOT( mutedDictionariesChanged() ) );
@ -96,6 +100,11 @@ void DictionaryBar::setDictionaryIconSize( int extent )
} }
void DictionaryBar::contextMenuEvent( QContextMenuEvent * event ) void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
{
showContextMenu( event );
}
void DictionaryBar::showContextMenu( QContextMenuEvent * event, bool extended )
{ {
QMenu menu( this ); QMenu menu( this );
@ -141,9 +150,20 @@ void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
if ( !dictActions.empty() ) if ( !dictActions.empty() )
menu.addSeparator(); menu.addSeparator();
unsigned refsAdded = 0;
for( QList< QAction * >::iterator i = dictActions.begin(); for( QList< QAction * >::iterator i = dictActions.begin();
i != dictActions.end(); ++i ) i != dictActions.end(); ++i )
{ {
// Enough! Or the menu would become too large.
if ( refsAdded++ >= maxDictionaryRefsInContextMenu && !extended )
{
menu.addSeparator();
menu.addAction( maxDictionaryRefsAction );
break;
}
// We need new action, since the one we have has text elided // We need new action, since the one we have has text elided
QAction * action = menu.addAction( (*i)->icon(), (*i)->toolTip() ); QAction * action = menu.addAction( (*i)->icon(), (*i)->toolTip() );
@ -181,6 +201,11 @@ void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
QApplication::beep(); QApplication::beep();
} }
if( result && result == maxDictionaryRefsAction )
{
showContextMenu( event, true );
}
if ( result == editAction ) if ( result == editAction )
emit editGroupRequested(); emit editGroupRequested();
else else

View file

@ -19,7 +19,7 @@ public:
/// Constructs an empty dictionary bar /// Constructs an empty dictionary bar
DictionaryBar( QWidget * parent, DictionaryBar( QWidget * parent,
Config::Events &, QString const & _editDictionaryCommand ); Config::Events &, QString const & _editDictionaryCommand, unsigned short const & maxDictionaryRefsInContextMenu_ );
/// Sets dictionaries to be displayed in the bar. Their statuses (enabled/ /// Sets dictionaries to be displayed in the bar. Their statuses (enabled/
/// disabled) are taken from the configuration data. /// disabled) are taken from the configuration data.
@ -51,9 +51,12 @@ private:
Config::Events & configEvents; Config::Events & configEvents;
Config::MutedDictionaries storedMutedSet; Config::MutedDictionaries storedMutedSet;
QString editDictionaryCommand; QString editDictionaryCommand;
// how many dictionaries should be shown in the context menu:
unsigned short const & maxDictionaryRefsInContextMenu;
std::vector< sptr< Dictionary::Class > > allDictionaries; std::vector< sptr< Dictionary::Class > > allDictionaries;
/// All the actions we have added to the toolbar /// All the actions we have added to the toolbar
QList< QAction * > dictActions; QList< QAction * > dictActions;
QAction * maxDictionaryRefsAction;
bool use14x21; bool use14x21;
int timerId; int timerId;
@ -71,6 +74,8 @@ private slots:
void actionWasTriggered( QAction * ); void actionWasTriggered( QAction * );
void dictsPaneClicked( QString const & ); void dictsPaneClicked( QString const & );
void showContextMenu( QContextMenuEvent * event, bool extended = false );
}; };
#endif #endif

View file

@ -84,7 +84,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
addTab( this ), addTab( this ),
cfg( cfg_ ), cfg( cfg_ ),
history( History::Load(), cfg_.preferences.maxStringsInHistory, cfg_.maxHeadwordSize ), history( History::Load(), cfg_.preferences.maxStringsInHistory, cfg_.maxHeadwordSize ),
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ), dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle, articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle,
cfg.preferences.addonStyle ), cfg.preferences.addonStyle ),
articleNetMgr( this, dictionaries, articleMaker, articleNetMgr( this, dictionaries, articleMaker,

View file

@ -138,6 +138,8 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
ui.collapseBigArticles->setChecked( p.collapseBigArticles ); ui.collapseBigArticles->setChecked( p.collapseBigArticles );
ui.articleSizeLimit->setValue( p.articleSizeLimit ); ui.articleSizeLimit->setValue( p.articleSizeLimit );
ui.maxDictsInContextMenu->setValue( p.maxDictionaryRefsInContextMenu );
// Different platforms have different keys available // Different platforms have different keys available
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
@ -258,6 +260,8 @@ Config::Preferences Preferences::getPreferences()
p.collapseBigArticles = ui.collapseBigArticles->isChecked(); p.collapseBigArticles = ui.collapseBigArticles->isChecked();
p.articleSizeLimit = ui.articleSizeLimit->text().toInt(); p.articleSizeLimit = ui.articleSizeLimit->text().toInt();
p.maxDictionaryRefsInContextMenu = ui.maxDictsInContextMenu->text().toInt();
p.pronounceOnLoadMain = ui.pronounceOnLoadMain->isChecked(); p.pronounceOnLoadMain = ui.pronounceOnLoadMain->isChecked();
p.pronounceOnLoadPopup = ui.pronounceOnLoadPopup->isChecked(); p.pronounceOnLoadPopup = ui.pronounceOnLoadPopup->isChecked();
p.useExternalPlayer = ui.useExternalPlayer->isChecked(); p.useExternalPlayer = ui.useExternalPlayer->isChecked();

View file

@ -47,6 +47,140 @@
<string>&amp;Interface</string> <string>&amp;Interface</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Startup</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="cbAutostart">
<property name="toolTip">
<string>Automatically starts GoldenDict after operation system bootup.</string>
</property>
<property name="text">
<string>Start with system</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="addonStylesLabel">
<property name="text">
<string>Add-on style:</string>
</property>
</widget>
</item>
<item>
<widget class="StylesComboBox" name="addonStyles"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="enableTrayIcon">
<property name="toolTip">
<string>When enabled, an icon appears in the sytem tray area which can be used
to open main window and perform other tasks.</string>
</property>
<property name="title">
<string>Enable system tray icon</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="startToTray">
<property name="toolTip">
<string>With this on, the application starts directly to system tray without showing
its main window.</string>
</property>
<property name="text">
<string>Start to system tray</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closeToTray">
<property name="toolTip">
<string>With this on, an attempt to close main window would hide it instead of closing
the application.</string>
</property>
<property name="text">
<string>Close to system tray</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="doubleClickTranslates">
<property name="text">
<string>Double-click translates the word clicked</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="escKeyHidesMainWindow">
<property name="toolTip">
<string>Normally, pressing ESC key moves focus to the translation line.
With this on however, it will hide the main window.</string>
</property>
<property name="text">
<string>ESC key hides main window</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="selectBySingleClick">
<property name="toolTip">
<string>Turn this option on if you want to select words by single mouse click</string>
</property>
<property name="text">
<string>Select word by single click</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
@ -97,95 +231,6 @@ be the last ones.</string>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QGroupBox" name="enableTrayIcon">
<property name="toolTip">
<string>When enabled, an icon appears in the sytem tray area which can be used
to open main window and perform other tasks.</string>
</property>
<property name="title">
<string>Enable system tray icon</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="startToTray">
<property name="toolTip">
<string>With this on, the application starts directly to system tray without showing
its main window.</string>
</property>
<property name="text">
<string>Start to system tray</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closeToTray">
<property name="toolTip">
<string>With this on, an attempt to close main window would hide it instead of closing
the application.</string>
</property>
<property name="text">
<string>Close to system tray</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="selectBySingleClick">
<property name="toolTip">
<string>Turn this option on if you want to select words by single mouse click</string>
</property>
<property name="text">
<string>Select word by single click</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Startup</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="cbAutostart">
<property name="toolTip">
<string>Automatically starts GoldenDict after operation system bootup.</string>
</property>
<property name="text">
<string>Start with system</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
@ -252,48 +297,52 @@ the application.</string>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="0"> <item row="3" column="1">
<widget class="QCheckBox" name="doubleClickTranslates"> <layout class="QHBoxLayout" name="horizontalLayout_13">
<property name="text"> <item>
<string>Double-click translates the word clicked</string> <widget class="QLabel" name="maxDictsInContextMenuLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="escKeyHidesMainWindow">
<property name="toolTip"> <property name="toolTip">
<string>Normally, pressing ESC key moves focus to the translation line. <string>Adjust this value to avoid huge context menus.</string>
With this on however, it will hide the main window.</string>
</property> </property>
<property name="text"> <property name="text">
<string>ESC key hides main window</string> <string>Context menu dictionaries limit:</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="addonStylesLabel">
<property name="text">
<string>Add-on style:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="StylesComboBox" name="addonStyles"/> <widget class="QSpinBox" name="maxDictsInContextMenu">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>20</number>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_6"> <widget class="QLabel" name="label_12">
<property name="orientation"> <property name="sizePolicy">
<enum>Qt::Horizontal</enum> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="text">
<size> <string/>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -1252,7 +1301,7 @@ It is not needed to select this option if you don't use such programs.</string>
<item> <item>
<widget class="QSpinBox" name="articleSizeLimit"> <widget class="QSpinBox" name="articleSizeLimit">
<property name="toolTip"> <property name="toolTip">
<string>Artiles longer than this size will be collapsed</string> <string>Articles longer than this size will be collapsed</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>100000</number> <number>100000</number>

View file

@ -49,7 +49,7 @@ ScanPopup::ScanPopup( QWidget * parent,
switchExpandModeAction( this ), switchExpandModeAction( this ),
focusTranslateLineAction( this ), focusTranslateLineAction( this ),
wordFinder( this ), wordFinder( this ),
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ), dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
mouseEnteredOnce( false ), mouseEnteredOnce( false ),
mouseIntercepted( false ), mouseIntercepted( false ),
hideTimer( this ) hideTimer( this )