#include "mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
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 trapeziumPoints;
trapeziumPoints << QPointF(-50, -25);
}
ошибка: mainwindow.o: in function `MainWindow::MainWindow(QWidget*)':