diff options
Diffstat (limited to 'tests/manual/foreignwindows')
-rw-r--r-- | tests/manual/foreignwindows/CMakeLists.txt | 57 | ||||
-rw-r--r-- | tests/manual/foreignwindows/foreignwindows.pro | 2 | ||||
-rw-r--r-- | tests/manual/foreignwindows/main.cpp | 65 |
3 files changed, 75 insertions, 49 deletions
diff --git a/tests/manual/foreignwindows/CMakeLists.txt b/tests/manual/foreignwindows/CMakeLists.txt new file mode 100644 index 0000000000..41b2260946 --- /dev/null +++ b/tests/manual/foreignwindows/CMakeLists.txt @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## foreignwindows Binary: +##################################################################### + +qt_internal_add_manual_test(foreignwindows + SOURCES + ../diaglib/eventfilter.cpp ../diaglib/eventfilter.h + ../diaglib/nativewindowdump.h + ../diaglib/qwindowdump.cpp ../diaglib/qwindowdump.h + ../diaglib/textdump.cpp ../diaglib/textdump.h + main.cpp + DEFINES + QT_DIAG_LIB + INCLUDE_DIRECTORIES + ../diaglib + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::OpenGL + Qt::Widgets +) + +## Scopes: +##################################################################### + +qt_internal_extend_target(foreignwindows CONDITION WIN32 + SOURCES + ../diaglib/nativewindowdump_win.cpp + LIBRARIES + user32 +) + +qt_internal_extend_target(foreignwindows CONDITION UNIX + SOURCES + ../diaglib/nativewindowdump.cpp +) + +qt_internal_extend_target(foreignwindows CONDITION QT_FEATURE_widgets + SOURCES + ../diaglib/debugproxystyle.cpp ../diaglib/debugproxystyle.h + ../diaglib/logwidget.cpp ../diaglib/logwidget.h + ../diaglib/qwidgetdump.cpp ../diaglib/qwidgetdump.h + LIBRARIES + Qt::WidgetsPrivate +) + +qt_internal_extend_target(foreignwindows CONDITION QT_FEATURE_opengl + SOURCES + ../diaglib/glinfo.cpp ../diaglib/glinfo.h + LIBRARIES + Qt::OpenGL + Qt::OpenGLWidgets +) diff --git a/tests/manual/foreignwindows/foreignwindows.pro b/tests/manual/foreignwindows/foreignwindows.pro index 15bf2395f8..b78931bf7a 100644 --- a/tests/manual/foreignwindows/foreignwindows.pro +++ b/tests/manual/foreignwindows/foreignwindows.pro @@ -1,5 +1,5 @@ TEMPLATE = app -QT += widgets +QT += widgets opengl CONFIG += cmdline c++11 SOURCES += main.cpp include(../diaglib/diaglib.pri) diff --git a/tests/manual/foreignwindows/main.cpp b/tests/manual/foreignwindows/main.cpp index 44aff54773..1fb4b0c167 100644 --- a/tests/manual/foreignwindows/main.cpp +++ b/tests/manual/foreignwindows/main.cpp @@ -1,34 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtWidgets/QAction> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtGui/QAction> #include <QtWidgets/QApplication> -#include <QtWidgets/QDesktopWidget> #include <QtWidgets/QMainWindow> #include <QtWidgets/QMenu> #include <QtWidgets/QMenuBar> @@ -59,9 +33,9 @@ QT_USE_NAMESPACE -typedef QSharedPointer<QWidget> WidgetPtr; -typedef QList<WidgetPtr> WidgetPtrList; -typedef QList<WId> WIdList; +using WidgetPtr = QSharedPointer<QWidget>; +using WidgetPtrList = QList<WidgetPtr>; +using WIdList = QList<WId>; // Create some pre-defined Windows controls by class name static WId createInternalWindow(const QString &name) @@ -74,7 +48,7 @@ static WId createInternalWindow(const QString &name) CreateWindowEx(0, reinterpret_cast<const wchar_t *>(name.utf16()), L"NativeCtrl", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, GetModuleHandle(NULL), NULL); + nullptr, nullptr, GetModuleHandle(nullptr), nullptr); if (hwnd) { SetWindowText(hwnd, L"Demo"); result = WId(hwnd); @@ -83,7 +57,7 @@ static WId createInternalWindow(const QString &name) } } #else // Q_OS_WIN - Q_UNUSED(name) + Q_UNUSED(name); #endif return result; } @@ -143,7 +117,7 @@ EmbeddingWindow::EmbeddingWindow(QWindow *window) : m_window(window) fileMenu->addSeparator(); action = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit); toolbar->addAction(action); - action->setShortcut(Qt::CTRL + Qt::Key_Q); + action->setShortcut(Qt::CTRL | Qt::Key_Q); } void EmbeddingWindow::releaseForeignWindow() @@ -179,7 +153,7 @@ void WindowDumper::dump() const debug << '#' << n++; if (m_watchedWindows.size() > 1) debug << '\n'; - foreach (const QWindow *w, m_watchedWindows) { + for (const QWindow *w : m_watchedWindows) { const QPoint globalPos = w->mapToGlobal(QPoint()); debug << " " << w << " pos=" << globalPos.x() << ',' << globalPos.y() << '\n'; } @@ -212,7 +186,7 @@ struct EventFilterOption QtDiag::EventFilter::EventCategories categories; }; -EventFilterOption eventFilterOptions[] = { +static EventFilterOption eventFilterOptions[] = { {"mouse-events", "Dump mouse events.", QtDiag::EventFilter::MouseEvents}, {"keyboard-events", "Dump keyboard events.", QtDiag::EventFilter::KeyEvents}, {"state-events", "Dump state/focus change events.", QtDiag::EventFilter::StateChangeEvents | QtDiag::EventFilter::FocusEvents} @@ -227,9 +201,6 @@ static inline bool isOptionSet(int argc, char *argv[], const char *option) int main(int argc, char *argv[]) { - // Check for no scaling before QApplication is instantiated. - if (isOptionSet(argc, argv, "-s")) - QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); QGuiApplication::setApplicationDisplayName("Foreign window tester"); @@ -248,11 +219,10 @@ int main(int argc, char *argv[]) parser.addOption(outputAllOption); QCommandLineOption continuousOption(QStringList() << QStringLiteral("c") << QStringLiteral("continuous"), QStringLiteral("Output continuously.")); - parser.addOption(outputAllOption); + parser.addOption(continuousOption); QCommandLineOption moveOption(QStringList() << QStringLiteral("m") << QStringLiteral("move"), QStringLiteral("Move window to top left corner.")); parser.addOption(moveOption); - parser.addOption(continuousOption); QCommandLineOption embedOption(QStringList() << QStringLiteral("e") << QStringLiteral("embed"), QStringLiteral("Embed a foreign window into a Qt widget.")); parser.addOption(embedOption); @@ -271,7 +241,7 @@ int main(int argc, char *argv[]) } QWindowList windows; - foreach (const QString &argument, parser.positionalArguments()) { + for (const QString &argument : parser.positionalArguments()) { bool ok = true; WId wid = createInternalWindow(argument); if (!wid) @@ -295,7 +265,7 @@ int main(int argc, char *argv[]) int exitCode = 0; if (parser.isSet(embedOption)) { - QtDiag::EventFilter::EventCategories eventCategories = 0; + QtDiag::EventFilter::EventCategories eventCategories; for (int i = 0; i < eventFilterOptionCount; ++i) { if (parser.isSet(QLatin1String(eventFilterOptions[i].name))) eventCategories |= eventFilterOptions[i].categories; @@ -303,11 +273,11 @@ int main(int argc, char *argv[]) if (eventCategories) app.installEventFilter(new QtDiag::EventFilter(eventCategories, &app)); - const QRect availableGeometry = QApplication::desktop()->availableGeometry(0); + const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QPoint pos = availableGeometry.topLeft() + QPoint(availableGeometry.width(), availableGeometry.height()) / 3; WidgetPtrList mainWindows; - foreach (QWindow *window, windows) { + for (QWindow *window : std::as_const(windows)) { WidgetPtr mainWindow(new EmbeddingWindow(window)); mainWindow->move(pos); mainWindow->resize(availableGeometry.size() / 4); @@ -324,7 +294,6 @@ int main(int argc, char *argv[]) QObject::connect(timer, &QTimer::timeout, &dumper, &WindowDumper::dump); timer->start(1000); exitCode = app.exec(); - } else { WindowDumper(windows).dump(); } |