From b37c2861d33f36df953a6423eea39f58c5ab85c2 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:47:37 +0800 Subject: [PATCH] opt: large icon and word zoom (#2038) --- src/ui/mainwindow.cc | 19 +++++++++++---- src/ui/scanpopup.cc | 55 +++++++++++--------------------------------- src/ui/scanpopup.ui | 4 ++-- 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 5e85d0798..977c7d986 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -240,12 +240,14 @@ MainWindow::MainWindow( Config::Class & cfg_ ): // translate box groupListInToolbar = new GroupComboBox( navToolbar ); - groupListInToolbar->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ); + groupListInToolbar->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred ); groupListInToolbar->setSizeAdjustPolicy( QComboBox::AdjustToContents ); + groupListInToolbar->setStyleSheet( "QComboBox { padding: 0px; margin: 0px; }" ); translateBoxLayout->addWidget( groupListInToolbar ); translateBox = new TranslateBox( navToolbar ); - translateBox->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); + translateBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred ); + translateBox->setStyleSheet( "QComboBox { padding: 0px; margin: 0px; }" ); translateBoxLayout->addWidget( translateBox ); translateBoxToolBarAction = navToolbar->addWidget( translateBoxWidget ); @@ -3140,6 +3142,10 @@ int MainWindow::getIconSize() void MainWindow::iconSizeActionTriggered( QAction * /*action*/ ) { + //reset word zoom + cfg.preferences.wordsZoomLevel = 0; + wordsZoomBase->setEnabled( false ); + bool useLargeIcons = useLargeIconsInToolbarsAction.isChecked(); int extent = getIconSize(); if ( useLargeIcons ) { @@ -3159,9 +3165,11 @@ void MainWindow::iconSizeActionTriggered( QAction * /*action*/ ) scanPopup->setDictionaryIconSize(); - //ajust the font size as well + //adjust the font size as well auto font = translateLine->font(); - font.setPixelSize( extent ); + font.setWeight( QFont::Normal ); + //arbitrary value to make it look good + font.setPixelSize( extent * 0.8 ); translateLine->setFont( font ); translateBox->completerWidget()->setFont( font ); groupList->setFont( font ); @@ -3654,7 +3662,8 @@ void MainWindow::applyWordsZoomLevel() if ( ps < 1 ) { ps = 1; } - font.setPixelSize( ps ); + + font.setPixelSize( ps * 0.8 ); ui.wordList->setFont( font ); translateLine->setFont( font ); translateBox->completerWidget()->setFont( font ); diff --git a/src/ui/scanpopup.cc b/src/ui/scanpopup.cc index f94ad9e6b..798ae438b 100644 --- a/src/ui/scanpopup.cc +++ b/src/ui/scanpopup.cc @@ -348,56 +348,27 @@ void ScanPopup::applyZoomFactor() const void ScanPopup::applyWordsZoomLevel() { - QFont font( wordListDefaultFont ); - int ps = font.pointSize(); + QFont font = ui.translateBox->translateLine()->font(); - if ( cfg.preferences.wordsZoomLevel != 0 ) { - ps += cfg.preferences.wordsZoomLevel; - if ( ps < 1 ) { - ps = 1; - } - font.setPointSize( ps ); - } - - if ( ui.translateBox->completerWidget()->font().pointSize() != ps ) { - ui.translateBox->completerWidget()->setFont( font ); - } - - font = translateLineDefaultFont; - ps = font.pointSize(); - - if ( cfg.preferences.wordsZoomLevel != 0 ) { - ps += cfg.preferences.wordsZoomLevel; - if ( ps < 1 ) { - ps = 1; - } - font.setPointSize( ps ); - } - - if ( ui.translateBox->translateLine()->font().pointSize() != ps ) { - ui.translateBox->translateLine()->setFont( font ); - } - - font = groupListDefaultFont; - ps = font.pointSize(); + int ps = dictionaryBar.iconSize().height(); if ( cfg.preferences.wordsZoomLevel != 0 ) { ps += cfg.preferences.wordsZoomLevel; if ( ps < 1 ) { ps = 1; } - font.setPointSize( ps ); + font.setPixelSize( ps * 0.8 ); } + ui.translateBox->completerWidget()->setFont( font ); + ui.translateBox->translateLine()->setFont( font ); - if ( ui.groupList->font().pointSize() != ps ) { - disconnect( ui.groupList, &GroupComboBox::currentIndexChanged, this, &ScanPopup::currentGroupChanged ); - int n = ui.groupList->currentIndex(); - ui.groupList->clear(); - ui.groupList->setFont( font ); - ui.groupList->fill( groups ); - ui.groupList->setCurrentIndex( n ); - connect( ui.groupList, &GroupComboBox::currentIndexChanged, this, &ScanPopup::currentGroupChanged ); - } + disconnect( ui.groupList, &GroupComboBox::currentIndexChanged, this, &ScanPopup::currentGroupChanged ); + int n = ui.groupList->currentIndex(); + ui.groupList->clear(); + ui.groupList->setFont( font ); + ui.groupList->fill( groups ); + ui.groupList->setCurrentIndex( n ); + connect( ui.groupList, &GroupComboBox::currentIndexChanged, this, &ScanPopup::currentGroupChanged ); ui.outerFrame->layout()->activate(); } @@ -1151,6 +1122,8 @@ void ScanPopup::setDictionaryIconSize() else if ( cfg.usingToolbarsIconSize == Config::ToolbarsIconSize::Large ) { dictionaryBar.setDictionaryIconSize( DictionaryBar::IconSize::Large ); } + + applyWordsZoomLevel(); } diff --git a/src/ui/scanpopup.ui b/src/ui/scanpopup.ui index e9550651c..1031fed21 100644 --- a/src/ui/scanpopup.ui +++ b/src/ui/scanpopup.ui @@ -70,7 +70,7 @@ - + 0 0 @@ -83,7 +83,7 @@ - + 0 0