#include "mainwindow.h"
#include <QMenuBar>
#include <QInputDialog>
#include <QDialogButtonBox>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QVBoxLayout>
#include <QGraphicsPolygonItem>
#include <QGraphicsItem>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("QT-GI-15");

// Создание QGraphicsView для отображения
scene = new QGraphicsScene();
QGraphicsItem *item = new QGraphicsRectItem();
scene->addItem(item);
view = new QGraphicsView(scene);
setCentralWidget(view);

// Создание меню с действиями
QMenu *fileMenu = new QMenu("File");
showPictureAction = new QAction("Show picture");
connect(showPictureAction, &QAction::triggered, this, &MainWindow::showPicture);
fileMenu->addAction(showPictureAction);

chooseAction = new QAction("Choose");
connect(chooseAction, &QAction::triggered, this, &MainWindow::choose);
fileMenu->addAction(chooseAction);

animateAction = new QAction("Animate");
connect(animateAction, &QAction::triggered, this, &MainWindow::animate);
fileMenu->addAction(animateAction);

stopAction = new QAction("Stop");
connect(stopAction, &QAction::triggered, this, &MainWindow::stop);
fileMenu->addAction(stopAction);

quitAction = new QAction("Quit");
connect(quitAction, &QAction::triggered, this, &MainWindow::quit);
fileMenu->addAction(quitAction);

menuBar()->addMenu(fileMenu);

// Создание окна выбора
chooseDialog = new QDialog();
chooseDialog->setWindowTitle("Choose");
speedLabel = new QLabel("Speed:");
directionLabel = new QLabel("Direction:");
upDownRadioButton = new QRadioButton("Up-Down");
leftRightRadioButton = new QRadioButton("Left-Right");
speedLineEdit = new QLineEdit();
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, chooseDialog, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, chooseDialog, &QDialog::reject);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(speedLabel);
layout->addWidget(speedLineEdit);
layout->addWidget(directionLabel);
layout->addWidget(upDownRadioButton);
layout->addWidget(leftRightRadioButton);
layout->addWidget(buttonBox);
chooseDialog->setLayout(layout);
}

MainWindow::~MainWindow()
{
delete chooseDialog;
delete scene;
delete view;
}

void MainWindow::showPicture()
{
// Очистка сцены и создание объекта для отображения
scene->clear();

QBrush brush(Qt::red);
QPen blackpen(Qt::black);
blackpen.setWidth(2);
QGraphicsRectItem *rect = new QGraphicsRectItem(-50, -25, 100, 50);
rect->setBrush(brush);
rect->setPen(blackpen);
QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem(-30, -20, 60, 40);
ellipse->setBrush(brush);
ellipse->setPen(blackpen);
QPolygonF triangle;
triangle << QPointF(0, -25) << QPointF(-25, 25) << QPointF(25, 25);
QGraphicsPolygonItem *polygon = new QGraphicsPolygonItem(triangle);
polygon->setBrush(brush);
polygon->setPen(blackpen);

QVector<QPointF> trapeziumPoints;
trapeziumPoints << QPointF(-50, -25) << QPointF(50, -25) << QPointF(30, 25) << QPointF(-30, 25);
QGraphicsPolygonItem *trapezium = new QGraphicsPolygonItem(QPolygonF(trapeziumPoints), item);
trapezium->setPen(QPen(Qt::black));

trapezium->setBrush(QBrush(Qt::red));
QGraphicsPolygonItem *polygonObj = new QGraphicsPolygonItem(QPolygonF(triangle), item);
polygonObj->setPen(QColor(Qt::black));;
polygonObj->setBrush(Qt::red);


QGraphicsItemGroup *item = new QGraphicsItemGroup();
item->addToGroup(rect);
item->addToGroup(ellipse);
item->addToGroup(polygon);
item->addToGroup(trapezium);
item->setPos(0, 0);
scene->addItem(item);

// Центрирование объекта
int x = (view->viewport()->width() - item->boundingRect().width()) / 2;
int y = (view->viewport()->height() - item->boundingRect().height()) / 2;
item->setPos(x, y);
}

void MainWindow::choose()
{
// Отображение окна выбора
if (chooseDialog->exec() == QDialog::Accepted) {
// Задание направления движения объекта
int angle;
if (upDownRadioButton->isChecked()) {
angle = 90;
} else {
angle = 0;
}

// Задание скорости движения объекта
int speed = speedLineEdit->text().toInt();

// Запись параметров движения в свойства объекта
item->setData(0, angle);
item->setData(1, speed);
}
}

void MainWindow::animate()
{
// Проверка наличия объекта на сцене
    if (item == nullptr) {
    return;
    }

// Циклическое перемещение объекта на заданную угловую дистанцию
int start = 0;
int end = 200;
int angle = item->setData("angle").toInt();

QPropertyAnimation animation = new QPropertyAnimation(item, "pos");
animation->setDuration(1000 / item->property("speed").toInt() * (end - start));
animation->setLoopCount(-1);
animation->setEasingCurve(QEasingCurve::Linear);

QList<QVariant> values1;
values1.append(QVariant(QPointF(0, 0)));
values1.append(QVariant(QPointF(end * qCos(qDegreesToRadians(angle)), end * qSin(qDegreesToRadians(angle)))));
animation->setKeyValueAt(0, values1);

QList<QVariant> values2;
values2.append(QVariant(QPointF(end * qCos(qDegreesToRadians(angle)), end * qSin(qDegreesToRadians(angle)))));
values2.append(QVariant(QPointF(0, 0)));
animation->setKeyValueAt(1, values2);

animation->start();
}

void MainWindow::stop()
{
// Остановка анимации
QList<QPropertyAnimation> animations = item->property("animations").value<QList<QPropertyAnimation>>();
foreach (QPropertyAnimation *animation, animations) {
animation->stop();
}
}

void MainWindow::quit()
{
// Завершение приложения
QApplication::exit();
}

/home/abdugaffor/Case/Qt projects/untitled/mainwindow.cpp:151: ошибка: too few arguments to function call, expected 2, have 1