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.usingSmallIconsInToolbars = ( root.namedItem( "usingSmallIconsInToolbars" ).toElement().text() == "1" );
c.usingToolbarsIconSize =
( static_cast< ToolbarsIconSize >( root.namedItem( "usingToolbarsIconSize" ).toElement().text().toInt() ) );
if ( !root.namedItem( "historyExportPath" ).isNull() )
c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text();
@ -2151,8 +2152,8 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.showingDictBarNames ? "1" : "0" ) );
root.appendChild( opt );
opt = dd.createElement( "usingSmallIconsInToolbars" );
opt.appendChild( dd.createTextNode( c.usingSmallIconsInToolbars ? "1" : "0" ) );
opt = dd.createElement( "usingToolbarsIconSize" );
opt.appendChild( dd.createTextNode( QString::number( static_cast< int >( c.usingToolbarsIconSize ) ) ) );
root.appendChild( opt );
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
{
Paths paths;
@ -868,7 +875,7 @@ struct Class
bool showingDictBarNames;
bool usingSmallIconsInToolbars;
ToolbarsIconSize usingToolbarsIconSize = ToolbarsIconSize::Normal;
/// Maximum size for the headwords.
/// Bigger headwords won't be indexed. For now, only in DSL.
@ -885,7 +892,6 @@ struct Class
lastPopupGroupId( 0 ),
pinPopupWindow( false ),
showingDictBarNames( false ),
usingSmallIconsInToolbars( false ),
maxHeadwordSize( 256U ),
maxHeadwordsToExpand( 0 )
{

View file

@ -92,6 +92,12 @@ void DictionaryBar::setDictionaryIconSize( IconSize size )
setIconSize( normalIconSize );
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 {
Small,
Normal,
// TODO: implement something to have an Large option
Large,
};
void setDictionaryIconSize( IconSize size );

View file

@ -145,6 +145,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
switchToPrevTabAction( this ),
showDictBarNamesAction( tr( "Show Names in Dictionary &Bar" ), this ),
useSmallIconsInToolbarsAction( tr( "Show Small Icons in &Toolbars" ), this ),
useLargeIconsInToolbarsAction( tr( "Show Large Icons in &Toolbars" ), this ),
toggleMenuBarAction( tr( "&Menubar" ), this ),
focusHeadwordsDlgAction( this ),
focusArticleViewAction( this ),
@ -507,10 +508,17 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
// Use small icons in toolbars
useSmallIconsInToolbarsAction.setCheckable( true );
useSmallIconsInToolbarsAction.setChecked( cfg.usingSmallIconsInToolbars );
useSmallIconsInToolbarsAction.setChecked( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Small );
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
toggleMenuBarAction.setCheckable( true );
toggleMenuBarAction.setChecked( !cfg.preferences.hideMenubar );
@ -535,6 +543,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
ui.menuView->addSeparator();
ui.menuView->addAction( &showDictBarNamesAction );
ui.menuView->addAction( &useSmallIconsInToolbarsAction );
ui.menuView->addAction( &useLargeIconsInToolbarsAction );
ui.menuView->addSeparator();
ui.alwaysOnTop->setChecked( cfg.preferences.alwaysOnTop );
ui.menuView->addAction( ui.alwaysOnTop );
@ -905,6 +914,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
#endif
useSmallIconsInToolbarsTriggered();
useLargeIconsInToolbarsTriggered();
if ( cfg.preferences.checkForNewReleases ) {
QTimer::singleShot( 0, this, &MainWindow::checkNewRelease );
@ -1655,8 +1666,15 @@ void MainWindow::updateDictionaryBar()
dictionaryBar.setDictionaries( grp->dictionaries );
dictionaryBar.setDictionaryIconSize( useSmallIconsInToolbarsAction.isChecked() ? DictionaryBar::IconSize::Small :
DictionaryBar::IconSize::Normal );
if ( useSmallIconsInToolbarsAction.isChecked() ) {
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()
{
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 ) :
QApplication::style()->pixelMetric( QStyle::PM_ToolBarIconSize );
@ -3021,7 +3046,30 @@ void MainWindow::useSmallIconsInToolbarsTriggered()
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();
}

View file

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

View file

@ -1110,10 +1110,18 @@ void ScanPopup::on_goForwardButton_clicked() const
void ScanPopup::setDictionaryIconSize()
{
dictionaryBar.setDictionaryIconSize( cfg.usingSmallIconsInToolbars ? DictionaryBar::IconSize::Small :
DictionaryBar::IconSize::Normal );
if ( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Small ) {
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
{
int i;