feature: add Large toolbar icons support (#1789)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run

Co-authored-by: shenleban tongying <shenlebantongying@gmail.com>
Co-authored-by: hashirama <noroi_harau@tutanota.com>
This commit is contained in:
Konstantin 2024-09-30 04:36:27 +00:00 committed by GitHub
parent e91725e495
commit 4a0124de3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 84 additions and 14 deletions

View file

@ -1157,7 +1157,8 @@ Class load()
c.showingDictBarNames = ( root.namedItem( "showingDictBarNames" ).toElement().text() == "1" ); c.showingDictBarNames = ( root.namedItem( "showingDictBarNames" ).toElement().text() == "1" );
c.usingSmallIconsInToolbars = ( root.namedItem( "usingSmallIconsInToolbars" ).toElement().text() == "1" ); c.usingToolbarsIconSize =
( static_cast< ToolbarsIconSize >( root.namedItem( "usingToolbarsIconSize" ).toElement().text().toInt() ) );
if ( !root.namedItem( "historyExportPath" ).isNull() ) if ( !root.namedItem( "historyExportPath" ).isNull() )
c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text(); c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text();
@ -2151,8 +2152,8 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.showingDictBarNames ? "1" : "0" ) ); opt.appendChild( dd.createTextNode( c.showingDictBarNames ? "1" : "0" ) );
root.appendChild( opt ); root.appendChild( opt );
opt = dd.createElement( "usingSmallIconsInToolbars" ); opt = dd.createElement( "usingToolbarsIconSize" );
opt.appendChild( dd.createTextNode( c.usingSmallIconsInToolbars ? "1" : "0" ) ); opt.appendChild( dd.createTextNode( QString::number( static_cast< int >( c.usingToolbarsIconSize ) ) ) );
root.appendChild( opt ); root.appendChild( opt );
if ( !c.historyExportPath.isEmpty() ) { if ( !c.historyExportPath.isEmpty() ) {

View file

@ -820,6 +820,13 @@ struct HeadwordsDialog
} }
}; };
// TODO: arbitrary sizing
enum class ToolbarsIconSize : std::uint8_t {
Small = 0,
Normal = 1,
Large = 2,
};
struct Class struct Class
{ {
Paths paths; Paths paths;
@ -868,7 +875,7 @@ struct Class
bool showingDictBarNames; bool showingDictBarNames;
bool usingSmallIconsInToolbars; ToolbarsIconSize usingToolbarsIconSize = ToolbarsIconSize::Normal;
/// Maximum size for the headwords. /// Maximum size for the headwords.
/// Bigger headwords won't be indexed. For now, only in DSL. /// Bigger headwords won't be indexed. For now, only in DSL.
@ -885,7 +892,6 @@ struct Class
lastPopupGroupId( 0 ), lastPopupGroupId( 0 ),
pinPopupWindow( false ), pinPopupWindow( false ),
showingDictBarNames( false ), showingDictBarNames( false ),
usingSmallIconsInToolbars( false ),
maxHeadwordSize( 256U ), maxHeadwordSize( 256U ),
maxHeadwordsToExpand( 0 ) maxHeadwordsToExpand( 0 )
{ {

View file

@ -92,6 +92,12 @@ void DictionaryBar::setDictionaryIconSize( IconSize size )
setIconSize( normalIconSize ); setIconSize( normalIconSize );
break; break;
} }
case IconSize::Large: {
auto largeSize = QApplication::style()->pixelMetric( QStyle::PM_LargeIconSize );
setIconSize( { largeSize + 10, largeSize + 10 } ); // the value isn't large enough, so we add 10
break;
}
} }
} }

View file

@ -38,7 +38,7 @@ public:
enum class IconSize { enum class IconSize {
Small, Small,
Normal, Normal,
// TODO: implement something to have an Large option Large,
}; };
void setDictionaryIconSize( IconSize size ); void setDictionaryIconSize( IconSize size );

View file

@ -145,6 +145,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
switchToPrevTabAction( this ), switchToPrevTabAction( this ),
showDictBarNamesAction( tr( "Show Names in Dictionary &Bar" ), this ), showDictBarNamesAction( tr( "Show Names in Dictionary &Bar" ), this ),
useSmallIconsInToolbarsAction( tr( "Show Small Icons in &Toolbars" ), this ), useSmallIconsInToolbarsAction( tr( "Show Small Icons in &Toolbars" ), this ),
useLargeIconsInToolbarsAction( tr( "Show Large Icons in &Toolbars" ), this ),
toggleMenuBarAction( tr( "&Menubar" ), this ), toggleMenuBarAction( tr( "&Menubar" ), this ),
focusHeadwordsDlgAction( this ), focusHeadwordsDlgAction( this ),
focusArticleViewAction( this ), focusArticleViewAction( this ),
@ -507,10 +508,17 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
// Use small icons in toolbars // Use small icons in toolbars
useSmallIconsInToolbarsAction.setCheckable( true ); useSmallIconsInToolbarsAction.setCheckable( true );
useSmallIconsInToolbarsAction.setChecked( cfg.usingSmallIconsInToolbars ); useSmallIconsInToolbarsAction.setChecked( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Small );
connect( &useSmallIconsInToolbarsAction, &QAction::triggered, this, &MainWindow::useSmallIconsInToolbarsTriggered ); connect( &useSmallIconsInToolbarsAction, &QAction::triggered, this, &MainWindow::useSmallIconsInToolbarsTriggered );
// Use large icons in toolbars
useLargeIconsInToolbarsAction.setCheckable( true );
useLargeIconsInToolbarsAction.setChecked( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Large );
connect( &useLargeIconsInToolbarsAction, &QAction::triggered, this, &MainWindow::useLargeIconsInToolbarsTriggered );
// Toggle Menubar // Toggle Menubar
toggleMenuBarAction.setCheckable( true ); toggleMenuBarAction.setCheckable( true );
toggleMenuBarAction.setChecked( !cfg.preferences.hideMenubar ); toggleMenuBarAction.setChecked( !cfg.preferences.hideMenubar );
@ -535,6 +543,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
ui.menuView->addSeparator(); ui.menuView->addSeparator();
ui.menuView->addAction( &showDictBarNamesAction ); ui.menuView->addAction( &showDictBarNamesAction );
ui.menuView->addAction( &useSmallIconsInToolbarsAction ); ui.menuView->addAction( &useSmallIconsInToolbarsAction );
ui.menuView->addAction( &useLargeIconsInToolbarsAction );
ui.menuView->addSeparator(); ui.menuView->addSeparator();
ui.alwaysOnTop->setChecked( cfg.preferences.alwaysOnTop ); ui.alwaysOnTop->setChecked( cfg.preferences.alwaysOnTop );
ui.menuView->addAction( ui.alwaysOnTop ); ui.menuView->addAction( ui.alwaysOnTop );
@ -905,6 +914,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
#endif #endif
useSmallIconsInToolbarsTriggered(); useSmallIconsInToolbarsTriggered();
useLargeIconsInToolbarsTriggered();
if ( cfg.preferences.checkForNewReleases ) { if ( cfg.preferences.checkForNewReleases ) {
QTimer::singleShot( 0, this, &MainWindow::checkNewRelease ); QTimer::singleShot( 0, this, &MainWindow::checkNewRelease );
@ -1655,8 +1666,15 @@ void MainWindow::updateDictionaryBar()
dictionaryBar.setDictionaries( grp->dictionaries ); dictionaryBar.setDictionaries( grp->dictionaries );
dictionaryBar.setDictionaryIconSize( useSmallIconsInToolbarsAction.isChecked() ? DictionaryBar::IconSize::Small : if ( useSmallIconsInToolbarsAction.isChecked() ) {
DictionaryBar::IconSize::Normal ); dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Small );
}
else if ( useLargeIconsInToolbarsAction.isChecked() ) {
dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Large );
}
else {
dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Normal );
}
} }
} }
@ -3010,6 +3028,13 @@ void MainWindow::showDictBarNamesTriggered()
void MainWindow::useSmallIconsInToolbarsTriggered() void MainWindow::useSmallIconsInToolbarsTriggered()
{ {
bool useSmallIcons = useSmallIconsInToolbarsAction.isChecked(); bool useSmallIcons = useSmallIconsInToolbarsAction.isChecked();
if ( useSmallIcons ) {
cfg.usingToolbarsIconSize = Config::ToolbarsIconSize::Small;
useLargeIconsInToolbarsAction.setChecked( false );
}
else if ( !useLargeIconsInToolbarsAction.isChecked() ) {
cfg.usingToolbarsIconSize = Config::ToolbarsIconSize::Normal;
}
int extent = useSmallIcons ? QApplication::style()->pixelMetric( QStyle::PM_SmallIconSize ) : int extent = useSmallIcons ? QApplication::style()->pixelMetric( QStyle::PM_SmallIconSize ) :
QApplication::style()->pixelMetric( QStyle::PM_ToolBarIconSize ); QApplication::style()->pixelMetric( QStyle::PM_ToolBarIconSize );
@ -3021,7 +3046,30 @@ void MainWindow::useSmallIconsInToolbarsTriggered()
updateDictionaryBar(); updateDictionaryBar();
cfg.usingSmallIconsInToolbars = useSmallIcons;
scanPopup->setDictionaryIconSize();
}
void MainWindow::useLargeIconsInToolbarsTriggered()
{
bool useLargeIcons = useLargeIconsInToolbarsAction.isChecked();
if ( useLargeIcons ) {
cfg.usingToolbarsIconSize = Config::ToolbarsIconSize::Large;
useSmallIconsInToolbarsAction.setChecked( false );
}
else if ( !useSmallIconsInToolbarsAction.isChecked() ) {
cfg.usingToolbarsIconSize = Config::ToolbarsIconSize::Normal;
}
int extent = useLargeIcons ? QApplication::style()->pixelMetric( QStyle::PM_LargeIconSize ) :
QApplication::style()->pixelMetric( QStyle::PM_ToolBarIconSize );
navToolbar->setIconSize( QSize( extent, extent ) );
menuButton->setIconSize( QSize( extent, extent ) );
updateDictionaryBar();
scanPopup->setDictionaryIconSize(); scanPopup->setDictionaryIconSize();
} }

View file

@ -107,8 +107,8 @@ private:
QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction, closeAllTabAction, QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction, closeAllTabAction,
closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction, closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction,
useSmallIconsInToolbarsAction, toggleMenuBarAction, focusHeadwordsDlgAction, focusArticleViewAction, useSmallIconsInToolbarsAction, useLargeIconsInToolbarsAction, toggleMenuBarAction, focusHeadwordsDlgAction,
addAllTabToFavoritesAction; focusArticleViewAction, addAllTabToFavoritesAction;
QAction stopAudioAction; QAction stopAudioAction;
QToolBar * navToolbar; QToolBar * navToolbar;
@ -408,6 +408,7 @@ private slots:
void showDictBarNamesTriggered(); void showDictBarNamesTriggered();
void useSmallIconsInToolbarsTriggered(); void useSmallIconsInToolbarsTriggered();
void useLargeIconsInToolbarsTriggered();
void toggleMenuBarTriggered( bool announce = true ); void toggleMenuBarTriggered( bool announce = true );
void on_clearHistory_triggered(); void on_clearHistory_triggered();

View file

@ -1110,10 +1110,18 @@ void ScanPopup::on_goForwardButton_clicked() const
void ScanPopup::setDictionaryIconSize() void ScanPopup::setDictionaryIconSize()
{ {
dictionaryBar.setDictionaryIconSize( cfg.usingSmallIconsInToolbars ? DictionaryBar::IconSize::Small : if ( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Small ) {
DictionaryBar::IconSize::Normal ); dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Small );
}
else if ( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Normal ) {
dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Normal );
}
else if ( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Large ) {
dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Large );
}
} }
void ScanPopup::setGroupByName( QString const & name ) const void ScanPopup::setGroupByName( QString const & name ) const
{ {
int i; int i;