KWin
Loading...
Searching...
No Matches
copy.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include <QClipboard>
10#include <QGuiApplication>
11#include <QPainter>
12#include <QRasterWindow>
13#include <QTimer>
14
15class Window : public QRasterWindow
16{
17 Q_OBJECT
18public:
19 explicit Window();
20 ~Window() override;
21
22protected:
23 void paintEvent(QPaintEvent *event) override;
24 void focusInEvent(QFocusEvent *event) override;
25};
26
28 : QRasterWindow()
29{
30}
31
32Window::~Window() = default;
33
34void Window::paintEvent(QPaintEvent *event)
35{
36 QPainter p(this);
37 p.fillRect(0, 0, width(), height(), Qt::red);
38}
39
40void Window::focusInEvent(QFocusEvent *event)
41{
42 QRasterWindow::focusInEvent(event);
43 // TODO: make it work without singleshot
44 QTimer::singleShot(100, [] {
45 qApp->clipboard()->setText(QStringLiteral("test"));
46 });
47}
48
49int main(int argc, char *argv[])
50{
51 QGuiApplication app(argc, argv);
52 std::unique_ptr<Window> w(new Window);
53 w->setGeometry(QRect(0, 0, 100, 200));
54 w->show();
55
56 return app.exec();
57}
58
59#include "copy.moc"
~Window() override
Window()
Definition copy.cpp:27
void focusInEvent(QFocusEvent *event) override
Definition copy.cpp:40
void paintEvent(QPaintEvent *event) override
Definition copy.cpp:34