Libksieve

sieveeditorhelphtmlwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "sieveeditorhelphtmlwidget.h"
7 #include "sieveeditorloadprogressindicator.h"
8 
9 #include "sieveeditorwebengineview.h"
10 
11 #include <QVBoxLayout>
12 
13 #include <KPIMTextEdit/SlideContainer>
14 
15 #include "findbar/findbarwebengineview.h"
16 
17 using namespace KSieveUi;
18 namespace
19 {
20 qreal zoomBy()
21 {
22  return 20;
23 }
24 }
25 SieveEditorHelpHtmlWidget::SieveEditorHelpHtmlWidget(QWidget *parent)
26  : QWidget(parent)
27 {
28  auto lay = new QVBoxLayout(this);
29  lay->setContentsMargins({});
30  mProgressIndicator = new SieveEditorLoadProgressIndicator(this);
31  mProgressIndicator->setObjectName(QStringLiteral("progressindicator"));
32  connect(mProgressIndicator, &SieveEditorLoadProgressIndicator::pixmapChanged, this, &SieveEditorHelpHtmlWidget::slotPixmapChanged);
33  connect(mProgressIndicator, &SieveEditorLoadProgressIndicator::loadFinished, this, &SieveEditorHelpHtmlWidget::slotLoadFinished);
34 
35  mWebView = new SieveEditorWebEngineView(this);
36  mWebView->setObjectName(QStringLiteral("webview"));
37  connect(mWebView, &SieveEditorWebEngineView::titleChanged, this, &SieveEditorHelpHtmlWidget::slotTitleChanged);
38  connect(mWebView, &SieveEditorWebEngineView::loadStarted, this, &SieveEditorHelpHtmlWidget::slotLoadStarted);
39  connect(mWebView, &SieveEditorWebEngineView::loadFinished, this, &SieveEditorHelpHtmlWidget::slotFinished);
40  connect(mWebView, &SieveEditorWebEngineView::selectionChanged, this, &SieveEditorHelpHtmlWidget::slotSelectionChanged);
41  lay->addWidget(mWebView);
42 
43  mSliderContainer = new KPIMTextEdit::SlideContainer(this);
44  mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
45  lay->addWidget(mSliderContainer);
46  mFindBar = new KSieveUi::FindBarWebEngineView(mWebView, this);
47  mFindBar->setObjectName(QStringLiteral("findbar"));
48  connect(mFindBar, &KSieveUi::FindBarWebEngineView::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
49  mSliderContainer->setContent(mFindBar);
50 }
51 
52 SieveEditorHelpHtmlWidget::~SieveEditorHelpHtmlWidget()
53 {
54 }
55 
56 QString SieveEditorHelpHtmlWidget::title() const
57 {
58  return mTitle;
59 }
60 
61 void SieveEditorHelpHtmlWidget::slotLoadFinished(bool success)
62 {
63  Q_EMIT loadFinished(this, success);
64 }
65 
66 QUrl SieveEditorHelpHtmlWidget::currentUrl() const
67 {
68  return mWebView->url();
69 }
70 
71 void SieveEditorHelpHtmlWidget::slotPixmapChanged(const QPixmap &pixmap)
72 {
73  Q_EMIT progressIndicatorPixmapChanged(this, pixmap);
74 }
75 
76 void SieveEditorHelpHtmlWidget::slotFinished(bool b)
77 {
78  mProgressIndicator->stopAnimation(b);
79 }
80 
81 void SieveEditorHelpHtmlWidget::slotLoadStarted()
82 {
83  mProgressIndicator->startAnimation();
84 }
85 
86 void SieveEditorHelpHtmlWidget::slotTitleChanged(const QString &title)
87 {
88  if (mTitle != title) {
89  mTitle = title;
90  Q_EMIT titleChanged(this, title);
91  }
92 }
93 
94 void SieveEditorHelpHtmlWidget::openUrl(const QUrl &url)
95 {
96  mWebView->setUrl(url);
97 }
98 
99 void SieveEditorHelpHtmlWidget::zoomIn()
100 {
101  if (mZoomFactor >= 300) {
102  return;
103  }
104  mZoomFactor += zoomBy();
105  if (mZoomFactor > 300) {
106  mZoomFactor = 300;
107  }
108  mWebView->setZoomFactor(mZoomFactor / 100.0);
109 }
110 
111 void SieveEditorHelpHtmlWidget::copy()
112 {
113  mWebView->triggerPageAction(QWebEnginePage::Copy);
114 }
115 
116 bool SieveEditorHelpHtmlWidget::hasSelection() const
117 {
118  return mWebView->hasSelection();
119 }
120 
121 void SieveEditorHelpHtmlWidget::selectAll()
122 {
123  mWebView->triggerPageAction(QWebEnginePage::SelectAll);
124 }
125 
126 void SieveEditorHelpHtmlWidget::zoomOut()
127 {
128  if (mZoomFactor <= 10) {
129  return;
130  }
131  mZoomFactor -= zoomBy();
132  if (mZoomFactor < 10) {
133  mZoomFactor = 10;
134  }
135  mWebView->setZoomFactor(mZoomFactor / 100.0);
136 }
137 
138 void SieveEditorHelpHtmlWidget::resetZoom()
139 {
140  mZoomFactor = 100;
141  mWebView->setZoomFactor(1.0);
142 }
143 
144 void SieveEditorHelpHtmlWidget::slotSelectionChanged()
145 {
146  Q_EMIT copyAvailable(mWebView->hasSelection());
147 }
148 
149 void SieveEditorHelpHtmlWidget::find()
150 {
151  if (mWebView->hasSelection()) {
152  mFindBar->setText(mWebView->selectedText());
153  }
154  mSliderContainer->slideIn();
155  mFindBar->focusAndSetCursor();
156 }
QString url(QUrl::FormattingOptions options) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.