qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(allcursors)
add_subdirectory(childwidget)
add_subdirectory(childwindow)
add_subdirectory(childwindowcontainer)
add_subdirectory(grab_override)
add_subdirectory(qcursorhighdpi)

View File

@ -0,0 +1,18 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_allcursors Binary:
#####################################################################
qt_internal_add_manual_test(tst_allcursors
GUI
SOURCES
main.cpp
mainwindow.cpp mainwindow.h mainwindow.ui
LIBRARIES
Qt::Gui
Qt::Widgets
ENABLE_AUTOGEN_TOOLS
uic
)

View File

@ -0,0 +1,10 @@
TARGET = tst_allcursors
TEMPLATE = app
QT = core gui widgets
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showFullScreen();
#ifdef QT_KEYPAD_NAVIGATION
QApplication::setNavigationMode(Qt::NavigationModeCursorForceVisible);
#endif
return a.exec();
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QBitmap>
#include <QImage>
#include <QPainter>
#include <QKeyEvent>
#include <QPoint>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
QPoint off(0, 0);
switch (event->key()) {
case Qt::Key_Q:
qApp->quit();
break;
case Qt::Key_Up:
off.setY(-4);
break;
case Qt::Key_Down:
off.setY(4);
break;
case Qt::Key_Left:
off.setX(-4);
break;
case Qt::Key_Right:
off.setX(4);
break;
default:
return QMainWindow::keyPressEvent(event);
}
off += QCursor::pos();
QCursor::setPos(off);
}

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QTimer;
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
void keyPressEvent(QKeyEvent* event);
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Arrow</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="cursor">
<cursorShape>UpArrowCursor</cursorShape>
</property>
<property name="text">
<string>up arrow</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="cursor">
<cursorShape>CrossCursor</cursorShape>
</property>
<property name="text">
<string>cross</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="cursor">
<cursorShape>WaitCursor</cursorShape>
</property>
<property name="text">
<string>wait</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_5">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>ibeam</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_6">
<property name="cursor">
<cursorShape>SizeVerCursor</cursorShape>
</property>
<property name="text">
<string>sizever</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="cursor">
<cursorShape>SizeHorCursor</cursorShape>
</property>
<property name="text">
<string>sizehor</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_8">
<property name="cursor">
<cursorShape>SizeFDiagCursor</cursorShape>
</property>
<property name="text">
<string>sizebdiag</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_9">
<property name="cursor">
<cursorShape>SizeBDiagCursor</cursorShape>
</property>
<property name="text">
<string>sizefdiag</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="cursor">
<cursorShape>SizeAllCursor</cursorShape>
</property>
<property name="text">
<string>sizeall</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_11">
<property name="cursor">
<cursorShape>BlankCursor</cursorShape>
</property>
<property name="text">
<string>blank</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_12">
<property name="cursor">
<cursorShape>SplitVCursor</cursorShape>
</property>
<property name="text">
<string>splitv</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="cursor">
<cursorShape>SplitHCursor</cursorShape>
</property>
<property name="text">
<string>splith</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_14">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>pointhand</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_15">
<property name="cursor">
<cursorShape>ForbiddenCursor</cursorShape>
</property>
<property name="text">
<string>forbidden</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_16">
<property name="cursor">
<cursorShape>WhatsThisCursor</cursorShape>
</property>
<property name="text">
<string>whatsthis</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_19">
<property name="cursor">
<cursorShape>BusyCursor</cursorShape>
</property>
<property name="text">
<string>busy</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_17">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>openhand</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_18">
<property name="cursor">
<cursorShape>ClosedHandCursor</cursorShape>
</property>
<property name="text">
<string>closehand</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,17 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_manual_childwidget Binary:
#####################################################################
qt_internal_add_manual_test(tst_manual_childwidget
GUI
SOURCES
main.cpp
INCLUDE_DIRECTORIES
.
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,6 @@
TEMPLATE = app
TARGET = tst_manual_childwidget
INCLUDEPATH += .
QT += widgets
SOURCES += main.cpp

View File

@ -0,0 +1,63 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets>
class CursorWidget : public QWidget
{
public:
CursorWidget(QCursor cursor, QColor color)
:m_cursor(cursor)
,m_color(color)
{
if (cursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(cursor);
}
void paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.fillRect(e->rect(), m_color);
}
void mousePressEvent(QMouseEvent *)
{
// Toggle cursor
QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor;
if (newCursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(newCursor);
}
private:
QCursor m_cursor;
QColor m_color;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
// Test child widgets (one of which is native) with set cursors.
// Click window to toggle cursor.
CursorWidget w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker());
w1.resize(200, 200);
w1.show();
CursorWidget w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker());
w2.setParent(&w1);
w2.setGeometry(0, 0, 100, 100);
w2.show();
CursorWidget w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker());
w3.winId();
w3.setParent(&w1);
w3.setGeometry(100, 100, 100, 100);
w3.show();
return app.exec();
}

View File

@ -0,0 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## childwindow Binary:
#####################################################################
qt_internal_add_manual_test(childwindow
GUI
SOURCES
main.cpp
INCLUDE_DIRECTORIES
.
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,5 @@
TEMPLATE = app
TARGET = childwindow
INCLUDEPATH += .
SOURCES += main.cpp

View File

@ -0,0 +1,62 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtGui>
class CursorWindow : public QRasterWindow
{
public:
CursorWindow(QCursor cursor, QColor color)
:m_cursor(cursor)
,m_color(color)
{
if (cursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(cursor);
}
void paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.fillRect(e->rect(), m_color);
}
void mousePressEvent(QMouseEvent *)
{
// Toggle cursor
QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor;
if (newCursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(newCursor);
}
private:
QCursor m_cursor;
QColor m_color;
};
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
// Test child windows with set cursors. Create parent window and
// two child windows. Click window to toggle cursor.
CursorWindow w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker());
w1.resize(200, 200);
w1.show();
CursorWindow w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker());
w2.setParent(&w1);
w2.setGeometry(0, 0, 100, 100);
w2.show();
CursorWindow w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker());
w3.setParent(&w1);
w3.setGeometry(100, 100, 100, 100);
w3.show();
return app.exec();
}

View File

@ -0,0 +1,17 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## childwindowcontainer Binary:
#####################################################################
qt_internal_add_manual_test(childwindowcontainer
GUI
SOURCES
main.cpp
INCLUDE_DIRECTORIES
.
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,6 @@
TEMPLATE = app
TARGET = childwindowcontainer
INCLUDEPATH += .
QT += widgets
SOURCES += main.cpp

View File

@ -0,0 +1,109 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets>
class CursorWindow : public QRasterWindow
{
public:
CursorWindow(QCursor cursor, QColor color)
:m_cursor(cursor)
,m_color(color)
{
if (cursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(cursor);
}
void paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.fillRect(e->rect(), m_color);
}
void mousePressEvent(QMouseEvent *)
{
// Toggle cursor
QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor;
if (newCursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(newCursor);
}
private:
QCursor m_cursor;
QColor m_color;
};
class CursorWidget : public QWidget
{
public:
CursorWidget(QCursor cursor, QColor color)
:m_cursor(cursor)
,m_color(color)
{
if (cursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(cursor);
}
void paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.fillRect(e->rect(), m_color);
}
void mousePressEvent(QMouseEvent *)
{
// Toggle cursor
QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor;
if (newCursor.shape() == Qt::ArrowCursor)
unsetCursor();
else
setCursor(newCursor);
}
private:
QCursor m_cursor;
QColor m_color;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
{
// Create top-level windowContainer with window. Setting the cursor
// for the container should set the cursor for the window as well.
// Setting the cursor for the window overrides the cursor for the
// container. The example starts out with a window cursor; click
// to fall back to the container cursor.
CursorWindow *w1 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker());
QWidget* container = QWidget::createWindowContainer(w1);
container->resize(200, 200);
container->setCursor(Qt::PointingHandCursor);
container->show();
}
{
// Similar to above, but with a top-level QWiget
CursorWidget *w1 = new CursorWidget(QCursor(Qt::IBeamCursor), QColor(Qt::green).darker());
w1->resize(200, 200);
CursorWindow *w2 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker());
QWidget* container = QWidget::createWindowContainer(w2);
container->winId(); // must make the container native, otherwise setCursor
// sets the cursor on a QWindowContainerClassWindow which
// is outside the QWindow hierarchy (macOS).
container->setParent(w1);
container->setCursor(Qt::PointingHandCursor);
container->setGeometry(0, 0, 100, 100);
w1->show();
}
return app.exec();
}

View File

@ -0,0 +1,30 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## t_cursors Binary:
#####################################################################
qt_internal_add_manual_test(t_cursors
GUI
SOURCES
main.cpp
mainwindow.cpp mainwindow.h mainwindow.ui
LIBRARIES
Qt::Gui
Qt::Widgets
ENABLE_AUTOGEN_TOOLS
uic
)
# Resources:
set(images_resource_files
"data/monkey_on_64x64.png"
)
qt_internal_add_resource(t_cursors "images"
PREFIX
"/"
FILES
${images_resource_files}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,12 @@
TARGET = t_cursors
TEMPLATE = app
QT = core gui widgets
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += images.qrc

View File

@ -0,0 +1,6 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/">
<file>data/monkey_on_64x64.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showFullScreen();
#ifdef QT_KEYPAD_NAVIGATION
QApplication::setNavigationMode(Qt::NavigationModeCursorForceVisible);
#endif
return a.exec();
}

View File

@ -0,0 +1,103 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QBitmap>
#include <QImage>
#include <QPainter>
#include <QKeyEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pix(":/data/monkey_on_64x64.png");
QImage mask(16, 16, QImage::Format_MonoLSB);
QImage bw(16, 16, QImage::Format_MonoLSB);
mask.fill(0);
bw.fill(0);
for (int x = 0; x < 16; x++) {
bw.setPixel(x, x, 1);
bw.setPixel(x, 15 - x, 1);
mask.setPixel(x, x, 1);
mask.setPixel(x, 15 - x, 1);
if (x > 0 && x < 15) {
mask.setPixel(x - 1, x, 1);
mask.setPixel(x + 1, x, 1);
mask.setPixel(x - 1, 15 - x, 1);
mask.setPixel(x + 1, 15 - x, 1);
}
}
ccurs = QCursor(pix);
bcurs = QCursor(QBitmap::fromImage(bw), QBitmap::fromImage(mask));
ui->label->setCursor(ccurs);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(toggleOverrideCursor()));
timer->start(2000);
override = 0;
}
MainWindow::~MainWindow()
{
delete timer;
delete ui;
}
void MainWindow::toggleOverrideCursor()
{
switch (override) {
case 0:
QGuiApplication::setOverrideCursor(Qt::BusyCursor);
break;
case 1:
QGuiApplication::restoreOverrideCursor();
break;
case 2:
ui->label->grabMouse(Qt::ForbiddenCursor);
break;
case 3:
case 5:
ui->label->releaseMouse();
break;
case 4:
ui->label->grabMouse();
break;
case 6:
ui->label->setCursor(bcurs);
break;
case 7:
ui->label->setCursor(ccurs);
break;
}
override = (override + 1) % 8;
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
QPoint off(0, 0);
switch (event->key()) {
case Qt::Key_Up:
off.setY(-4);
break;
case Qt::Key_Down:
off.setY(4);
break;
case Qt::Key_Left:
off.setX(-4);
break;
case Qt::Key_Right:
off.setX(4);
break;
default:
return QMainWindow::keyPressEvent(event);
}
off += QCursor::pos();
QCursor::setPos(off);
}

View File

@ -0,0 +1,38 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QTimer;
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void toggleOverrideCursor();
private:
void keyPressEvent(QKeyEvent* event);
Ui::MainWindow *ui;
QTimer *timer;
int override;
QCursor ccurs;
QCursor bcurs;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSplitter" name="splitter_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="midLineWidth">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Custom</string>
</property>
</widget>
<widget class="QSplitter" name="splitter">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="midLineWidth">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QLabel" name="label_2">
<property name="cursor">
<cursorShape>ForbiddenCursor</cursorShape>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Forbidden</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="cursor">
<cursorShape>WaitCursor</cursorShape>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Wait</string>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>240</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = allcursors childwidget childwindow childwindowcontainer grab_override qcursorhighdpi

View File

@ -0,0 +1,24 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qcursorhighdpi Binary:
#####################################################################
qt_internal_add_manual_test(qcursorhighdpi
SOURCES
main.cpp
LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
)
## Scopes:
#####################################################################
qt_internal_extend_target(qcursorhighdpi CONDITION WIN32
LIBRARIES
user32
)

View File

@ -0,0 +1,311 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QAction>
#include <QApplication>
#include <QGridLayout>
#include <QLabel>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QSharedPointer>
#include <QToolBar>
#include <QBitmap>
#include <QCursor>
#include <QDrag>
#include <QPainter>
#include <QPixmap>
#include <QDebug>
#include <QMimeData>
#include <QStringList>
#include <QTextStream>
#include <QScreen>
#include <QWindow>
#include <private/qhighdpiscaling_p.h>
#include <qpa/qplatformwindow.h>
#ifdef Q_OS_WIN
# include <qt_windows.h>
#endif
#include <algorithm>
#include <iterator>
// High DPI cursor test for testing cursor sizes in multi-screen setups.
// It creates one widget per screen with a grid of standard cursors,
// pixmap / bitmap cursors and pixmap / bitmap cursors with device pixel ratio 2.
// On the left, there is a ruler with 10 DIP marks.
// The code is meant to compile with Qt 4 also.
static QString screenInfo(const QWidget *w)
{
QString result;
QTextStream str(&result);
QScreen *screen = nullptr;
if (const QWindow *window = w->windowHandle())
screen = window->screen();
if (screen) {
str << '"' << screen->name() << "\" " << screen->size().width() << 'x'
<< screen->size().height() << ", DPR=" << screen->devicePixelRatio()
<< ", " << screen->logicalDotsPerInchX() << "DPI ";
if (QHighDpiScaling::isActive())
str << ", factor=" << QHighDpiScaling::factor(screen);
else
str << ", no scaling";
} else {
str << "<null>";
}
#ifdef Q_OS_WIN
str << ", SM_C_CURSOR: " << GetSystemMetrics(SM_CXCURSOR) << 'x' << GetSystemMetrics(SM_CYCURSOR);
#endif
return result;
}
// Helpers for painting pixmaps and creating cursors
static QPixmap paintPixmap(int size, QColor c)
{
QPixmap result(size, size);
result.fill(c);
QPainter p(&result);
p.drawRect(QRect(QPoint(0, 0), result.size() - QSize(1, 1)));
p.drawLine(0, 0, size, size);
p.drawLine(0, size, size, 0);
return result;
}
static QCursor pixmapCursor(int size)
{
QCursor result(paintPixmap(size, Qt::red), size / 2, size / 2);
return result;
}
static QPair<QBitmap, QBitmap> paintBitmaps(int size)
{
QBitmap bitmap(size, size);
bitmap.fill(Qt::color1);
QBitmap mask(size, size);
mask.fill(Qt::color1);
{
QPainter mp(&mask);
mp.fillRect(QRect(0, 0, size / 2, size / 2), Qt::color0);
}
return QPair<QBitmap, QBitmap>(bitmap, mask);
}
static QCursor bitmapCursor(int size)
{
QPair<QBitmap, QBitmap> bitmaps = paintBitmaps(size);
return QCursor(bitmaps.first, bitmaps.second, size / 2, size / 2);
}
static QCursor pixmapCursorDevicePixelRatio(int size, int dpr)
{
QPixmap pixmap = paintPixmap(dpr * size, Qt::yellow);
pixmap.setDevicePixelRatio(dpr);
return QCursor(pixmap, size / 2, size / 2);
}
static QCursor bitmapCursorDevicePixelRatio(int size, int dpr)
{
QPair<QBitmap, QBitmap> bitmaps = paintBitmaps(dpr * size);
bitmaps.first.setDevicePixelRatio(dpr);
bitmaps.second.setDevicePixelRatio(dpr);
return QCursor(bitmaps.first, bitmaps.second, size / 2, size / 2);
}
// A label from which a pixmap can be dragged for testing drag with pixmaps/DPR.
class DraggableLabel : public QLabel {
public:
explicit DraggableLabel(const QPixmap &p, const QString &text, QWidget *parent = Q_NULLPTR)
: QLabel(text, parent), m_pixmap(p)
{
setToolTip(QLatin1String("Click to drag away the pixmap. Press Shift to set a circular mask."));
}
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
const QPixmap m_pixmap;
};
void DraggableLabel::mousePressEvent(QMouseEvent *)
{
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(QVariant::fromValue(m_pixmap));
QDrag *drag = new QDrag(this);
QPixmap pixmap = m_pixmap;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
QBitmap mask(pixmap.width(), pixmap.height());
mask.clear();
QPainter painter(&mask);
painter.setBrush(Qt::color1);
const int hx = pixmap.width() / 2;
const int hy = pixmap.width() / 2;
painter.drawEllipse(QPoint(hx, hy), hx, hy);
pixmap.setMask(mask);
}
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
QPoint sizeP = QPoint(m_pixmap.width(), m_pixmap.height());
sizeP /= int(m_pixmap.devicePixelRatio());
drag->setHotSpot(sizeP / 2);
qDebug() << "Dragging:" << m_pixmap;
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
// Vertical ruler widget with 10 px marks
class VerticalRuler : public QWidget {
public:
VerticalRuler(QWidget *parent = Q_NULLPTR);
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
};
VerticalRuler::VerticalRuler(QWidget *parent) : QWidget(parent)
{
const int screenWidth = screen()->geometry().width();
setFixedWidth(screenWidth / 48); // 1920 pixel monitor ->40
}
void VerticalRuler::paintEvent(QPaintEvent *)
{
const QSize sizeS(size());
const QPoint sizeP(sizeS.width(), sizeS.height());
const QPoint center = sizeP / 2;
QPainter painter(this);
painter.fillRect(QRect(QPoint(0, 0), sizeS), Qt::white);
painter.drawLine(center.x(), 0, center.x(), sizeP.y());
for (int y = 0; y < sizeP.y(); y += 10)
painter.drawLine(center.x() - 5, y, center.x() + 5, y);
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = Q_NULLPTR);
void updateScreenInfo() { m_screenInfoLabel->setText(screenInfo(this)); }
public slots:
void screenChanged() { updateScreenInfo(); }
private:
QLabel *m_screenInfoLabel;
};
static QLabel *createCursorLabel(const QCursor &cursor, const QString &additionalText = QString())
{
QString labelText;
QDebug(&labelText).nospace() << cursor.shape();
labelText.remove(0, labelText.indexOf('(') + 1);
labelText.chop(1);
if (!additionalText.isEmpty())
labelText += ' ' + additionalText;
const QPixmap cursorPixmap = cursor.pixmap();
QLabel *result = Q_NULLPTR;
if (cursorPixmap.size().isEmpty()) {
result = new QLabel(labelText);
result->setFrameShape(QFrame::Box);
} else {
result = new DraggableLabel(cursor.pixmap(), labelText);
result->setFrameShape(QFrame::StyledPanel);
}
result->setCursor(cursor);
return result;
}
static void addToGrid(QWidget *w, QGridLayout *gridLayout, int columnCount, int &row, int &col)
{
gridLayout->addWidget(w, row, col);
if (col >= columnCount) {
col = 0;
row++;
} else {
col++;
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_screenInfoLabel(new QLabel)
{
QString title = "Cursors ";
title += '(' + QGuiApplication::platformName() + ") ";
title += QT_VERSION_STR;
setWindowTitle(title);
QMenu *fileMenu = menuBar()->addMenu("File");
QAction *quitAction = fileMenu->addAction("Quit");
quitAction->setShortcut(Qt::CTRL | Qt::Key_Q);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
QToolBar *fileToolBar = addToolBar("File");
fileToolBar->addAction(quitAction);
QWidget *cw = new QWidget;
QHBoxLayout *hLayout = new QHBoxLayout(cw);
hLayout->addWidget(new VerticalRuler(cw));
QGridLayout *gridLayout = new QGridLayout;
hLayout->addLayout(gridLayout);
const int columnCount = 5;
const int size = 32;
int row = 0;
int col = 0;
for (int i = 0; i < Qt::BitmapCursor; ++i)
addToGrid(createCursorLabel(QCursor(static_cast<Qt::CursorShape>(i))), gridLayout, columnCount, row, col);
addToGrid(createCursorLabel(QCursor(pixmapCursor(size)),
QLatin1String("Plain PX ") + QString::number(size)),
gridLayout, columnCount, row, col);
addToGrid(createCursorLabel(bitmapCursor(size),
QLatin1String("Plain BM ") + QString::number(size)),
gridLayout, columnCount, row, col);
addToGrid(createCursorLabel(QCursor(pixmapCursorDevicePixelRatio(size, 2)),
"PX with DPR 2 " + QString::number(size)),
gridLayout, columnCount, row, col);
addToGrid(createCursorLabel(QCursor(bitmapCursorDevicePixelRatio(size, 2)),
"BM with DPR 2 " + QString::number(size)),
gridLayout, columnCount, row, col);
gridLayout->addWidget(m_screenInfoLabel, row + 1, 0, 1, columnCount);
setCentralWidget(cw);
}
typedef QSharedPointer<MainWindow> MainWindowPtr;
typedef QList<MainWindowPtr> MainWindowPtrList;
int main(int argc, char *argv[])
{
QStringList arguments;
std::copy(argv + 1, argv + argc, std::back_inserter(arguments));
QApplication app(argc, argv);
MainWindowPtrList windows;
const int lastScreen = arguments.contains("-p")
? 0 // Primary screen only
: QGuiApplication::screens().size() - 1; // All screens
for (int s = lastScreen; s >= 0; --s) {
MainWindowPtr window(new MainWindow());
const QPoint pos = QGuiApplication::screens().at(s)->geometry().center() - QPoint(200, 100);
window->move(pos);
windows.append(window);
window->show();
window->updateScreenInfo();
QObject::connect(window->windowHandle(), &QWindow::screenChanged,
window.data(), &MainWindow::updateScreenInfo);
}
return app.exec();
}
#include "main.moc"

View File

@ -0,0 +1,5 @@
TEMPLATE = app
QT = core gui gui-private core-private widgets
CONFIG -= app_bundle
SOURCES += main.cpp
win32: LIBS += -luser32