-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadratic_dialog.cpp
85 lines (68 loc) · 2.33 KB
/
quadratic_dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "quadratic_dialog.h"
#include "ui_quadratic_dialog.h"
#include <QGraphicsPixmapItem>
QuadraticDialog::QuadraticDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::QuadraticDialog),
userInput(0)
{
ui->setupUi(this);
// Disable window resizing by modifying window flags
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
setFixedSize(size());
setUpImage();
// Set the legend text
ui->labelLegend->setText("Solve quadratic equation to disable blocking. Write one of the correct roots of the equation.");
}
QuadraticDialog::~QuadraticDialog()
{
delete ui;
}
void QuadraticDialog::setUpImage()
{
// Initialize the QGraphicsScene
scene = new QGraphicsScene(this);
// Check if the scene is initialized correctly
if (!scene) {
qDebug() << "Failed to create QGraphicsScene";
return;
}
// Load the image
QPixmap pixmap(":/public/plant.png"); // Ensure the path matches your .qrc file
if (pixmap.isNull()) {
qDebug() << "Failed to load image";
return;
}
// Create a QGraphicsPixmapItem with the QPixmap
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
if (!item) {
qDebug() << "Failed to create QGraphicsPixmapItem";
return;
}
// Add the item to the scene
qDebug() << "Adding item to the scene";
scene->addItem(item);
// Set the scene to the QGraphicsView
ui->graphicsView->setScene(scene);
// Set the view to have a transparent background and no frame
ui->graphicsView->setStyleSheet("background: transparent; border: none;");
ui->graphicsView->setFrameShape(QFrame::NoFrame);
ui->graphicsView->setAttribute(Qt::WA_OpaquePaintEvent, false);
ui->graphicsView->setAttribute(Qt::WA_NoSystemBackground, true);
ui->graphicsView->setBackgroundBrush(Qt::NoBrush);
// Optionally, adjust the view's properties
ui->graphicsView->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
}
void QuadraticDialog::on_buttonBox_accepted()
{
userInput = ui->inputLineEdit->text().toInt();
}
int QuadraticDialog::getUserInput() const
{
return userInput;
}
void QuadraticDialog::setEquation(int a, int b, int c, int root1, int root2)
{
QString equation = QString("%1x^2 + %2x + %3 = 0").arg(a).arg(b).arg(c);
ui->equationLabel->setText(equation);
}