-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockwindow.cpp
More file actions
125 lines (101 loc) · 3.08 KB
/
clockwindow.cpp
File metadata and controls
125 lines (101 loc) · 3.08 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
//
// Created by Asus on 09/03/2025.
//
// You may need to build the project (run Qt uic code generator) to get "ui_ClockWIndow.h" resolved
#include "clockwindow.h"
#include "ui_ClockWIndow.h"
#include <QTimer>
#include <QDateTime>
ClockWIndow::ClockWIndow(QWidget *parent) :
QWidget(parent), ui(new Ui::ClockWIndow), currentDateIndex(0), currentClockIndex(0), timerWindow(nullptr) {
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ClockWIndow::showTime);
timer->start(1000); // Aggiorna ogni secondo
connect(ui->changeFormat, &QPushButton::clicked, this, &ClockWIndow::changeDateFormat);
connect(ui->clockFormat, &QPushButton::clicked, this, &ClockWIndow::changeClockFormat);
connect(ui->openTimer, &QPushButton::clicked, this, &ClockWIndow::showTimerWindow);
showDate();
}
ClockWIndow::~ClockWIndow() {
delete ui;
delete timerWindow;
}
void ClockWIndow::showTime() {
QTime time = QTime::currentTime();
QString timeText = time.toString(formatsCLock[currentClockIndex]);
switch (currentClockIndex) {
case 0:
if((time.second()%2)==0){
timeText[3]=' ';
timeText[8]=' ';
}
break;
case 1:
if((time.second()%2)==0){
timeText[2]=' ';
timeText[5]=' ';
}
break;
case 2:
if((time.second()%2)==0)
timeText[2]=' ';
break;
case 3:
if((time.second()%2)==0)
timeText[2]=' ';
break;
}
ui->ClockLabel->setText(timeText);
}
void ClockWIndow::changeDateFormat() {
// Passa al formato successivo
currentDateIndex = (currentDateIndex + 1) % formatsDate.length();
showDate();
}
void ClockWIndow::changeClockFormat() {
currentClockIndex=(currentClockIndex+1)% formatsCLock.length(); // 4 formati
showTime();
}
void ClockWIndow::showTimerWindow() {
if (!timerWindow) {
timerWindow = new TimerWindow();
}
timerWindow->show();
}
int ClockWIndow::getCurrentDateIndex() const {
return currentDateIndex;
}
int ClockWIndow::getCurrentClockIndex() const {
return currentClockIndex;
}
TimerWindow *ClockWIndow::getTimerWindow() const {
return timerWindow;
}
QLabel *ClockWIndow::getClockLabel() const {
return ui->ClockLabel;
}
QLabel *ClockWIndow::getDateLabel() const {
return ui->DateLabel;
}
QString ClockWIndow::getClockLabelText() const {
return ui->ClockLabel->text();
}
QString ClockWIndow::getDateLabelText() const {
return ui->DateLabel->text();
}
void ClockWIndow::showDate() {
QDateTime date = QDateTime::currentDateTime();
QString dateText;
// Seleziona il formato corrente
dateText = date.toString(formatsDate[currentDateIndex]);
// Aggiorna l'etichetta con la data formattata
ui->DateLabel->setText(dateText);
}
// per il testing
const QStringList &ClockWIndow::getFormatsDate() const {
return formatsDate;
}
const QStringList &ClockWIndow::getFormatsCLock() const {
return formatsCLock;
}