Libksieve

sieveeditorhelphtmlwidget.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #include "sieveeditorhelphtmlwidget.h"
20 #include "sieveeditorloadprogressindicator.h"
21 
22 #include "sieveeditorwebengineview.h"
23 
24 #include <QVBoxLayout>
25 
26 #include <KPIMTextEdit/SlideContainer>
27 
28 #include "findbar/findbarwebengineview.h"
29 
30 using namespace KSieveUi;
31 namespace {
32 qreal zoomBy()
33 {
34  return 20;
35 }
36 }
37 SieveEditorHelpHtmlWidget::SieveEditorHelpHtmlWidget(QWidget *parent)
38  : QWidget(parent)
39  , mZoomFactor(100)
40 {
41  QVBoxLayout *lay = new QVBoxLayout(this);
42  lay->setContentsMargins(0, 0, 0, 0);
43  mProgressIndicator = new SieveEditorLoadProgressIndicator(this);
44  mProgressIndicator->setObjectName(QStringLiteral("progressindicator"));
45  connect(mProgressIndicator, &SieveEditorLoadProgressIndicator::pixmapChanged, this, &SieveEditorHelpHtmlWidget::slotPixmapChanged);
46  connect(mProgressIndicator, &SieveEditorLoadProgressIndicator::loadFinished, this, &SieveEditorHelpHtmlWidget::slotLoadFinished);
47 
48  mWebView = new SieveEditorWebEngineView(this);
49  mWebView->setObjectName(QStringLiteral("webview"));
50  connect(mWebView, &SieveEditorWebEngineView::titleChanged, this, &SieveEditorHelpHtmlWidget::slotTitleChanged);
51  connect(mWebView, &SieveEditorWebEngineView::loadStarted, this, &SieveEditorHelpHtmlWidget::slotLoadStarted);
52  connect(mWebView, &SieveEditorWebEngineView::loadFinished, this, &SieveEditorHelpHtmlWidget::slotFinished);
53  connect(mWebView, &SieveEditorWebEngineView::selectionChanged, this, &SieveEditorHelpHtmlWidget::slotSelectionChanged);
54  lay->addWidget(mWebView);
55 
56  mSliderContainer = new KPIMTextEdit::SlideContainer(this);
57  mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
58  lay->addWidget(mSliderContainer);
59  mFindBar = new KSieveUi::FindBarWebEngineView(mWebView, this);
60  mFindBar->setObjectName(QStringLiteral("findbar"));
61  connect(mFindBar, &KSieveUi::FindBarWebEngineView::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
62  mSliderContainer->setContent(mFindBar);
63 }
64 
65 SieveEditorHelpHtmlWidget::~SieveEditorHelpHtmlWidget()
66 {
67 }
68 
69 QString SieveEditorHelpHtmlWidget::title() const
70 {
71  return mTitle;
72 }
73 
74 void SieveEditorHelpHtmlWidget::slotLoadFinished(bool success)
75 {
76  Q_EMIT loadFinished(this, success);
77 }
78 
79 QUrl SieveEditorHelpHtmlWidget::currentUrl() const
80 {
81  return mWebView->url();
82 }
83 
84 void SieveEditorHelpHtmlWidget::slotPixmapChanged(const QPixmap &pixmap)
85 {
86  Q_EMIT progressIndicatorPixmapChanged(this, pixmap);
87 }
88 
89 void SieveEditorHelpHtmlWidget::slotFinished(bool b)
90 {
91  mProgressIndicator->stopAnimation(b);
92 }
93 
94 void SieveEditorHelpHtmlWidget::slotLoadStarted()
95 {
96  mProgressIndicator->startAnimation();
97 }
98 
99 void SieveEditorHelpHtmlWidget::slotTitleChanged(const QString &title)
100 {
101  if (mTitle != title) {
102  mTitle = title;
103  Q_EMIT titleChanged(this, title);
104  }
105 }
106 
107 void SieveEditorHelpHtmlWidget::openUrl(const QUrl &url)
108 {
109  mWebView->setUrl(url);
110 }
111 
112 void SieveEditorHelpHtmlWidget::zoomIn()
113 {
114  if (mZoomFactor >= 300) {
115  return;
116  }
117  mZoomFactor += zoomBy();
118  if (mZoomFactor > 300) {
119  mZoomFactor = 300;
120  }
121  mWebView->setZoomFactor(mZoomFactor / 100.0);
122 }
123 
124 void SieveEditorHelpHtmlWidget::copy()
125 {
126  mWebView->triggerPageAction(QWebEnginePage::Copy);
127 }
128 
129 bool SieveEditorHelpHtmlWidget::hasSelection() const
130 {
131  return mWebView->hasSelection();
132 }
133 
134 void SieveEditorHelpHtmlWidget::selectAll()
135 {
136  mWebView->triggerPageAction(QWebEnginePage::SelectAll);
137 }
138 
139 void SieveEditorHelpHtmlWidget::zoomOut()
140 {
141  if (mZoomFactor <= 10) {
142  return;
143  }
144  mZoomFactor -= zoomBy();
145  if (mZoomFactor < 10) {
146  mZoomFactor = 10;
147  }
148  mWebView->setZoomFactor(mZoomFactor / 100.0);
149 }
150 
151 void SieveEditorHelpHtmlWidget::resetZoom()
152 {
153  mZoomFactor = 100;
154  mWebView->setZoomFactor(1.0);
155 }
156 
157 void SieveEditorHelpHtmlWidget::slotSelectionChanged()
158 {
159  Q_EMIT copyAvailable(mWebView->hasSelection());
160 }
161 
162 void SieveEditorHelpHtmlWidget::find()
163 {
164  if (mWebView->hasSelection()) {
165  mFindBar->setText(mWebView->selectedText());
166  }
167  mSliderContainer->slideIn();
168  mFindBar->focusAndSetCursor();
169 }
QString url(QUrl::FormattingOptions options) const const
void setContentsMargins(int left, int top, int right, int bottom)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
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-2020 The KDE developers.
Generated on Tue Jul 14 2020 23:08:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.