Marble

MarbleWebView.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
4//
5
6#include "MarbleWebView.h"
7#include <QApplication>
8#include <QClipboard>
9#include <QContextMenuEvent>
10#include <QKeyEvent>
11#include <QMenu>
12
13MarbleWebView::MarbleWebView(QWidget *parent)
14 : QWebEngineView(parent)
15 , m_contextMenu(new QMenu(this))
16 , m_copyAction(new QAction(this))
17{
18 m_copyAction->setText(tr("Copy"));
19 m_copyAction->setIcon(QIcon(QStringLiteral(":/icons/edit-copy.png")));
20 m_copyAction->setIconVisibleInMenu(true);
21 m_copyAction->setToolTip(tr("Copy selected content"));
22 connect(m_copyAction, &QAction::triggered, this, &MarbleWebView::copySelectedText);
23 m_contextMenu->addAction(m_copyAction);
24 setContextMenuPolicy(Qt::DefaultContextMenu);
25}
26
27void MarbleWebView::contextMenuEvent(QContextMenuEvent *)
28{
29 m_copyAction->setEnabled(!selectedText().isEmpty());
30 m_contextMenu->exec(QCursor::pos());
31}
32
33void MarbleWebView::copySelectedText()
34{
35 const QString text = selectedText();
36 if (!text.isEmpty()) {
38 clipboard->setText(text);
39 }
40}
41
42void MarbleWebView::keyPressEvent(QKeyEvent *event)
43{
44 if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_C) {
45 copySelectedText();
46 return;
47 }
48
49 QWebEngineView::keyPressEvent(event);
50}
51
52#include "moc_MarbleWebView.cpp"
void setEnabled(bool)
void triggered(bool checked)
void setText(const QString &text, Mode mode)
QPoint pos()
QClipboard * clipboard()
QAction * exec()
bool isEmpty() const const
DefaultContextMenu
ControlModifier
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.