mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-06 17:25:24 +08:00
qt 6.5.1 original
This commit is contained in:
35
tests/manual/highdpi/kitchensink/CMakeLists.txt
Normal file
35
tests/manual/highdpi/kitchensink/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#####################################################################
|
||||
## kitchensink Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(kitchensink
|
||||
SOURCES
|
||||
dragwidget.cpp dragwidget.h
|
||||
main.cpp
|
||||
DEFINES
|
||||
HAVE_SCREEN_BASE_DPI
|
||||
INCLUDE_DIRECTORIES
|
||||
.
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(kitchensink_resource_files
|
||||
"qticon16.png"
|
||||
"qticon16@2x.png"
|
||||
"qticon16@3x.png"
|
||||
"qticon32.png"
|
||||
"qticon32@2x.png"
|
||||
"qticon64.png"
|
||||
)
|
||||
|
||||
qt_internal_add_resource(kitchensink "kitchensink"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${kitchensink_resource_files}
|
||||
)
|
196
tests/manual/highdpi/kitchensink/dragwidget.cpp
Normal file
196
tests/manual/highdpi/kitchensink/dragwidget.cpp
Normal file
@ -0,0 +1,196 @@
|
||||
// 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 <QtWidgets>
|
||||
#include "dragwidget.h"
|
||||
|
||||
class FramedLabel : public QLabel
|
||||
{
|
||||
public:
|
||||
FramedLabel(const QString &text, QWidget *parent)
|
||||
: QLabel(text, parent)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setFrameShape(QFrame::Panel);
|
||||
setFrameShadow(QFrame::Raised);
|
||||
}
|
||||
};
|
||||
|
||||
DragWidget::DragWidget(QString text, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
int x = 5;
|
||||
int y = 5;
|
||||
|
||||
bool createChildWindow = text.isEmpty(); // OK, yes this is a hack...
|
||||
if (text.isEmpty())
|
||||
text = "You can drag from this window and drop text here";
|
||||
|
||||
QStringList words = text.split(' ');
|
||||
for (const QString &word : words) {
|
||||
if (!word.isEmpty()) {
|
||||
auto wordLabel = new FramedLabel(word, this);
|
||||
wordLabel->move(x, y);
|
||||
wordLabel->show();
|
||||
x += wordLabel->width() + 2;
|
||||
if (x >= 245) {
|
||||
x = 5;
|
||||
y += wordLabel->height() + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
QPalette newPalette = palette();
|
||||
newPalette.setColor(QPalette::Window, Qt::white);
|
||||
setPalette(newPalette);
|
||||
*/
|
||||
|
||||
setAcceptDrops(true);
|
||||
setMinimumSize(400, qMax(200, y));
|
||||
setWindowTitle(tr("Draggable Text Window %1").arg(createChildWindow ? 1 : 2));
|
||||
if (createChildWindow)
|
||||
otherWindow = new DragWidget("Here is a second window that accepts drops");
|
||||
}
|
||||
|
||||
void DragWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasText()) {
|
||||
if (event->source() == this) {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void DragWidget::dragMoveEvent(QDragMoveEvent * event)
|
||||
{
|
||||
dragPos = event->pos();
|
||||
dragTimer.start(500, this);
|
||||
update();
|
||||
}
|
||||
|
||||
void DragWidget::dragLeaveEvent(QDragLeaveEvent *)
|
||||
{
|
||||
dragTimer.stop();
|
||||
update();
|
||||
}
|
||||
|
||||
void DragWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasText()) {
|
||||
const QMimeData *mime = event->mimeData();
|
||||
QStringList pieces = mime->text().split(QRegularExpression("\\s+"),
|
||||
Qt::SkipEmptyParts);
|
||||
QPoint position = event->pos();
|
||||
QPoint hotSpot;
|
||||
|
||||
QList<QByteArray> hotSpotPos = mime->data("application/x-hotspot").split(' ');
|
||||
if (hotSpotPos.size() == 2) {
|
||||
hotSpot.setX(hotSpotPos.first().toInt());
|
||||
hotSpot.setY(hotSpotPos.last().toInt());
|
||||
}
|
||||
dropPos = position - hotSpot;
|
||||
dropTimer.start(500, this);
|
||||
update();
|
||||
|
||||
foreach (QString piece, pieces) {
|
||||
FramedLabel *newLabel = new FramedLabel(piece, this);
|
||||
newLabel->move(position - hotSpot);
|
||||
newLabel->show();
|
||||
|
||||
position += QPoint(newLabel->width(), 0);
|
||||
}
|
||||
|
||||
if (event->source() == this) {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
for (QObject *child : children()) {
|
||||
if (child->isWidgetType()) {
|
||||
auto widget = static_cast<QWidget *>(child);
|
||||
if (!widget->isVisible())
|
||||
widget->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DragWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
|
||||
if (!child)
|
||||
return;
|
||||
|
||||
QPoint hotSpot = event->pos() - child->pos();
|
||||
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setText(child->text());
|
||||
mimeData->setData("application/x-hotspot",
|
||||
QByteArray::number(hotSpot.x()) + ' ' + QByteArray::number(hotSpot.y()));
|
||||
|
||||
const qreal dpr = devicePixelRatio() > 1 && !(QGuiApplication::keyboardModifiers() & Qt::ShiftModifier)
|
||||
? devicePixelRatio() : 1;
|
||||
|
||||
QPixmap pixmap(child->size() * dpr);
|
||||
pixmap.setDevicePixelRatio(dpr);
|
||||
child->render(&pixmap);
|
||||
|
||||
auto drag = new QDrag(this);
|
||||
drag->setMimeData(mimeData);
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setHotSpot(hotSpot);
|
||||
|
||||
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
|
||||
|
||||
if (dropAction == Qt::MoveAction)
|
||||
child->close();
|
||||
}
|
||||
|
||||
void DragWidget::timerEvent(QTimerEvent *e)
|
||||
{
|
||||
if (e->timerId() == dragTimer.timerId())
|
||||
dragTimer.stop();
|
||||
if (e->timerId() == dropTimer.timerId())
|
||||
dropTimer.stop();
|
||||
update();
|
||||
}
|
||||
|
||||
void DragWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.fillRect(rect(), Qt::white);
|
||||
|
||||
if (dropTimer.isActive()) {
|
||||
p.setBrush(Qt::red);
|
||||
p.drawEllipse(dropPos, 50, 50);
|
||||
}
|
||||
|
||||
if (dragTimer.isActive()) {
|
||||
p.setPen(QPen(Qt::blue, 5));
|
||||
QPoint p1 = (rect().topLeft()*3 + rect().bottomRight())/4;
|
||||
QPoint p2 = (rect().topLeft() + rect().bottomRight()*3)/4;
|
||||
p.drawLine(p1, dragPos);
|
||||
p.drawLine(p2, dragPos);
|
||||
}
|
||||
}
|
||||
|
||||
void DragWidget::showEvent(QShowEvent *)
|
||||
{
|
||||
if (otherWindow)
|
||||
otherWindow->show();
|
||||
}
|
||||
|
||||
void DragWidget::hideEvent(QHideEvent *)
|
||||
{
|
||||
if (otherWindow)
|
||||
otherWindow->hide();
|
||||
}
|
39
tests/manual/highdpi/kitchensink/dragwidget.h
Normal file
39
tests/manual/highdpi/kitchensink/dragwidget.h
Normal file
@ -0,0 +1,39 @@
|
||||
// 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 DRAGWIDGET_H
|
||||
#define DRAGWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QBasicTimer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class DragWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
DragWidget(QString text = QString(), QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent * event) override;
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void hideEvent(QHideEvent *event) override;
|
||||
|
||||
private:
|
||||
QPoint dragPos;
|
||||
QPoint dropPos;
|
||||
QBasicTimer dragTimer;
|
||||
QBasicTimer dropTimer;
|
||||
QWidget *otherWindow = nullptr;
|
||||
};
|
||||
|
||||
#endif // DRAGWIDGET_H
|
18
tests/manual/highdpi/kitchensink/kitchensink.pro
Normal file
18
tests/manual/highdpi/kitchensink/kitchensink.pro
Normal file
@ -0,0 +1,18 @@
|
||||
TEMPLATE = app
|
||||
TARGET = kitchensink
|
||||
INCLUDEPATH += .
|
||||
QT += widgets gui-private
|
||||
CONFIG += cmdline
|
||||
CONFIG += c++11
|
||||
# Input
|
||||
SOURCES += \
|
||||
dragwidget.cpp \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
dragwidget.h
|
||||
|
||||
RESOURCES += \
|
||||
kitchensink.qrc
|
||||
|
||||
DEFINES += HAVE_SCREEN_BASE_DPI
|
10
tests/manual/highdpi/kitchensink/kitchensink.qrc
Normal file
10
tests/manual/highdpi/kitchensink/kitchensink.qrc
Normal file
@ -0,0 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qticon16.png</file>
|
||||
<file>qticon16@2x.png</file>
|
||||
<file>qticon16@3x.png</file>
|
||||
<file>qticon32.png</file>
|
||||
<file>qticon32@2x.png</file>
|
||||
<file>qticon64.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
1453
tests/manual/highdpi/kitchensink/main.cpp
Normal file
1453
tests/manual/highdpi/kitchensink/main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
tests/manual/highdpi/kitchensink/qticon16.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
tests/manual/highdpi/kitchensink/qticon16@2x.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon16@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
tests/manual/highdpi/kitchensink/qticon16@3x.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon16@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
tests/manual/highdpi/kitchensink/qticon32.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
tests/manual/highdpi/kitchensink/qticon32@2x.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon32@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
BIN
tests/manual/highdpi/kitchensink/qticon64.png
Normal file
BIN
tests/manual/highdpi/kitchensink/qticon64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
Reference in New Issue
Block a user