bit of refactoring

This commit is contained in:
Martin Rotter 2022-04-04 12:04:41 +02:00
parent 0bb4d62545
commit 82bde2d087
9 changed files with 32 additions and 62 deletions

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" />
<releases>
<release version="4.2.1" date="2022-04-01"/>
<release version="4.2.1" date="2022-04-04"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -91,13 +91,7 @@ void WebBrowser::setHtml(const QString& html, const QUrl& base_url) {
m_webView->setHtml(html, base_url);
}
WebBrowser::~WebBrowser() {
//m_toolBar->removeAction(m_txtLocationAction);
//m_toolBar->removeAction(m_btnDiscoverFeedsAction);
// Delete members. Do not use scoped pointers here.
//delete m_layout;
}
WebBrowser::~WebBrowser() {}
double WebBrowser::verticalScrollBarPosition() const {
return m_webView->verticalScrollBarPosition();
@ -284,9 +278,9 @@ void WebBrowser::initializeLayout() {
m_actionOpenInSystemBrowser->setEnabled(false);
m_actionReadabilePage->setEnabled(false);
m_btnDiscoverFeedsAction->setDefaultWidget(new QWidget(this));
//m_btnDiscoverFeedsAction->setDefaultWidget(new QWidget(this));
//m_btnDiscoverFeedsAction->setDefaultWidget(m_btnDiscoverFeeds);
m_btnDiscoverFeedsAction->setDefaultWidget(m_btnDiscoverFeeds);
// Add needed actions into toolbar.
m_toolBar->addAction(m_actionBack);
@ -296,8 +290,8 @@ void WebBrowser::initializeLayout() {
m_toolBar->addAction(m_actionOpenInSystemBrowser);
m_toolBar->addAction(m_actionReadabilePage);
//m_toolBar->addAction(m_btnDiscoverFeedsAction);
//m_txtLocationAction = m_toolBar->addWidget(m_txtLocation);
m_toolBar->addAction(m_btnDiscoverFeedsAction);
m_txtLocationAction = m_toolBar->addWidget(m_txtLocation);
m_loadingProgress = new QProgressBar(this);
m_loadingProgress->setFixedHeight(10);

View File

@ -150,29 +150,13 @@ void LiteHtmlViewer::applyFont(const QFont& fon) {
QLiteHtmlWidget::setDefaultFont(fon);
}
bool LiteHtmlViewer::canZoomIn() const {
return zoomFactor() <= double(MAX_ZOOM_FACTOR) - double(ZOOM_FACTOR_STEP);
}
bool LiteHtmlViewer::canZoomOut() const {
return zoomFactor() >= double(MIN_ZOOM_FACTOR) + double(ZOOM_FACTOR_STEP);
}
qreal LiteHtmlViewer::zoomFactor() const {
return QLiteHtmlWidget::zoomFactor();
}
void LiteHtmlViewer::zoomIn() {
setZoomFactor(zoomFactor() + double(ZOOM_FACTOR_STEP));
}
void LiteHtmlViewer::zoomOut() {
setZoomFactor(zoomFactor() - double(ZOOM_FACTOR_STEP));
}
void LiteHtmlViewer::setZoomFactor(qreal zoom_factor) {
if (zoom_factor == 0.0) {
QLiteHtmlWidget::setZoomFactor(0.1);
QLiteHtmlWidget::setZoomFactor(MIN_ZOOM_FACTOR);
}
else {
QLiteHtmlWidget::setZoomFactor(zoom_factor);

View File

@ -30,11 +30,7 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
virtual double verticalScrollBarPosition() const;
virtual void setVerticalScrollBarPosition(double pos);
virtual void applyFont(const QFont& fon);
virtual bool canZoomIn() const;
virtual bool canZoomOut() const;
virtual qreal zoomFactor() const;
virtual void zoomIn();
virtual void zoomOut();
virtual void setZoomFactor(qreal zoom_factor);
private slots:

View File

@ -221,26 +221,10 @@ void WebEngineViewer::applyFont(const QFont& fon) {
QWebEngineProfile::defaultProfile()->settings()->setFontSize(QWebEngineSettings::DefaultFontSize, pixel_size);
}
bool WebEngineViewer::canZoomIn() const {
return zoomFactor() <= double(MAX_ZOOM_FACTOR) - double(ZOOM_FACTOR_STEP);
}
bool WebEngineViewer::canZoomOut() const {
return zoomFactor() >= double(MIN_ZOOM_FACTOR) + double(ZOOM_FACTOR_STEP);
}
qreal WebEngineViewer::zoomFactor() const {
return QWebEngineView::zoomFactor();
}
void WebEngineViewer::zoomIn() {
setZoomFactor(zoomFactor() + double(ZOOM_FACTOR_STEP));
}
void WebEngineViewer::zoomOut() {
setZoomFactor(zoomFactor() - double(ZOOM_FACTOR_STEP));
}
void WebEngineViewer::setZoomFactor(qreal zoom_factor) {
QWebEngineView::setZoomFactor(zoom_factor);
}

View File

@ -32,11 +32,7 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
virtual double verticalScrollBarPosition() const;
virtual void setVerticalScrollBarPosition(double pos);
virtual void applyFont(const QFont& fon);
virtual bool canZoomIn() const;
virtual bool canZoomOut() const;
virtual qreal zoomFactor() const;
virtual void zoomIn();
virtual void zoomOut();
virtual void setZoomFactor(qreal zoom_factor);
virtual QString html() const;
virtual QUrl url() const;

View File

@ -51,14 +51,30 @@ class WebViewer {
virtual void applyFont(const QFont& fon) = 0;
// Zooming.
virtual bool canZoomIn() const = 0;
virtual bool canZoomOut() const = 0;
virtual void zoomIn() = 0;
virtual void zoomOut() = 0;
virtual bool canZoomIn() const;
virtual bool canZoomOut() const;
virtual void zoomIn();
virtual void zoomOut();
virtual qreal zoomFactor() const = 0;
virtual void setZoomFactor(qreal zoom_factor) = 0;
};
inline WebViewer::~WebViewer() {}
inline void WebViewer::zoomIn() {
setZoomFactor(zoomFactor() + double(ZOOM_FACTOR_STEP));
}
inline void WebViewer::zoomOut() {
setZoomFactor(zoomFactor() - double(ZOOM_FACTOR_STEP));
}
inline bool WebViewer::canZoomIn() const {
return zoomFactor() <= double(MAX_ZOOM_FACTOR) - double(ZOOM_FACTOR_STEP);
}
inline bool WebViewer::canZoomOut() const {
return zoomFactor() >= double(MIN_ZOOM_FACTOR) + double(ZOOM_FACTOR_STEP);
}
#endif // WEBVIEWER_H

View File

@ -26,9 +26,9 @@ GmailServiceRoot::GmailServiceRoot(RootItem* parent)
}
GmailServiceRoot::~GmailServiceRoot() {
/*if (!m_emailPreview.isNull()) {
m_emailPreview->deleteLater();
}*/
if (!m_emailPreview.isNull()) {
m_emailPreview->deleteLater();
}
}
void GmailServiceRoot::updateTitle() {
@ -106,7 +106,7 @@ bool GmailServiceRoot::wantsBaggedIdsOfExistingMessages() const {
CustomMessagePreviewer* GmailServiceRoot::customMessagePreviewer() {
if (m_emailPreview.isNull()) {
m_emailPreview.reset(new EmailPreviewer());
m_emailPreview = new EmailPreviewer();
}
return m_emailPreview.data();

View File

@ -50,7 +50,7 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot {
void updateTitle();
private:
QScopedPointer<EmailPreviewer> m_emailPreview;
QPointer<EmailPreviewer> m_emailPreview;
GmailNetworkFactory* m_network;
QAction* m_actionReply;
Message m_replyToMessage;