diff options
Diffstat (limited to 'tests/manual/xembed')
-rw-r--r-- | tests/manual/xembed/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tests/manual/xembed/gtk-container/CMakeLists.txt | 24 | ||||
-rw-r--r-- | tests/manual/xembed/gtk-container/gtk-container.cpp | 43 | ||||
-rw-r--r-- | tests/manual/xembed/gtk-container/gtk-container.pro | 16 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-raster/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-raster/main.cpp | 29 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-raster/qt-client-raster.pro | 9 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-raster/rasterwindow.cpp | 72 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-raster/rasterwindow.h | 32 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-widget/CMakeLists.txt | 16 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-widget/main.cpp | 32 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-widget/qt-client-widget.pro | 9 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-widget/window.cpp | 206 | ||||
-rw-r--r-- | tests/manual/xembed/qt-client-widget/window.h | 38 | ||||
-rw-r--r-- | tests/manual/xembed/xembed.pro | 11 |
15 files changed, 560 insertions, 0 deletions
diff --git a/tests/manual/xembed/CMakeLists.txt b/tests/manual/xembed/CMakeLists.txt new file mode 100644 index 0000000000..44bb2ea818 --- /dev/null +++ b/tests/manual/xembed/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(QT_FEATURE_gtk3) + add_subdirectory(gtk-container) +endif() +add_subdirectory(qt-client-raster) +add_subdirectory(qt-client-widget) diff --git a/tests/manual/xembed/gtk-container/CMakeLists.txt b/tests/manual/xembed/gtk-container/CMakeLists.txt new file mode 100644 index 0000000000..34a802c142 --- /dev/null +++ b/tests/manual/xembed/gtk-container/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_find_package(GTK3) +qt_find_package(X11) + +##################################################################### +## gtk-container Binary: +##################################################################### + +qt_internal_add_manual_test(gtk-container + GUI + SOURCES + gtk-container.cpp + DEFINES + GDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_6 + LIBRARIES + PkgConfig::GTK3 + Qt::Core + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + X11::X11 +) diff --git a/tests/manual/xembed/gtk-container/gtk-container.cpp b/tests/manual/xembed/gtk-container/gtk-container.cpp new file mode 100644 index 0000000000..2ecbe10545 --- /dev/null +++ b/tests/manual/xembed/gtk-container/gtk-container.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <gtk/gtk.h> +#include <gtk/gtkx.h> + +gchar *cmd; + +void launch_app(GtkButton */* btn */, guint32 *id) +{ + gchar *command = g_strdup_printf("%s %u", cmd, *id); + g_spawn_command_line_async(command, NULL); +} + +gint main(gint argc, gchar **argv) +{ + if (argc <=1 || argc > 2) { + g_print("No client application defined.\n"); + return 0; + } + + cmd = g_strdup_printf("%s", argv[1]); + + gtk_init(&argc, &argv); + + GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + GtkWidget *sock = gtk_socket_new(); + GtkWidget *btn = gtk_button_new_with_label("Hello, World!"); + g_signal_connect(sock, "plug-removed", gtk_main_quit, NULL); + g_signal_connect(win, "delete-event", gtk_main_quit, NULL); + gtk_widget_set_size_request(sock, 200, 200); + gtk_box_pack_start(GTK_BOX(vbox), btn, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), sock, TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(win), vbox); + gtk_widget_show_all(win); + + guint32 id = gtk_socket_get_id(GTK_SOCKET(sock)); + g_signal_connect(btn, "clicked", G_CALLBACK(launch_app), &id); + + gtk_main(); + return 0; +} diff --git a/tests/manual/xembed/gtk-container/gtk-container.pro b/tests/manual/xembed/gtk-container/gtk-container.pro new file mode 100644 index 0000000000..e98f1d6cfa --- /dev/null +++ b/tests/manual/xembed/gtk-container/gtk-container.pro @@ -0,0 +1,16 @@ +TEMPLATE = app +TARGET = gtk-container +QT_FOR_CONFIG += widgets-private +INCLUDEPATH += . +CONFIG += X11 +QMAKE_USE += gtk3 + +# You can make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# Please consult the documentation of the deprecated API in order to know +# how to port your code away from it. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x060000 # disables all APIs deprecated in Qt 6.0.0 and earlier + +# Input +SOURCES += gtk-container.cpp diff --git a/tests/manual/xembed/qt-client-raster/CMakeLists.txt b/tests/manual/xembed/qt-client-raster/CMakeLists.txt new file mode 100644 index 0000000000..0784f411a3 --- /dev/null +++ b/tests/manual/xembed/qt-client-raster/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## qt-client-raster Binary: +##################################################################### + +qt_internal_add_manual_test(qt-client-raster + GUI + SOURCES + main.cpp + rasterwindow.cpp rasterwindow.h + LIBRARIES + Qt::Gui +) diff --git a/tests/manual/xembed/qt-client-raster/main.cpp b/tests/manual/xembed/qt-client-raster/main.cpp new file mode 100644 index 0000000000..628a9f652c --- /dev/null +++ b/tests/manual/xembed/qt-client-raster/main.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "rasterwindow.h" +#include <QDebug> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QStringList args = app.arguments(); + + WId winId = 0; + if (args.count() > 1) { + bool ok; + winId = args[1].toUInt(&ok); + Q_ASSERT(ok); + } + + RasterWindow window; + + QWindow *foreign = QWindow::fromWinId(winId); + Q_ASSERT(foreign != 0); + + window.setParent(foreign); + window.show(); + + return app.exec(); +} diff --git a/tests/manual/xembed/qt-client-raster/qt-client-raster.pro b/tests/manual/xembed/qt-client-raster/qt-client-raster.pro new file mode 100644 index 0000000000..9a47ed41c2 --- /dev/null +++ b/tests/manual/xembed/qt-client-raster/qt-client-raster.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET= qt-client-raster +QT += gui + +SOURCES += \ + main.cpp \ + rasterwindow.cpp +HEADERS += \ + rasterwindow.h diff --git a/tests/manual/xembed/qt-client-raster/rasterwindow.cpp b/tests/manual/xembed/qt-client-raster/rasterwindow.cpp new file mode 100644 index 0000000000..89d765f707 --- /dev/null +++ b/tests/manual/xembed/qt-client-raster/rasterwindow.cpp @@ -0,0 +1,72 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "rasterwindow.h" + +RasterWindow::RasterWindow(QWindow *parent) + : QWindow(parent) + , m_update_pending(false) +{ + winId(); + + m_backingStore = new QBackingStore(this); + create(); + + setGeometry(100, 100, 300, 200); +} + + +bool RasterWindow::event(QEvent *event) +{ + if (event->type() == QEvent::UpdateRequest) { + m_update_pending = false; + renderNow(); + return true; + } + return QWindow::event(event); +} + +void RasterWindow::renderLater() +{ + if (!m_update_pending) { + m_update_pending = true; + QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); + } +} + +void RasterWindow::resizeEvent(QResizeEvent *resizeEvent) +{ + m_backingStore->resize(resizeEvent->size()); + if (isExposed()) + renderNow(); +} + +void RasterWindow::exposeEvent(QExposeEvent *) +{ + if (isExposed()) { + renderNow(); + } +} + +void RasterWindow::renderNow() +{ + if (!isExposed()) + return; + + QRect rect(0, 0, width(), height()); + m_backingStore->beginPaint(rect); + + QPaintDevice *device = m_backingStore->paintDevice(); + QPainter painter(device); + + painter.fillRect(0, 0, width(), height(), Qt::white); + render(&painter); + + m_backingStore->endPaint(); + m_backingStore->flush(rect); +} + +void RasterWindow::render(QPainter *painter) +{ + painter->drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, QStringLiteral("QWindow")); +} diff --git a/tests/manual/xembed/qt-client-raster/rasterwindow.h b/tests/manual/xembed/qt-client-raster/rasterwindow.h new file mode 100644 index 0000000000..2d41cd8e5d --- /dev/null +++ b/tests/manual/xembed/qt-client-raster/rasterwindow.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef RASTERWINDOW_H +#define RASTERWINDOW_H + +#include <QtGui> + +class RasterWindow : public QWindow +{ + Q_OBJECT +public: + explicit RasterWindow(QWindow *parent = nullptr); + + virtual void render(QPainter *painter); + +public slots: + void renderLater(); + void renderNow(); + +protected: + bool event(QEvent *event) override; + + void resizeEvent(QResizeEvent *event) override; + void exposeEvent(QExposeEvent *event) override; + +private: + QBackingStore *m_backingStore; + bool m_update_pending; +}; + +#endif // RASTERWINDOW_H diff --git a/tests/manual/xembed/qt-client-widget/CMakeLists.txt b/tests/manual/xembed/qt-client-widget/CMakeLists.txt new file mode 100644 index 0000000000..8c9ea9e0f8 --- /dev/null +++ b/tests/manual/xembed/qt-client-widget/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## qt-client-widget Binary: +##################################################################### + +qt_internal_add_manual_test(qt-client-widget + GUI + SOURCES + main.cpp + window.cpp window.h + LIBRARIES + Qt::Gui + Qt::Widgets +) diff --git a/tests/manual/xembed/qt-client-widget/main.cpp b/tests/manual/xembed/qt-client-widget/main.cpp new file mode 100644 index 0000000000..bd8b05b054 --- /dev/null +++ b/tests/manual/xembed/qt-client-widget/main.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QApplication> +#include <QDebug> +#include <QWindow> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QStringList args = app.arguments(); + + WId winId = 0; + if (args.count() > 1) { + bool ok; + winId = args[1].toUInt(&ok); + Q_ASSERT(ok); + } + + Window window; + + QWindow *foreign = QWindow::fromWinId(winId); + Q_ASSERT(foreign != 0); + + window.windowHandle()->setParent(foreign); + window.show(); + + return app.exec(); +} diff --git a/tests/manual/xembed/qt-client-widget/qt-client-widget.pro b/tests/manual/xembed/qt-client-widget/qt-client-widget.pro new file mode 100644 index 0000000000..3dfe2c9ab1 --- /dev/null +++ b/tests/manual/xembed/qt-client-widget/qt-client-widget.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET= qt-client-widget +QT += widgets + +SOURCES += \ + main.cpp \ + window.cpp +HEADERS += \ + window.h diff --git a/tests/manual/xembed/qt-client-widget/window.cpp b/tests/manual/xembed/qt-client-widget/window.cpp new file mode 100644 index 0000000000..92feca7506 --- /dev/null +++ b/tests/manual/xembed/qt-client-widget/window.cpp @@ -0,0 +1,206 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtWidgets> + +#include "window.h" + +Window::Window() +{ + setAttribute(Qt::WA_NativeWindow); + setAttribute(Qt::WA_DontCreateNativeAncestors); + createWinId(); + + QGroupBox *echoGroup = new QGroupBox(tr("Echo")); + + QLabel *echoLabel = new QLabel(tr("Mode:")); + QComboBox *echoComboBox = new QComboBox; + echoComboBox->addItem(tr("Normal")); + echoComboBox->addItem(tr("Password")); + echoComboBox->addItem(tr("PasswordEchoOnEdit")); + echoComboBox->addItem(tr("No Echo")); + + echoLineEdit = new QLineEdit; + echoLineEdit->setFocus(); + + QGroupBox *validatorGroup = new QGroupBox(tr("Validator")); + + QLabel *validatorLabel = new QLabel(tr("Type:")); + QComboBox *validatorComboBox = new QComboBox; + validatorComboBox->addItem(tr("No validator")); + validatorComboBox->addItem(tr("Integer validator")); + validatorComboBox->addItem(tr("Double validator")); + + validatorLineEdit = new QLineEdit; + + QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment")); + + QLabel *alignmentLabel = new QLabel(tr("Type:")); + QComboBox *alignmentComboBox = new QComboBox; + alignmentComboBox->addItem(tr("Left")); + alignmentComboBox->addItem(tr("Centered")); + alignmentComboBox->addItem(tr("Right")); + + alignmentLineEdit = new QLineEdit; + + QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask")); + + QLabel *inputMaskLabel = new QLabel(tr("Type:")); + QComboBox *inputMaskComboBox = new QComboBox; + inputMaskComboBox->addItem(tr("No mask")); + inputMaskComboBox->addItem(tr("Phone number")); + inputMaskComboBox->addItem(tr("ISO date")); + inputMaskComboBox->addItem(tr("License key")); + + inputMaskLineEdit = new QLineEdit; + + QGroupBox *accessGroup = new QGroupBox(tr("Access")); + + QLabel *accessLabel = new QLabel(tr("Read-only:")); + QComboBox *accessComboBox = new QComboBox; + accessComboBox->addItem(tr("False")); + accessComboBox->addItem(tr("True")); + + accessLineEdit = new QLineEdit; + + QGroupBox *testGroup = new QGroupBox(tr("Test")); + + QLabel *testLabel = new QLabel(tr("Drag and Drop:")); + textEdit = new QTextEdit; + + connect(echoComboBox, SIGNAL(activated(int)), + this, SLOT(echoChanged(int))); + connect(validatorComboBox, SIGNAL(activated(int)), + this, SLOT(validatorChanged(int))); + connect(alignmentComboBox, SIGNAL(activated(int)), + this, SLOT(alignmentChanged(int))); + connect(inputMaskComboBox, SIGNAL(activated(int)), + this, SLOT(inputMaskChanged(int))); + connect(accessComboBox, SIGNAL(activated(int)), + this, SLOT(accessChanged(int))); + + QGridLayout *echoLayout = new QGridLayout; + echoLayout->addWidget(echoLabel, 0, 0); + echoLayout->addWidget(echoComboBox, 0, 1); + echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2); + echoGroup->setLayout(echoLayout); + + QGridLayout *validatorLayout = new QGridLayout; + validatorLayout->addWidget(validatorLabel, 0, 0); + validatorLayout->addWidget(validatorComboBox, 0, 1); + validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2); + validatorGroup->setLayout(validatorLayout); + + QGridLayout *alignmentLayout = new QGridLayout; + alignmentLayout->addWidget(alignmentLabel, 0, 0); + alignmentLayout->addWidget(alignmentComboBox, 0, 1); + alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2); + alignmentGroup-> setLayout(alignmentLayout); + + QGridLayout *inputMaskLayout = new QGridLayout; + inputMaskLayout->addWidget(inputMaskLabel, 0, 0); + inputMaskLayout->addWidget(inputMaskComboBox, 0, 1); + inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2); + inputMaskGroup->setLayout(inputMaskLayout); + + QGridLayout *accessLayout = new QGridLayout; + accessLayout->addWidget(accessLabel, 0, 0); + accessLayout->addWidget(accessComboBox, 0, 1); + accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2); + accessGroup->setLayout(accessLayout); + + QGridLayout *testLayout = new QGridLayout; + testLayout->addWidget(testLabel, 0, 0); + testLayout->addWidget(textEdit, 1, 0, 1, 2); + testGroup->setLayout(testLayout); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(echoGroup, 0, 0); + layout->addWidget(validatorGroup, 1, 0); + layout->addWidget(alignmentGroup, 2, 0); + layout->addWidget(inputMaskGroup, 0, 1); + layout->addWidget(accessGroup, 1, 1); + layout->addWidget(testGroup, 2, 1); + setLayout(layout); + + setWindowTitle(tr("Line Edits")); +} + +void Window::echoChanged(int index) +{ + switch (index) { + case 0: + echoLineEdit->setEchoMode(QLineEdit::Normal); + break; + case 1: + echoLineEdit->setEchoMode(QLineEdit::Password); + break; + case 2: + echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit); + break; + case 3: + echoLineEdit->setEchoMode(QLineEdit::NoEcho); + } +} + +void Window::validatorChanged(int index) +{ + switch (index) { + case 0: + validatorLineEdit->setValidator(0); + break; + case 1: + validatorLineEdit->setValidator(new QIntValidator( + validatorLineEdit)); + break; + case 2: + validatorLineEdit->setValidator(new QDoubleValidator(-999.0, + 999.0, 2, validatorLineEdit)); + } + + validatorLineEdit->clear(); +} + +void Window::alignmentChanged(int index) +{ + switch (index) { + case 0: + alignmentLineEdit->setAlignment(Qt::AlignLeft); + break; + case 1: + alignmentLineEdit->setAlignment(Qt::AlignCenter); + break; + case 2: + alignmentLineEdit->setAlignment(Qt::AlignRight); + } +} + +void Window::inputMaskChanged(int index) +{ + switch (index) { + case 0: + inputMaskLineEdit->setInputMask(""); + break; + case 1: + inputMaskLineEdit->setInputMask("+99 99 99 99 99;_"); + break; + case 2: + inputMaskLineEdit->setInputMask("0000-00-00"); + inputMaskLineEdit->setText("00000000"); + inputMaskLineEdit->setCursorPosition(0); + break; + case 3: + inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#"); + } +} + +void Window::accessChanged(int index) +{ + switch (index) { + case 0: + accessLineEdit->setReadOnly(false); + break; + case 1: + accessLineEdit->setReadOnly(true); + } +} diff --git a/tests/manual/xembed/qt-client-widget/window.h b/tests/manual/xembed/qt-client-widget/window.h new file mode 100644 index 0000000000..2b069f1ff0 --- /dev/null +++ b/tests/manual/xembed/qt-client-widget/window.h @@ -0,0 +1,38 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QComboBox; +class QLineEdit; +class QTextEdit; +QT_END_NAMESPACE + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +public slots: + void echoChanged(int); + void validatorChanged(int); + void alignmentChanged(int); + void inputMaskChanged(int); + void accessChanged(int); + +private: + QLineEdit *echoLineEdit; + QLineEdit *validatorLineEdit; + QLineEdit *alignmentLineEdit; + QLineEdit *inputMaskLineEdit; + QLineEdit *accessLineEdit; + QTextEdit *textEdit; +}; + +#endif diff --git a/tests/manual/xembed/xembed.pro b/tests/manual/xembed/xembed.pro new file mode 100644 index 0000000000..14a4ddea44 --- /dev/null +++ b/tests/manual/xembed/xembed.pro @@ -0,0 +1,11 @@ +TEMPLATE=subdirs +QT_FOR_CONFIG += network-private gui-private + +TEMPLATE = subdirs +QT_FOR_CONFIG += widgets-private + +SUBDIRS = \ +qt-client-raster \ +qt-client-widget + +qtHaveModule(widgets):qtConfig(gtk3): SUBDIRS += gtk-container |