File indexing completed on 2024-11-10 04:55:56

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include <QClipboard>
0010 #include <QGuiApplication>
0011 #include <QPainter>
0012 #include <QRasterWindow>
0013 #include <QTimer>
0014 
0015 class Window : public QRasterWindow
0016 {
0017     Q_OBJECT
0018 public:
0019     explicit Window();
0020     ~Window() override;
0021 
0022 protected:
0023     void paintEvent(QPaintEvent *event) override;
0024     void focusInEvent(QFocusEvent *event) override;
0025 };
0026 
0027 Window::Window()
0028     : QRasterWindow()
0029 {
0030 }
0031 
0032 Window::~Window() = default;
0033 
0034 void Window::paintEvent(QPaintEvent *event)
0035 {
0036     QPainter p(this);
0037     p.fillRect(0, 0, width(), height(), Qt::red);
0038 }
0039 
0040 void Window::focusInEvent(QFocusEvent *event)
0041 {
0042     QRasterWindow::focusInEvent(event);
0043     // TODO: make it work without singleshot
0044     QTimer::singleShot(100, [] {
0045         qApp->clipboard()->setText(QStringLiteral("test"));
0046     });
0047 }
0048 
0049 int main(int argc, char *argv[])
0050 {
0051     QGuiApplication app(argc, argv);
0052     std::unique_ptr<Window> w(new Window);
0053     w->setGeometry(QRect(0, 0, 100, 200));
0054     w->show();
0055 
0056     return app.exec();
0057 }
0058 
0059 #include "copy.moc"