refactor: convert articleview into plain code

This commit is contained in:
shenleban tongying 2023-03-17 05:42:44 -04:00 committed by xiaoyifang
parent fb6d4f9ccd
commit a75867f82b
7 changed files with 400 additions and 620 deletions

View file

@ -48,6 +48,7 @@ ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: false
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentAccessModifiers: false
IndentPPDirectives: BeforeHash
MaxEmptyLinesToKeep: 2
NamespaceIndentation: Inner

View file

@ -16,6 +16,7 @@ Checks: >
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer,
-google-default-arguments,
-misc-non-private-member-variables-in-classes,
-misc-const-correctness,

View file

@ -133,7 +133,6 @@ set(QRC_RESOURCES
set(UI_SRC
about.ui
articleview.ui
authentication.ui
chineseconversion.ui
dictgroupwidget.ui

File diff suppressed because it is too large Load diff

View file

@ -1,34 +1,39 @@
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef __ARTICLEVIEW_HH_INCLUDED__
#define __ARTICLEVIEW_HH_INCLUDED__
#ifndef GOLDENDICT_ARTICLEVIEW_HH
#define GOLDENDICT_ARTICLEVIEW_HH
#include <QWebEngineView>
#include <QAction>
#include <QCheckBox>
#include <QLabel>
#include <QMap>
#include <QUrl>
#include <QPushButton>
#include <QSet>
#include <QUrl>
#include <QWebEngineView>
#include <list>
#include "article_netmgr.hh"
#include "audioplayerinterface.hh"
#include "instances.hh"
#include "groupcombobox.hh"
#include "ui_articleview.h"
#include "globalbroadcaster.h"
#include "article_inspect.h"
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
#include <QtCore5Compat/QRegExp>
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
#include <QtCore5Compat/QRegExp>
#endif
#include "ankiconnector.h"
#include "webmultimediadownload.hh"
#include "base_type.h"
#include "articlewebview.hh"
class ResourceToSaveHandler;
class ArticleViewAgent ;
/// A widget with the web view tailored to view and handle articles -- it
/// uses the appropriate netmgr, handles link clicks, rmb clicks etc
class ArticleView: public QFrame
class ArticleView: public QWidget
{
Q_OBJECT
@ -38,9 +43,8 @@ class ArticleView: public QFrame
Instances::Groups const & groups;
bool popupView;
Config::Class const & cfg;
QWebChannel *channel;
QWebChannel * channel;
ArticleViewAgent * agent;
Ui::ArticleView ui;
AnkiConnector * ankiConnector;
@ -167,7 +171,25 @@ public:
void setDelayedHighlightText(QString const & text);
public slots:
private:
// widgets
ArticleWebView * webview;
QWidget * searchPanel;
QLineEdit * searchText;
QPushButton * searchCloseButton;
QPushButton * searchPrevious;
QPushButton * searchNext;
QCheckBox * highlightAllButton;
QCheckBox * searchCaseSensitive;
QWidget * ftsSearchPanel;
QLabel * ftsSearchStatusLabel;
QPushButton * ftsSearchPrevious;
QPushButton * ftsSearchNext;
public slots:
/// Goes back in history
void back();
@ -176,8 +198,7 @@ public slots:
void forward();
/// Takes the focus to the view
void focus()
{ ui.definition->setFocus( Qt::ShortcutFocusReason ); }
void focus() { webview->setFocus( Qt::ShortcutFocusReason ); }
public:
@ -192,11 +213,11 @@ public:
void setZoomFactor( qreal factor )
{
qreal existedFactor = ui.definition->zoomFactor();
if(!qFuzzyCompare(existedFactor,factor)){
qDebug()<<"zoom factor ,existed:"<<existedFactor<<"set:"<<factor;
ui.definition->setZoomFactor( factor );
//ui.definition->page()->setZoomFactor(factor);
qreal existedFactor = webview->zoomFactor();
if( !qFuzzyCompare( existedFactor, factor ) ) {
qDebug() << "zoom factor ,existed:" << existedFactor << "set:" << factor;
webview->setZoomFactor( factor );
//webview->page()->setZoomFactor(factor);
}
}
@ -275,7 +296,7 @@ signals:
/// typically in response to user actions
/// (clicking on the article or using shortcuts).
/// id - the dictionary id of the active article.
void activeArticleChanged ( ArticleView const *, QString const & id );
void activeArticleChanged( ArticleView const *, QString const & id );
/// Signal to add word to history even if history is disabled
void forceAddWordToHistory( const QString & word);
@ -418,7 +439,6 @@ private:
QStringList getMutedDictionaries(unsigned group);
protected:
// We need this to hide the search bar when we're showed
void showEvent( QShowEvent * );

View file

@ -1,258 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ArticleView</class>
<widget class="QWidget" name="ArticleView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<height>634</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1000,0,0">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ArticleWebView" name="definition" native="true">
<property name="url" stdset="0">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="ftsSearchFrame">
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QToolButton" name="ftsSearchPrevious">
<property name="text">
<string>&amp;Previous</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/previous.svg</normaloff>:/icons/previous.svg</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="ftsSearchNext">
<property name="text">
<string>&amp;Next</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/next.svg</normaloff>:/icons/next.svg</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ftsSearchStatusLabel"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="searchFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="searchText"/>
</item>
<item>
<widget class="QToolButton" name="searchCloseButton">
<property name="text">
<string>x</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/closetab.svg</normaloff>:/icons/closetab.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="searchPrevious">
<property name="text">
<string>&amp;Previous</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/previous.svg</normaloff>:/icons/previous.svg</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="searchNext">
<property name="text">
<string>&amp;Next</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/next.svg</normaloff>:/icons/next.svg</iconset>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="highlightAllButton">
<property name="text">
<string>Highlight &amp;all</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/highlighter.png</normaloff>:/icons/highlighter.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="searchCaseSensitive">
<property name="text">
<string>&amp;Case Sensitive</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>782</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ArticleWebView</class>
<extends>QWidget</extends>
<header>articlewebview.hh</header>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -412,7 +412,6 @@ FORMS += groups.ui \
sources.ui \
initializing.ui \
scanpopup.ui \
articleview.ui \
preferences.ui \
about.ui \
editdictionaries.ui \