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 <QMenu>
9#include <QContextMenuEvent>
10#include <QKeyEvent>
11#include <QClipboard>
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, SIGNAL(triggered()),
23 this, SLOT(copySelectedText()));
24 m_contextMenu->addAction(m_copyAction);
25 setContextMenuPolicy(Qt::DefaultContextMenu);
26}
27
28void MarbleWebView::contextMenuEvent(QContextMenuEvent *event)
29{
30 m_copyAction->setEnabled(!selectedText().isEmpty());
31 m_contextMenu->exec(event->globalPos());
32}
33
34void MarbleWebView::copySelectedText()
35{
36 const QString text = selectedText();
37 if (!text.isEmpty()) {
39 clipboard->setText(text);
40 }
41}
42
43void MarbleWebView::keyPressEvent(QKeyEvent *event)
44{
45 if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_C) {
46 copySelectedText();
47 return;
48 }
49
50 QWebEngineView::keyPressEvent(event);
51}
52
53#include "moc_MarbleWebView.cpp"
void setEnabled(bool)
void setText(const QString &text, Mode mode)
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 Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.