This repository was archived by the owner on Dec 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
191 lines (161 loc) · 6.45 KB
/
mainwindow.cpp
File metadata and controls
191 lines (161 loc) · 6.45 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* @file mainwindow.cpp
* @author G. Maxime
* @brief Implémentation de la classe MainWindow pour l'interface principale de l'application.
* Cette classe hérite de QMainWindow et gère l'interface utilisateur principale,
* y compris l'affichage de la matrice LED, la saisie de texte, la sélection de couleur
* et le contrôle du mode horloge.
*/
// Inclusion de mes headers
#include "headers/mainwindow.h"
#include "headers/matrixdisplay.h"
// Inclusion des headers Qt nécessaires
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QWidget>
#include <QCheckBox>
#include <QColorDialog>
#include <QShortcut>
#include <QKeySequence>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
defaultText(QStringLiteral("HELLO WORLD!"))
{
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
matrixDisplay = new MatrixDisplay(this);
mainLayout->addWidget(matrixDisplay);
controlsWidget = new QWidget(this);
QHBoxLayout *controlsLayout = new QHBoxLayout(controlsWidget);
textInput = new QLineEdit(this);
textInput->setPlaceholderText("Enter text to display");
controlsLayout->addWidget(textInput);
updateButton = new QPushButton("Update Text", this);
controlsLayout->addWidget(updateButton);
QPushButton *colorButton = new QPushButton("Change Pixel Color", this);
controlsLayout->addWidget(colorButton);
QPushButton *colorButton_Background = new QPushButton("Change Background Color", this);
controlsLayout->addWidget(colorButton_Background);
clockCheckBox = new QCheckBox("Show Clock", this);
controlsLayout->addWidget(clockCheckBox);
scrollCheckBox = new QCheckBox("Scroll", this);
controlsLayout->addWidget(scrollCheckBox);
bounceCheckBox = new QCheckBox("Bounce Scroll", this);
controlsLayout->addWidget(bounceCheckBox);
speedLabel = new QLabel("Speed:", this);
controlsLayout->addWidget(speedLabel);
speedSlider = new QSlider(Qt::Horizontal, this);
speedSlider->setRange(1, 5);
speedSlider->setValue(2);
speedSlider->setSingleStep(1);
speedSlider->setToolTip("Adjust Scroll Speed");
connect(speedSlider, &QSlider::valueChanged, [this](int value) {
if (matrixDisplay) {
matrixDisplay->setScrollInterval(value);
}
});
controlsLayout->addWidget(speedSlider);
mainLayout->addWidget(controlsWidget);
// Ajout du raccourci clavier Ctrl+H pour afficher/masquer les contrôles
auto *toggleShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+H")), this);
toggleShortcut->setContext(Qt::ApplicationShortcut);
connect(toggleShortcut, &QShortcut::activated, this, &MainWindow::toggleControlsVisibility);
// Connexions des signaux du controllLayout aux slots
connect(updateButton, &QPushButton::clicked, this, &MainWindow::updateMatrixText);
connect(textInput, &QLineEdit::returnPressed, this, &MainWindow::updateMatrixText);
connect(colorButton, &QPushButton::clicked, this, &MainWindow::openColorPicker);
connect(colorButton_Background, &QPushButton::clicked, this, &MainWindow::openColorPicker_Background);
connect(clockCheckBox, &QCheckBox::toggled, this, &MainWindow::toggleClock);
connect(scrollCheckBox, &QCheckBox::toggled, matrixDisplay, &MatrixDisplay::setScrollEnabled);
connect(scrollCheckBox, &QCheckBox::toggled, this, &MainWindow::toggleSpeedControlVisibility);
connect(scrollCheckBox, &QCheckBox::toggled, this, &MainWindow::toggleBounceCheckboxVisibility);
connect(bounceCheckBox, &QCheckBox::toggled, [this](bool checked){
if (matrixDisplay) {
if (checked) {
matrixDisplay->setScrollMode(MatrixDisplay::bounceMode);
} else {
matrixDisplay->setScrollMode(MatrixDisplay::defaultMode);
}
}
});
setWindowTitle("Matrix Display");
resize(900, 220);
matrixDisplay->setText(defaultText);
textInput->setText(defaultText);
scrollCheckBox->setChecked(matrixDisplay->requiresScrolling());
}
MainWindow::~MainWindow() {}
void MainWindow::updateMatrixText()
{
matrixDisplay->setText(textInput->text());
bool needsScroll = matrixDisplay->requiresScrolling();
if (scrollCheckBox->isChecked() != needsScroll) {
scrollCheckBox->setChecked(needsScroll);
}
}
void MainWindow::openColorPicker()
{
QColor color = QColorDialog::getColor(Qt::green, this, "Choose Pixel Color");
if (color.isValid()) {
matrixDisplay->setColor(color);
}
}
void MainWindow::openColorPicker_Background()
{
QColor color = QColorDialog::getColor(Qt::darkGray, this, "Choose Background Color");
if (color.isValid()) {
matrixDisplay->setColor_Background(color);
}
}
void MainWindow::toggleClock(bool checked)
{
if (checked) {
scrollCheckBox->setChecked(false);
scrollCheckBox->setVisible(false);
matrixDisplay->setScrollEnabled(false);
matrixDisplay->setDisplayMode(MatrixDisplay::Clock);
textInput->setEnabled(false);
textInput->setVisible(false);
this->toggleSpeedControlVisibility();
this->toggleBounceCheckboxVisibility();
this->updateButton->setVisible(false);
} else {
scrollCheckBox->setVisible(true);
textInput->setVisible(true);
matrixDisplay->setDisplayMode(MatrixDisplay::Text);
if (textInput->text().trimmed().isEmpty()) {
textInput->setText(defaultText);
}
matrixDisplay->setText(textInput->text());
bool needsScroll = matrixDisplay->requiresScrolling();
if (scrollCheckBox->isChecked() != needsScroll) {
scrollCheckBox->setChecked(needsScroll);
}
textInput->setEnabled(true);
this->updateButton->setVisible(true);
this->toggleSpeedControlVisibility();
this->toggleBounceCheckboxVisibility();
}
}
void MainWindow::toggleControlsVisibility()
{
if (!controlsWidget) return;
controlsWidget->setVisible(!controlsWidget->isVisible());
}
void MainWindow::toggleSpeedControlVisibility()
{
if (!speedSlider) return;
speedSlider->setVisible(scrollCheckBox->isChecked());
speedLabel->setVisible(scrollCheckBox->isChecked());
}
void MainWindow::toggleBounceCheckboxVisibility()
{
if (scrollCheckBox->isChecked())
bounceCheckBox->setVisible(true);
else
bounceCheckBox->setVisible(false);
}