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,19 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qgraphicsitemgroup Binary:
#####################################################################
qt_internal_add_manual_test(qgraphicsitemgroup
GUI
SOURCES
customitem.cpp customitem.h
main.cpp
widget.cpp widget.h widget.ui
LIBRARIES
Qt::Gui
Qt::Widgets
ENABLE_AUTOGEN_TOOLS
uic
)

View File

@ -0,0 +1,69 @@
// 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 "customitem.h"
#include <QPainter>
#include <QStyle>
#include <QStyleOption>
QList<CustomGroup*> CustomScene::selectedCustomGroups() const
{
QList<QGraphicsItem*> all = selectedItems();
QList<CustomGroup*> groups;
foreach (QGraphicsItem *item, all) {
CustomGroup* group = qgraphicsitem_cast<CustomGroup*>(item);
if (group)
groups.append(group);
}
return groups;
}
QList<CustomItem*> CustomScene::selectedCustomItems() const
{
QList<QGraphicsItem*> all = selectedItems();
QList<CustomItem*> items;
foreach (QGraphicsItem *item, all) {
CustomItem* citem = qgraphicsitem_cast<CustomItem*>(item);
if (citem)
items.append(citem);
}
return items;
}
CustomGroup::CustomGroup() :
QGraphicsItemGroup()
{
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
}
void CustomGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
if (option->state & QStyle::State_Selected)
painter->setOpacity(1.);
else
painter->setOpacity(0.2);
painter->setPen(QPen(QColor(100, 100, 100), 2, Qt::DashLine));
painter->drawRect(boundingRect().adjusted(-2, -2, 2, 2));
}
QRectF CustomGroup::boundingRect() const
{
return QGraphicsItemGroup::boundingRect().adjusted(-4, -4, 4 ,4);
}
CustomItem::CustomItem(qreal x, qreal y, qreal width, qreal height, const QBrush &brush) :
QGraphicsRectItem(x, y, width, height)
{
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setBrush(brush);
setPen(Qt::NoPen);
setTransformOriginPoint(boundingRect().center());
}

View 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 CUSTOMITEM_H
#define CUSTOMITEM_H
#include <QGraphicsItem>
#include <QBrush>
#include <QGraphicsScene>
class CustomGroup : public QGraphicsItemGroup
{
public:
CustomGroup();
virtual ~CustomGroup() { }
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QRectF boundingRect() const;
};
class CustomItem : public QGraphicsRectItem
{
public:
CustomItem(qreal x, qreal y, qreal width, qreal height, const QBrush & brush = QBrush());
virtual ~CustomItem() { }
};
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public:
CustomScene() : QGraphicsScene() { }
QList<CustomItem*> selectedCustomItems() const;
QList<CustomGroup*> selectedCustomGroups() const;
};
#endif // CUSTOMITEM_H

View File

@ -0,0 +1,13 @@
// 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 "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,9 @@
TARGET = qgraphicsitemgroup
QT += widgets
TEMPLATE = app
SOURCES += main.cpp \
widget.cpp \
customitem.cpp
HEADERS += widget.h \
customitem.h
FORMS += widget.ui

View File

@ -0,0 +1,222 @@
// 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 "widget.h"
#include "ui_widget.h"
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget),
previousSelectionCount(0)
{
ui->setupUi(this);
effect = new QGraphicsOpacityEffect;
effect->setOpacity(0.3);
ui->groupBox->setGraphicsEffect(effect);
fadeIn = new QPropertyAnimation(effect, "opacity");
fadeIn->setDuration(200);
fadeIn->setStartValue(0.3);
fadeIn->setEndValue(1.);
fadeOut = new QPropertyAnimation(effect, "opacity");
fadeOut->setDuration(200);
fadeOut->setStartValue(1.);
fadeOut->setEndValue(0.3);
scene = new CustomScene;
scene->setSceneRect(-250,-250,500,500);
ui->view->setScene(scene);
scene->setBackgroundBrush(Qt::white);
ui->view->setInteractive(true);
ui->view->setDragMode(QGraphicsView::RubberBandDrag);
ui->view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
ui->view->setRenderHints( QPainter::SmoothPixmapTransform |
QPainter::TextAntialiasing |
QPainter::Antialiasing );
rectBlue = new CustomItem(-100, -100, 50, 50, QColor(80, 80, 200));
scene->addItem(rectBlue);
rectGreen = new CustomItem(100, -100, 50, 50, QColor(80, 200, 80));
scene->addItem(rectGreen);
rectRed = new CustomItem(-100, 100, 50, 50, QColor(200, 80, 80));
scene->addItem(rectRed);
rectYellow = new CustomItem(100, 100, 50, 50, QColor(200, 200, 20));
scene->addItem(rectYellow);
connect(scene, SIGNAL(selectionChanged()), this, SLOT(onSceneSelectionChanged()));
}
Widget::~Widget()
{
delete ui;
delete fadeIn;
delete fadeOut;
}
void Widget::on_rotate_valueChanged(int value)
{
if (scene->selectedItems().count() != 1)
return;
QGraphicsItem *item = scene->selectedItems().at(0);
item->setRotation(value);
ui->rotateItem->setValue(checkedItem()->rotation());
}
void Widget::on_scale_valueChanged(int value)
{
if (scene->selectedItems().count() != 1)
return;
QGraphicsItem *item = scene->selectedItems().at(0);
item->setScale(value / 10.);
ui->scaleItem->setValue(checkedItem()->scale() * 10);
}
void Widget::on_rotateItem_valueChanged(int value)
{
if (!scene->selectedItems().empty() && scene->selectedItems().at(0) == checkedItem())
ui->rotate->setValue(value);
else
checkedItem()->setRotation(value);
}
void Widget::on_scaleItem_valueChanged(int value)
{
if (!scene->selectedItems().empty() && scene->selectedItems().at(0) == checkedItem())
ui->scale->setValue(value);
else
checkedItem()->setScale(value / 10.);
}
void Widget::on_group_clicked()
{
QList<QGraphicsItem*> all = scene->selectedItems();
if (all.size() < 2)
return;
QList<CustomItem*> items = scene->selectedCustomItems();
QList<CustomGroup*> groups = scene->selectedCustomGroups();
if (groups.size() == 1) {
foreach (CustomItem *item, items) {
item->setSelected(false);
groups[0]->addToGroup(item);
}
return;
}
CustomGroup* group = new CustomGroup;
scene->addItem(group);
foreach (QGraphicsItem *item, all) {
item->setSelected(false);
group->addToGroup(item);
}
group->setSelected(true);
updateUngroupButton();
}
void Widget::on_dismantle_clicked()
{
QList<CustomGroup*> groups = scene->selectedCustomGroups();
foreach (CustomGroup *group, groups) {
foreach (QGraphicsItem *item, group->childItems())
group->removeFromGroup(item);
delete group;
}
updateUngroupButton();
}
void Widget::on_merge_clicked()
{
QList<CustomGroup*> groups = scene->selectedCustomGroups();
if (groups.size() < 2)
return;
CustomGroup *newBigGroup = groups.takeFirst();
foreach (CustomGroup *group, groups) {
foreach (QGraphicsItem *item, group->childItems())
item->setGroup(newBigGroup);
delete group;
}
}
void Widget::onSceneSelectionChanged()
{
QList<QGraphicsItem*> all = scene->selectedItems();
QList<CustomGroup*> groups = scene->selectedCustomGroups();
if (all.empty() && all.count() != previousSelectionCount) {
fadeOut->start();
} else if (previousSelectionCount == 0) {
fadeIn->start();
}
if (all.count() == 1) {
QGraphicsItem *item = all.at(0);
ui->rotate->setValue(item->rotation());
ui->scale->setValue(item->scale() * 10);
} else {
ui->rotate->setValue(ui->rotate->minimum());
ui->scale->setValue(ui->scale->minimum());
}
ui->rotate->setEnabled(all.size() == 1);
ui->scale->setEnabled(all.size() == 1);
ui->group->setEnabled(all.size() > 1);
ui->dismantle->setEnabled(!groups.empty());
ui->merge->setEnabled(groups.size() > 1);
previousSelectionCount = all.size();
updateUngroupButton();
}
void Widget::on_ungroup_clicked()
{
QGraphicsItemGroup *oldGroup = checkedItem()->group();
checkedItem()->setGroup(0);
if (oldGroup && oldGroup->childItems().empty())
delete oldGroup;
updateUngroupButton();
}
void Widget::updateUngroupButton()
{
ui->ungroup->setEnabled(checkedItem()->group() != 0);
}
CustomItem * Widget::checkedItem() const
{
CustomItem *item = nullptr;
if (ui->blue->isChecked())
item = rectBlue;
else if (ui->red->isChecked())
item = rectRed;
else if (ui->green->isChecked())
item = rectGreen;
else if (ui->yellow->isChecked())
item = rectYellow;
return item;
}
void Widget::on_buttonGroup_buttonClicked()
{
ui->rotateItem->setValue(checkedItem()->rotation());
ui->scaleItem->setValue(checkedItem()->scale() * 10);
updateUngroupButton();
}

View File

@ -0,0 +1,55 @@
// 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 WIDGET_H
#define WIDGET_H
#include "customitem.h"
#include <QWidget>
#include <QGraphicsItemGroup>
#include <QPainter>
namespace Ui {
class Widget;
}
class QGraphicsOpacityEffect;
class QPropertyAnimation;
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
protected Q_SLOTS:
void on_rotate_valueChanged(int value);
void on_scale_valueChanged(int value);
void on_rotateItem_valueChanged(int value);
void on_scaleItem_valueChanged(int value);
void on_group_clicked();
void on_dismantle_clicked();
void on_merge_clicked();
void onSceneSelectionChanged();
void on_ungroup_clicked();
void on_buttonGroup_buttonClicked();
private:
void updateUngroupButton();
CustomItem * checkedItem() const;
Ui::Widget *ui;
CustomScene *scene;
CustomItem *rectBlue;
CustomItem *rectRed;
CustomItem *rectGreen;
CustomItem *rectYellow;
QGraphicsOpacityEffect* effect;
QPropertyAnimation *fadeIn;
QPropertyAnimation *fadeOut;
int previousSelectionCount;
};
#endif // WIDGET_H

View File

@ -0,0 +1,319 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>782</width>
<height>695</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Items</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QRadioButton" name="blue">
<property name="text">
<string>Blue</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="red">
<property name="text">
<string>Red</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="green">
<property name="text">
<string>Green</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="yellow">
<property name="text">
<string>Yellow</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Rotate</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="rotateItem">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="scaleItem">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="ungroup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ungroup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>164</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>164</height>
</size>
</property>
<property name="title">
<string>Selection</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Rotate</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="rotate">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="scale">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="group">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Group</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="merge">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Merge Groups</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dismantle">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Dismantle Group</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGraphicsView" name="view"/>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>