mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Revert "fix: white flash when WebEngine page is loading in dark reader mode"
This reverts commit f7d6328f40
.
This commit is contained in:
parent
4008e47625
commit
3a93f8b959
|
@ -1,3 +1,18 @@
|
|||
html
|
||||
{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
||||
.gdarticle
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
html
|
||||
{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
text-decoration: none;
|
||||
|
@ -9,6 +19,11 @@ a:hover
|
|||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.gdarticle
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
||||
/* The 'From ' string which preceeds dictionary name in the heading */
|
||||
.gdfromprefix
|
||||
{
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
html
|
||||
{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
margin-top: 1px;
|
||||
margin-right: 3px;
|
||||
margin-left: 2px;
|
||||
margin-bottom: 3px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
a
|
||||
|
@ -24,6 +30,7 @@ a:hover
|
|||
padding: 5px;
|
||||
border: 1px solid #d0dde2;
|
||||
border-radius: 8px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.gdactivearticle
|
||||
|
|
|
@ -51,11 +51,6 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
"<html><head>"
|
||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
|
||||
|
||||
// background is #242525 because Darkreader will invert pure white to this value
|
||||
if( GlobalBroadcaster::instance()->getPreference()->darkReaderMode ){
|
||||
result += R"(<style> html { background-color: #242525;} body { background-color: #242525;} </style>)";
|
||||
}
|
||||
|
||||
// add jquery
|
||||
{
|
||||
result += "<script type=\"text/javascript\" "
|
||||
|
@ -156,11 +151,13 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
|
||||
if( GlobalBroadcaster::instance()->getPreference()->darkReaderMode )
|
||||
{
|
||||
// Why .gdarticle background reset?
|
||||
// some custom theme may change it to other colors and they looks horrible in darkreader mode
|
||||
// #242525 because Darkreader will invert pure white to this value
|
||||
result += R"(
|
||||
<script src="qrc:///scripts/darkreader.js"></script>
|
||||
<style> .gdarticle { background: initial;} </style>
|
||||
<style>
|
||||
body { background: #242525; }
|
||||
.gdarticle { background: initial;}
|
||||
</style>
|
||||
<script>
|
||||
// This function returns a promise, but it is synchroneous because it does not use await
|
||||
function fetchShim(src) {
|
||||
|
|
|
@ -9,34 +9,31 @@
|
|||
#include <QTimer>
|
||||
#include <QDialog>
|
||||
#include <QMainWindow>
|
||||
#include <QColor>
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <qt_windows.h>
|
||||
#endif
|
||||
|
||||
ArticleWebView::ArticleWebView( QWidget * parent, Config::Class * cfg ):
|
||||
ArticleWebView::ArticleWebView( QWidget *parent ):
|
||||
QWebEngineView( parent ),
|
||||
midButtonPressed( false ),
|
||||
selectionBySingleClick( false ),
|
||||
cfg(cfg)
|
||||
selectionBySingleClick( false )
|
||||
{
|
||||
auto *page = new ArticleWebPage( this );
|
||||
|
||||
if(cfg->preferences.darkReaderMode){
|
||||
page->setBackgroundColor(QColor(36,37,37));
|
||||
}
|
||||
|
||||
auto page = new ArticleWebPage( this );
|
||||
connect( page, &ArticleWebPage::linkClicked, this, &ArticleWebView::linkClicked );
|
||||
this->setPage( page );
|
||||
setZoomFactor(cfg->preferences.zoomFactor);
|
||||
|
||||
}
|
||||
|
||||
ArticleWebView::~ArticleWebView()
|
||||
{
|
||||
}
|
||||
|
||||
void ArticleWebView::setUp( Config::Class * cfg )
|
||||
{
|
||||
this->cfg = cfg;
|
||||
setZoomFactor(cfg->preferences.zoomFactor);
|
||||
}
|
||||
|
||||
QWebEngineView * ArticleWebView::createWindow( QWebEnginePage::WebWindowType type )
|
||||
{
|
||||
if(type==QWebEnginePage::WebWindowType::WebDialog)
|
||||
|
|
|
@ -22,8 +22,9 @@ class ArticleWebView: public QWebEngineView
|
|||
|
||||
public:
|
||||
|
||||
ArticleWebView( QWidget * parent, Config::Class * cfg);
|
||||
ArticleWebView( QWidget * parent );
|
||||
~ArticleWebView();
|
||||
void setUp( Config::Class * cfg );
|
||||
|
||||
bool isMidButtonPressed() const
|
||||
{ return midButtonPressed; }
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#endif
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QStackedWidget>
|
||||
|
||||
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MAC )
|
||||
#include "speechclient.hh"
|
||||
|
@ -251,45 +250,13 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
ftsPosition( 0 )
|
||||
{
|
||||
// setup GUI
|
||||
|
||||
webview = new ArticleWebView( this , const_cast< Config::Class * >( &cfg ) );
|
||||
webview = new ArticleWebView( this );
|
||||
ftsSearchPanel = new FtsSearchPanel( this );
|
||||
searchPanel = new SearchPanel( this );
|
||||
|
||||
auto * mainLayout = new QVBoxLayout( this );
|
||||
|
||||
// Special treatment of darkReaderMode
|
||||
// As of Qt6.4, the Qt WebEngine/Chromium's white loading color cannot be changed.
|
||||
// Here we cover the problem by swapping it out when the page is loading.
|
||||
|
||||
// if darkReaderMode not enabled, then just add webview normally.
|
||||
if( !cfg.preferences.darkReaderMode ) {
|
||||
mainLayout->addWidget( webview );
|
||||
}
|
||||
else {
|
||||
|
||||
auto * container = new QStackedWidget( this );
|
||||
auto * dummyBlack = new QWidget( this );
|
||||
dummyBlack->setStyleSheet( "background-color:#242525;" );
|
||||
container->setStyleSheet( "background-color:#242525;" );
|
||||
container->addWidget( webview );
|
||||
container->addWidget( dummyBlack );
|
||||
|
||||
connect( webview, &ArticleWebView::loadFinished, this, [ = ]() {
|
||||
// delay showing the webview because page rendering will show a glimpse of white
|
||||
QTimer::singleShot( 200, [ = ]() { container->setCurrentWidget( webview );});
|
||||
});
|
||||
|
||||
connect( webview, &ArticleWebView::loadStarted, this, [ = ]() {
|
||||
container->setCurrentWidget( dummyBlack );
|
||||
} );
|
||||
|
||||
mainLayout->addWidget( container );
|
||||
|
||||
container->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||
}
|
||||
|
||||
// Layout
|
||||
auto * mainLayout = new QVBoxLayout( this );
|
||||
mainLayout->addWidget( webview );
|
||||
mainLayout->addWidget( ftsSearchPanel );
|
||||
mainLayout->addWidget( searchPanel );
|
||||
|
||||
|
@ -313,6 +280,8 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
|
||||
//
|
||||
|
||||
webview->setUp( const_cast< Config::Class * >( &cfg ) );
|
||||
|
||||
goBackAction.setShortcut( QKeySequence( "Alt+Left" ) );
|
||||
webview->addAction( &goBackAction );
|
||||
connect( &goBackAction, &QAction::triggered, this, &ArticleView::back );
|
||||
|
|
Loading…
Reference in a new issue