Libksieve

sieveeditorhelphtmlwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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 <TextAddonsWidgets/SlideContainer>
14
15#include "findbar/findbarwebengineview.h"
16
17using namespace KSieveUi;
18namespace
19{
20qreal zoomBy()
21{
22 return 20;
23}
24}
25SieveEditorHelpHtmlWidget::SieveEditorHelpHtmlWidget(QWidget *parent)
26 : QWidget(parent)
27{
28 auto lay = new QVBoxLayout(this);
29 lay->setContentsMargins({});
30 mProgressIndicator = new SieveEditorLoadProgressIndicator(this);
31 mProgressIndicator->setObjectName(QLatin1StringView("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(QLatin1StringView("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 TextAddonsWidgets::SlideContainer(this);
44 mSliderContainer->setObjectName(QLatin1StringView("slidercontainer"));
45 lay->addWidget(mSliderContainer);
46 mFindBar = new KSieveUi::FindBarWebEngineView(mWebView, this);
47 mFindBar->setObjectName(QLatin1StringView("findbar"));
48 connect(mFindBar, &KSieveUi::FindBarWebEngineView::hideFindBar, mSliderContainer, &TextAddonsWidgets::SlideContainer::slideOut);
49 mSliderContainer->setContent(mFindBar);
50}
51
52SieveEditorHelpHtmlWidget::~SieveEditorHelpHtmlWidget() = default;
53
54QString SieveEditorHelpHtmlWidget::title() const
55{
56 return mTitle;
57}
58
59void SieveEditorHelpHtmlWidget::slotLoadFinished(bool success)
60{
61 Q_EMIT loadFinished(this, success);
62}
63
64QUrl SieveEditorHelpHtmlWidget::currentUrl() const
65{
66 return mWebView->url();
67}
68
69void SieveEditorHelpHtmlWidget::slotPixmapChanged(const QPixmap &pixmap)
70{
71 Q_EMIT progressIndicatorPixmapChanged(this, pixmap);
72}
73
74void SieveEditorHelpHtmlWidget::slotFinished(bool b)
75{
76 mProgressIndicator->stopAnimation(b);
77}
78
79void SieveEditorHelpHtmlWidget::slotLoadStarted()
80{
81 mProgressIndicator->startAnimation();
82}
83
84void SieveEditorHelpHtmlWidget::slotTitleChanged(const QString &title)
85{
86 if (mTitle != title) {
87 mTitle = title;
88 Q_EMIT titleChanged(this, title);
89 }
90}
91
92void SieveEditorHelpHtmlWidget::openUrl(const QUrl &url)
93{
94 mWebView->setUrl(url);
95}
96
97void SieveEditorHelpHtmlWidget::zoomIn()
98{
99 if (mZoomFactor >= 300) {
100 return;
101 }
102 mZoomFactor += zoomBy();
103 if (mZoomFactor > 300) {
104 mZoomFactor = 300;
105 }
106 mWebView->setZoomFactor(mZoomFactor / 100.0);
107}
108
109void SieveEditorHelpHtmlWidget::copy()
110{
111 mWebView->triggerPageAction(QWebEnginePage::Copy);
112}
113
114bool SieveEditorHelpHtmlWidget::hasSelection() const
115{
116 return mWebView->hasSelection();
117}
118
119void SieveEditorHelpHtmlWidget::selectAll()
120{
121 mWebView->triggerPageAction(QWebEnginePage::SelectAll);
122}
123
124void SieveEditorHelpHtmlWidget::zoomOut()
125{
126 if (mZoomFactor <= 10) {
127 return;
128 }
129 mZoomFactor -= zoomBy();
130 if (mZoomFactor < 10) {
131 mZoomFactor = 10;
132 }
133 mWebView->setZoomFactor(mZoomFactor / 100.0);
134}
135
136void SieveEditorHelpHtmlWidget::resetZoom()
137{
138 mZoomFactor = 100;
139 mWebView->setZoomFactor(1.0);
140}
141
142void SieveEditorHelpHtmlWidget::slotSelectionChanged()
143{
144 Q_EMIT copyAvailable(mWebView->hasSelection());
145}
146
147void SieveEditorHelpHtmlWidget::find()
148{
149 if (mWebView->hasSelection()) {
150 mFindBar->setText(mWebView->selectedText());
151 }
152 mSliderContainer->slideIn();
153 mFindBar->focusAndSetCursor();
154}
155
156#include "moc_sieveeditorhelphtmlwidget.cpp"
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.