-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.h
163 lines (133 loc) · 5.09 KB
/
mainwindow.h
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QGraphicsView>
#include <QTimeEdit> // Add this line
#include <QSettings> // Add this line
class ZoomableGraphicsView; // Forward declaration
class MainWindow : public QWidget
{
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = nullptr);
void startSchedule();
void startNextTimerInSchedule();
void editSchedule();
QString getRandomImage(const QString& directory);
int levels; // Add this line
QImage posterizeImage(const QImage& image, int levels);
bool m_isBlurred = false;
bool scheduleActive; // Declare the scheduleActive member variable
QGraphicsLineItem* m_horizontalLine;
QGraphicsLineItem* m_verticalLine;
void updateLines();
private slots:
void onOpenButtonClicked();
void onHistoryButtonClicked();
void onNextButtonClicked();
void onFlipButtonClicked();
void onGrayscaleButtonClicked(); // Declare the onGrayscaleButtonClicked function
void onPosterizeButtonClicked(int levels);
void onDegradeButtonClicked();
void onMedianFilterButtonClicked();
private:
ZoomableGraphicsView* m_view; // Declare the m_view member variable
QGraphicsPixmapItem* m_originalPixmapItem; // Declare the m_originalPixmapItem member variable
QGraphicsPixmapItem* m_grayscalePixmapItem; // Declare the m_grayscalePixmapItem member variable
bool m_isGrayscale; // Declare the m_isGrayscale member variable
QFileInfoList m_files; // Add this line
int m_currentIndex = 0; // Add this line
void setDirectory(const QString& directory); // Add this line
QTime countdownTime;
bool isTimerRunning;
QTimer* timer;
QPixmap m_originalPixmap; // Store the original pixmap
QPixmap m_grayscalePixmap; // Store the grayscale pixmap
bool m_isPosterized; // Add this line
QPushButton* startTimerButton; // Add this line
QStringList directoryHistory;
bool m_isMedianFiltered; // Add this line
QList<QTime> schedule;
int currentScheduleIndex;
private:
void loadImageFromDirectory(const QString& directory);
QList<QTimer*> timers;
QSettings settings;
private:
QString m_directory;
protected:
void closeEvent(QCloseEvent* event) override;
};
#include <QDialog>
#include <QListWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QTime>
class ScheduleDialog : public QDialog {
Q_OBJECT
public:
ScheduleDialog(QWidget* parent = nullptr, const QList<QTime>& schedule = QList<QTime>())
: QDialog(parent), schedule(schedule) {
QVBoxLayout* layout = new QVBoxLayout(this);
// Create a QTimeEdit for time input
QTimeEdit* timeEdit = new QTimeEdit(this);
timeEdit->setDisplayFormat("hh:mm:ss");
layout->addWidget(timeEdit);
// Create a QListWidget to display the schedule
listWidget = new QListWidget(this); // Initialize the listWidget member variable
layout->addWidget(listWidget);
// Initialize the QListWidget with the schedule
for (const QTime& time : schedule) {
listWidget->addItem(time.toString("hh:mm:ss"));
}
// Create an "Add" button
QPushButton* addButton = new QPushButton("Add", this);
connect(addButton, &QPushButton::clicked, this, [=]() {
QTime time = timeEdit->time();
this->schedule.append(time);
listWidget->addItem(time.toString("hh:mm:ss"));
});
layout->addWidget(addButton);
QPushButton* removeButton = new QPushButton("Remove Timer", this);
connect(removeButton, &QPushButton::clicked, this, &ScheduleDialog::removeTimer);
layout->addWidget(removeButton);
QPushButton* okButton = new QPushButton("OK", this);
connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
layout->addWidget(okButton);
setLayout(layout);
}
QList<QTime> getSchedule() const {
QList<QTime> schedule;
for (int i = 0; i < listWidget->count(); ++i) {
schedule.append(QTime::fromString(listWidget->item(i)->text(), "hh:mm:ss"));
}
return schedule;
}
private slots:
void addTimer(QTime time) {
// Add a new timer to the list widget
listWidget->addItem(time.toString("hh:mm:ss"));
// Log the addition of the timer
qInfo() << "Added timer: " << QTime(0, 10).toString("hh:mm:ss");
qInfo() << "Current schedule: " << getSchedule();
}
void removeTimer() {
if (listWidget->currentRow() != -1) {
// Remove the currently selected timer from the list widget
QListWidgetItem* item = listWidget->takeItem(listWidget->currentRow());
QString itemText = item->text();
delete item;
// Log the removal of the timer
qInfo() << "Removed timer: " << itemText;
qInfo() << "Current schedule: " << getSchedule();
}
}
private:
QListWidget* listWidget;
QList<QTime> schedule;
QList<QTimer*> timers;
};
#endif // MAINWINDOW_H