Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jan 2, 2025
2 parents 4b3d090 + f13e223 commit 542ff72
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/dict/utils/indexedzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
return false;
}

if ( header.uncompressedSize == 0 ) {
//the compress data should have some issue.
qDebug() << "uncompressed size is 0;";
return false;
}

data.resize( header.uncompressedSize );

z_stream stream = {};
Expand Down
19 changes: 10 additions & 9 deletions src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <QGuiApplication>
#include <QWebEngineSettings>
#include <QProxyStyle>
#include <QShortcut>

#ifdef HAVE_X11
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
Expand Down Expand Up @@ -392,16 +393,16 @@ MainWindow::MainWindow( Config::Class & cfg_ ):

ui.menuZoom->addSeparator();

wordsZoomIn = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Words Zoom In" ) );
wordsZoomIn->setShortcuts( QList< QKeySequence >() << QKeySequence( "Alt++" ) << QKeySequence( "Alt+=" ) );
wordsZoomOut = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Words Zoom Out" ) );
wordsZoomOut->setShortcut( QKeySequence( "Alt+-" ) );
wordsZoomBase = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Words Normal Size" ) );
wordsZoomBase->setShortcut( QKeySequence( "Alt+0" ) );
wordsZoomIn = new QShortcut( this );
wordsZoomIn->setKey( QKeySequence( "Alt+=" ) );
wordsZoomOut = new QShortcut( this );
wordsZoomOut->setKey( QKeySequence( "Alt+-" ) );
wordsZoomBase = new QShortcut( this );
wordsZoomBase->setKey( QKeySequence( "Alt+0" ) );

connect( wordsZoomIn, &QAction::triggered, this, &MainWindow::doWordsZoomIn );
connect( wordsZoomOut, &QAction::triggered, this, &MainWindow::doWordsZoomOut );
connect( wordsZoomBase, &QAction::triggered, this, &MainWindow::doWordsZoomBase );
connect( wordsZoomIn, &QShortcut::activated, this, &MainWindow::doWordsZoomIn );
connect( wordsZoomOut, &QShortcut::activated, this, &MainWindow::doWordsZoomOut );
connect( wordsZoomBase, &QShortcut::activated, this, &MainWindow::doWordsZoomBase );

// tray icon
#ifndef Q_OS_MACOS // macOS uses the dock menu instead of the tray icon
Expand Down
5 changes: 3 additions & 2 deletions src/ui/mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "audio/audioplayerfactory.hh"
#include "instances.hh"
#include "article_maker.hh"
#include "scanpopup.hh"
#include "ui/articleview.hh"
#include "wordfinder.hh"
#include "dictionarybar.hh"
Expand All @@ -34,12 +33,14 @@
#ifdef HAVE_X11
#include <fixx11h.h>
#endif
#include "scanpopup.hh"

#if defined( Q_OS_MAC )
#include "macos/gd_clipboard.hh"
#endif
//must place the qactiongroup after fixx11h.h, None in QActionGroup conflict with X.h's macro None.
#include <QActionGroup>
#include <QShortcut>

using std::string;
using std::vector;
Expand Down Expand Up @@ -118,7 +119,7 @@ private:
QAction *navBack, *navForward, *navPronounce, *enableScanningAction;
QAction * beforeOptionsSeparator;
QAction *zoomIn, *zoomOut, *zoomBase;
QAction *wordsZoomIn, *wordsZoomOut, *wordsZoomBase;
QShortcut *wordsZoomIn, *wordsZoomOut, *wordsZoomBase;
QAction *addToFavorites, *beforeAddToFavoritesSeparator;
QMenu trayIconMenu;
QMenu * tabMenu;
Expand Down
69 changes: 66 additions & 3 deletions src/ui/scanpopup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ScanPopup::ScanPopup( QWidget * parent,
hideTimer( this )
{
ui.setupUi( this );
toolbar = new QToolBar( "Found Dictionary", this );

if ( layoutDirection() == Qt::RightToLeft ) {
// Adjust button icons for Right-To-Left layout
Expand Down Expand Up @@ -104,6 +105,7 @@ ScanPopup::ScanPopup( QWidget * parent,
connect( this, &ScanPopup::closeMenu, definition, &ArticleView::closePopupMenu );
connect( definition, &ArticleView::sendWordToHistory, this, &ScanPopup::sendWordToHistory );
connect( definition, &ArticleView::typingEvent, this, &ScanPopup::typingEvent );
connect( definition, &ArticleView::updateFoundInDictsList, this, &ScanPopup::updateFoundInDictsList );

openSearchAction.setShortcut( QKeySequence( "Ctrl+F" ) );
openSearchAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
Expand Down Expand Up @@ -148,7 +150,7 @@ ScanPopup::ScanPopup( QWidget * parent,
dictionaryBar.setMutedDictionaries( grp ? &grp->popupMutedDictionaries : nullptr );
}

addToolBar( Qt::RightToolBarArea, &dictionaryBar );
addToolBar( Qt::RightToolBarArea, toolbar );

connect( &dictionaryBar, &DictionaryBar::editGroupRequested, this, &ScanPopup::editGroupRequested );
connect( this, &ScanPopup::closeMenu, &dictionaryBar, &DictionaryBar::closePopupMenu );
Expand Down Expand Up @@ -176,14 +178,17 @@ ScanPopup::ScanPopup( QWidget * parent,
restoreState( cfg.popupWindowState );
}

//fix this toolbar
addToolBar( Qt::TopToolBarArea, &dictionaryBar );

ui.onTopButton->setChecked( cfg.popupWindowAlwaysOnTop );
ui.onTopButton->setVisible( cfg.pinPopupWindow );
connect( ui.onTopButton, &QAbstractButton::clicked, this, &ScanPopup::alwaysOnTopClicked );

ui.pinButton->setChecked( cfg.pinPopupWindow );

if ( cfg.pinPopupWindow ) {
dictionaryBar.setMovable( true );
dictionaryBar.setMovable( false );
Qt::WindowFlags flags = pinnedWindowFlags;
if ( cfg.popupWindowAlwaysOnTop ) {
flags |= Qt::WindowStaysOnTopHint;
Expand Down Expand Up @@ -289,6 +294,64 @@ ScanPopup::ScanPopup( QWidget * parent,
applyWordsZoomLevel();
}

void ScanPopup::onActionTriggered()
{
QAction * action = qobject_cast< QAction * >( sender() );
if ( action != nullptr ) {
auto dictId = action->data().toString();
qDebug() << "Action triggered:" << dictId;
definition->jumpToDictionary( dictId, true );
}
}

void ScanPopup::updateFoundInDictsList()
{
if ( !toolbar->isVisible() ) {
// nothing to do, the list is not visible
return;
}
toolbar->setUpdatesEnabled( false );

unsigned currentId = ui.groupList->getCurrentGroup();
Instances::Group const * grp = groups.findGroup( currentId );

auto dictionaries = grp ? grp->dictionaries : allDictionaries;
QStringList ids = definition->getArticlesList();
QString activeId = definition->getActiveArticleId();
toolbar->clear();
if ( actionGroup != nullptr ) {
actionGroup->deleteLater();
}
actionGroup = new QActionGroup( this );
actionGroup->setExclusive( true );
for ( QStringList::const_iterator i = ids.constBegin(); i != ids.constEnd(); ++i ) {
// Find this dictionary

for ( unsigned x = dictionaries.size(); x--; ) {
if ( dictionaries[ x ]->getId() == i->toUtf8().data() ) {

auto dictionary = dictionaries[ x ];
QIcon icon = dictionary->getIcon();
QString dictName = QString::fromUtf8( dictionary->getName().c_str() );
QAction * action = new QAction( dictName, this );
action->setIcon( icon );
QString id = QString::fromStdString( dictionary->getId() );
action->setData( id );
action->setCheckable( true );
if ( id == activeId ) {
action->setChecked( true );
}
connect( action, &QAction::triggered, this, &ScanPopup::onActionTriggered );
toolbar->addAction( action );
actionGroup->addAction( action );
break;
}
}
}

toolbar->setUpdatesEnabled( true );
}

void ScanPopup::refresh()
{
// currentIndexChanged() signal is very trigger-happy. To avoid triggering
Expand Down Expand Up @@ -898,7 +961,7 @@ void ScanPopup::pinButtonClicked( bool checked )
#endif

setWindowTitle( QString( "%1 - GoldenDict-ng" ).arg( elideInputWord() ) );
dictionaryBar.setMovable( true );
dictionaryBar.setMovable( false );
hideTimer.stop();
}
else {
Expand Down
7 changes: 7 additions & 0 deletions src/ui/scanpopup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
#include "ui_scanpopup.h"
#include <QDialog>
#include <QClipboard>
#include <QToolBar>
#include "history.hh"
#include "dictionarybar.hh"
#include "mainstatusbar.hh"
#ifdef HAVE_X11
#include "scanflag.hh"
#endif

#include <QActionGroup>

/// This is a popup dialog to show translations when clipboard scanning mode
/// is enabled.
class ScanPopup: public QMainWindow, KeyboardState
Expand Down Expand Up @@ -136,6 +139,8 @@ private:
WordFinder wordFinder;
Config::Events configEvents;
DictionaryBar dictionaryBar;
QToolBar * toolbar;
QActionGroup * actionGroup = nullptr;
MainStatusBar * mainStatusBar;
/// Fonts saved before words zooming is in effect, so it could be reset back.
QFont wordListDefaultFont, translateLineDefaultFont, groupListDefaultFont;
Expand Down Expand Up @@ -227,4 +232,6 @@ private slots:
void alwaysOnTopClicked( bool checked );

void titleChanged( ArticleView *, QString const & title ) const;
void updateFoundInDictsList();
void onActionTriggered();
};

0 comments on commit 542ff72

Please sign in to comment.