-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimerwindow.cpp
More file actions
127 lines (103 loc) · 3.95 KB
/
timerwindow.cpp
File metadata and controls
127 lines (103 loc) · 3.95 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
//
// Created by Asus on 10/03/2025.
//
// You may need to build the project (run Qt uic code generator) to get "ui_TimerWindow.h" resolved
#include "timerwindow.h"
#include "ui_TimerWindow.h"
#include "titledialog.h"
TimerWindow::TimerWindow(QWidget *parent) :
QWidget(parent), ui(new Ui::TimerWindow) {
ui->setupUi(this);
setWindowTitle("Timer Manager");
soundType="sounds/alarm.wav";
genericTitle="Timer";
ui->timersList->setSelectionMode(QAbstractItemView::NoSelection);
ui->timersList->setUniformItemSizes(false);
ui->timersList->setSpacing(5);
ui->timersList->setStyleSheet("QListWidget { background-color: #2a2a2a; }");
connect(ui->startTimer, &QPushButton::clicked, this, &TimerWindow::addTimer);
connect(ui->menuButton, &QPushButton::clicked, this, &TimerWindow::selectSound);
connect(ui->titleButton, &QPushButton::clicked, this, &TimerWindow::showTitleEditor);
}
TimerWindow::~TimerWindow() {
delete ui;
}
void TimerWindow::removeTimer(TimerItem *timer) {
for (int i = 0; i < ui->timersList->count(); ++i) {
QListWidgetItem *item = ui->timersList->item(i);
if (ui->timersList->itemWidget(item) == timer) {
activeTimers.removeOne(timer);
delete item;
timer->deleteLater();
break;
}
}
}
void TimerWindow::selectSound() {
// Creazione del menu a tendina
QMenu* menu=new QMenu(ui->menuButton);
// Aggiunta delle opzioni al menu
QAction *opzione1 = menu->addAction("Default alarm");
QAction *opzione2 = menu->addAction("Rooster crowing");
QAction *opzione3 = menu->addAction("Retro game");
QAction *opzione4 = menu->addAction("Slot machine");
QAction *opzione5 = menu->addAction("Siren");
// Mostrare il menu accanto al pulsante quando viene premuto
QAction *selezionato = menu->exec(ui->menuButton->mapToGlobal(QPoint(0, ui->menuButton->height())));
// Verifica quale opzione è stata selezionata
if (selezionato) {
selectSoundOption(menu->actions().indexOf(selezionato));
}
}
void TimerWindow::addTimer() {
int hours = ui->hourSpinBox->value();
int minutes = ui->minSpinBox->value();
int seconds = ui->secondsSpinBox->value();
if (hours == 0 && minutes == 0 && seconds == 0) return; // Non aggiungere timer con 0 tempo
TimerItem *timer = new TimerItem(this);
timer->setMusicType(soundType);
timer->showTypeSound(ui->menuButton->text());
timer->setTitle(genericTitle);
timer->setDuration(hours, minutes, seconds);
timer->startTimer();
QListWidgetItem *item = new QListWidgetItem(ui->timersList);
item->setSizeHint(QSize(ui->timersList->width() - 10, 119));
ui->timersList->addItem(item);
ui->timersList->setItemWidget(item, timer);
ui->timersList->scrollToItem(item);
activeTimers.append(timer);
genericTitle="Timer";
connect(timer, &TimerItem::timerDeleted, this, &TimerWindow::removeTimer);
}
void TimerWindow::showTitleEditor() {
TitleDIalog dialog(this);
dialog.setTitle(genericTitle);
if (dialog.exec() == QDialog::Accepted) {
genericTitle = dialog.getTitle(); // Ottieni il titolo aggiornato
}
}
void TimerWindow::selectSoundOption(int index) {
QString soundsPath = "sounds/";
switch (index) {
case 0:
soundType = soundsPath + "alarm.wav";
ui->menuButton->setText("Default alarm");
break;
case 1:
soundType = soundsPath + "rooster-crowing.wav";
ui->menuButton->setText("Rooster crowing");
break;
case 2:
soundType = soundsPath + "retro-game.wav";
ui->menuButton->setText("Retro game");
break;
case 3:
soundType = soundsPath + "slot-machine.wav";
ui->menuButton->setText("Slot machine");
break;
case 4:
soundType = soundsPath + "siren.wav";
ui->menuButton->setText("Siren");
break;
}
}