0e279295f
김태훈
수동 요리 구현
|
1
2
3
4
|
#include "reservetimepopup.h"
#include "ui_reservetimepopup.h"
#include <QDateTime>
|
f5634ecc7
김태훈
엔코더 구현
|
5
6
|
#include <QKeyEvent>
#include <QDebug>
|
0e279295f
김태훈
수동 요리 구현
|
7
8
|
#include "reservedtimepopup.h"
|
f5634ecc7
김태훈
엔코더 구현
|
9
|
#include "formatterspinbox.h"
|
0e279295f
김태훈
수동 요리 구현
|
10
11
12
13
14
15
16
17
18
19
|
ReserveTimePopup::ReserveTimePopup(QWidget *parent) :
QWidget(parent),
ui(new Ui::ReserveTimePopup)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
QDateTime dt = QDateTime::currentDateTime();
|
2576fd06a
김태훈
수동 요리 예약 디자인/동작 변경
|
20
21
|
ui->hour->setValue(1);
ui->min->setValue(0);
|
f5634ecc7
김태훈
엔코더 구현
|
22
23
24
25
26
27
28
29
30
31
|
connect(ui->keyboard, SIGNAL(onOkKeyClicked()), ui->keyboard, SLOT(focusOutKeyboard()));
connect(ui->keyboard, SIGNAL(onCancelKeyClicked()), ui->keyboard, SLOT(focusOutKeyboard()));
connect(ui->keyboard, SIGNAL(onCancelKeyClicked()), SLOT(revert()));
foreach (FormatterSpinBox *b, findChildren<FormatterSpinBox *>())
b->installEventFilter(this);
ui->min->setFocus();
ui->min->selectAll();
|
0e279295f
김태훈
수동 요리 구현
|
32
33
34
35
36
37
|
}
ReserveTimePopup::~ReserveTimePopup()
{
delete ui;
}
|
f5634ecc7
김태훈
엔코더 구현
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
bool ReserveTimePopup::eventFilter(QObject *watched, QEvent *event)
{
FormatterSpinBox *e = qobject_cast<FormatterSpinBox *>(watched);
if (e)
{
switch (event->type())
{
case QEvent::FocusIn:
lastValue = e->value();
break;
default:
break;
}
}
return false;
}
void ReserveTimePopup::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
|
01249f413
김태훈
엔코더 방향 반전. 하드웨어가 변경됨
|
60
|
case 0x01000032: // Turn left
|
f5634ecc7
김태훈
엔코더 구현
|
61
62
63
64
65
|
onEncoderLeft();
break;
case 0x01000031: // Push
pushed = focusWidget();
break;
|
01249f413
김태훈
엔코더 방향 반전. 하드웨어가 변경됨
|
66
|
case 0x01000030: // Turn right
|
f5634ecc7
김태훈
엔코더 구현
|
67
68
69
70
71
72
73
74
75
|
onEncoderRight();
break;
}
}
void ReserveTimePopup::keyReleaseEvent(QKeyEvent *event)
{
switch (event->key())
{
|
01249f413
김태훈
엔코더 방향 반전. 하드웨어가 변경됨
|
76
|
case 0x01000032: // Turn left
|
f5634ecc7
김태훈
엔코더 구현
|
77
78
79
80
81
82
83
84
|
onEncoderLeft();
break;
case 0x01000031: // Push
if (focusWidget() == pushed)
onEncoderClicked(pushed);
pushed = NULL;
break;
|
01249f413
김태훈
엔코더 방향 반전. 하드웨어가 변경됨
|
85
|
case 0x01000030: // Turn right
|
f5634ecc7
김태훈
엔코더 구현
|
86
87
88
89
90
91
92
93
94
95
96
97
98
|
onEncoderRight();
break;
}
}
void ReserveTimePopup::revert()
{
FormatterSpinBox *b = qobject_cast<FormatterSpinBox *>(focusWidget());
if (b)
b->setValue(lastValue);
qDebug() << lastValue;
}
|
0e279295f
김태훈
수동 요리 구현
|
99
100
|
void ReserveTimePopup::on_okButton_clicked()
{
|
2576fd06a
김태훈
수동 요리 예약 디자인/동작 변경
|
101
102
|
QDateTime target = QDateTime::currentDateTime()
.addSecs(ui->hour->value() * 3600 + ui->min->value() * 60);
|
0e279295f
김태훈
수동 요리 구현
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
ReservedTimePopup *p = new ReservedTimePopup(parentWidget(), target);
connect(p, SIGNAL(timeout()), SIGNAL(timeout()));
connect(p, SIGNAL(canceled()), SIGNAL(canceled()));
connect(p, SIGNAL(destroyed(QObject*)), SLOT(deleteLater()));
p->showFullScreen();
hide();
}
void ReserveTimePopup::on_cancelButton_clicked()
{
emit canceled();
close();
}
|
f5634ecc7
김태훈
엔코더 구현
|
118
119
120
|
void ReserveTimePopup::onEncoderLeft()
{
|
2576fd06a
김태훈
수동 요리 예약 디자인/동작 변경
|
121
|
if (focusWidget() == ui->hour)
|
f5634ecc7
김태훈
엔코더 구현
|
122
123
124
125
126
127
128
129
130
|
ui->cancelButton->setFocus();
else
focusPreviousChild();
}
void ReserveTimePopup::onEncoderRight()
{
if (focusWidget() == ui->cancelButton)
{
|
2576fd06a
김태훈
수동 요리 예약 디자인/동작 변경
|
131
132
|
ui->hour->setFocus();
ui->hour->selectAll();
|
f5634ecc7
김태훈
엔코더 구현
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
}
else
focusNextChild();
}
void ReserveTimePopup::onEncoderClicked(QWidget *clicked)
{
QPushButton *b = qobject_cast<QPushButton *>(clicked);
if (b)
b->click();
else
{
FormatterSpinBox *e = qobject_cast<FormatterSpinBox *>(clicked);
if (e)
{
qDebug() << "focusinkeyboard";
ui->keyboard->focusInKeyboard();
}
}
}
|