Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Application/THP/thpwidgets/thp_html_widget.cpp
T
torstenandCopilot 09c244ff18 refactor: clean up verbose migration comments
Remove redundant Qt6 migration comments that restate obvious API changes:
- QtConcurrent::run parameter order explanations (preserved where lambda wrapping needed)
- QStringRef/QStringView API changes (shortened to essential info)
- QComboBox::activated signal signature change
- QMap::unite() removal semantics
- QAction include path change
- QMouseEvent/QWheelEvent position() API
- QList/QVector equivalence in Qt6
- QFuture continuation API
- Code generation comments

Preserved comments explaining non-obvious Qt6 behavior or necessary
API migration details.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-04 12:05:23 +00:00

140 lines
3.3 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Handle HTML output for thp
* $Id$
* $HeadURL$
* $Author$
*/
#include "thp_html_widget.h"
#include "ui_thp_html_widget.h"
#include <QUrl>
#include <QWebEnginePage>
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace THP
{
class MyQWebEnginePage : public QWebEnginePage
{
Q_OBJECT
public:
explicit MyQWebEnginePage(NGL::INGLLogger &logger, QObject *parent = nullptr)
: QWebEnginePage(parent)
, m_logger(logger)
{}
MyQWebEnginePage(NGL::INGLLogger &logger, QWebEngineProfile *profile, QObject *parent = nullptr)
: QWebEnginePage(profile, parent)
, m_logger(logger)
{}
bool needsToBeOpenedExternally(const QUrl &url)
{
const QString lpath = url.toString();
const QStringView ext = QStringView{lpath}.split(QLatin1Char('.')).last();
const QStringView ext2Chars = ext.left(2);
if (ext == QLatin1String("html") &&
QStringView{lpath}.mid(lpath.lastIndexOf(QLatin1Char('/')) + 1).startsWith(QLatin1String("combined_")))
return true;
// PDF
if (ext == QLatin1String("pdf"))
return true;
// A/V playlist
if (ext == QLatin1String("pls"))
return true;
// Situation
if (ext == QLatin1String("json"))
return true;
// Word/Excel/PowerPoint
if (ext2Chars == QLatin1String("do") ||
ext2Chars == QLatin1String("xl") ||
ext2Chars == QLatin1String("pp"))
return true;
return false;
}
bool acceptNavigationRequest(const QUrl &url,
QWebEnginePage::NavigationType type,
bool isMainFrame) override
{
Q_UNUSED(isMainFrame)
if (type == QWebEnginePage::NavigationTypeLinkClicked)
{
if (needsToBeOpenedExternally(url))
{
emit linkClicked(url);
DEBUG_LOG(m_logger) << "acceptNavigationRequest denied for " << url.toString();
return false;
}
}
DEBUG_LOG(m_logger) << "acceptNavigationRequest allowed for " << url.toString();
return true;
}
Q_SIGNALS:
void linkClicked(const QUrl &url);
private:
NGL::INGLLogger &m_logger;
};
HtmlWidget::HtmlWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::HtmlWidget)
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("THP.HtmlWidget"))
{
ui->setupUi(this);
auto webEnginePage = new MyQWebEnginePage(m_logger, this);
ui->html->setPage(webEnginePage);
connect(webEnginePage, &MyQWebEnginePage::linkClicked, this, &HtmlWidget::linkClicked);
connect(ui->html, &QWebEngineView::loadFinished, this, &HtmlWidget::loadFinished);
connect(ui->html, &QWebEngineView::urlChanged, this, &HtmlWidget::urlChanged);
connect(ui->html, &QWebEngineView::titleChanged, this, &HtmlWidget::titleChanged);
}
HtmlWidget::~HtmlWidget()
{
delete ui;
}
void HtmlWidget::back()
{
ui->html->back();
}
QString HtmlWidget::title() const
{
return ui->html->title();
}
QUrl HtmlWidget::url() const
{
return ui->html->url();
}
bool HtmlWidget::showHTML(const QUrl &url)
{
if (!url.isValid())
{
WARNING_LOG(m_logger) << "Invalid url: " << url.toString();
return false;
}
ui->html->load(url);
return true;
}
void HtmlWidget::setZoomFactor(double newZoomFactor)
{
ui->html->setZoomFactor(newZoomFactor);
}
void HtmlWidget::print(QPrinter *printer) const
{
ui->html->page()->print(printer, [](bool) {});
}
} // namespace THP
#include "thp_html_widget.moc"