cookpanelbutton.cpp
2.31 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
#include "cookpanelbutton.h"
#include "ui_cookpanelbutton.h"
#include "soundplayer.h"
#include "manualcooksettingwidget.h"
CookPanelButton::CookPanelButton(CookRecord record, QWidget *parent) :
QWidget(parent),
record(record),
ui(new Ui::CookPanelButton),
rendered(false),
longPressEnabled(false)
{
ui->setupUi(this);
setText(record.name);
foreach (QPushButton *button, findChildren<QPushButton *>())
connect(button, &QPushButton::pressed, SoundPlayer::playClick);
longPressedTimer.setSingleShot(true);
longPressedTimer.setInterval(3000);
connect(&longPressedTimer, SIGNAL(timeout()), SLOT(emitLongPressed()));
}
CookPanelButton::~CookPanelButton()
{
delete ui;
}
void CookPanelButton::setText(QString text)
{
ui->pushButton->setText(text);
}
void CookPanelButton::showInfo()
{
if (!rendered)
{
QPixmap p = CookHistory::render(record);
label = new QLabel(this);
label->setPixmap(p);
label->setGeometry((width() - p.width()) / 2, 65, p.width(), p.height());
}
label->show();
setMinimumHeight(ui->pushButton->height() + label->height());
}
void CookPanelButton::hideInfo()
{
label->hide();
setMinimumHeight(ui->pushButton->height());
}
void CookPanelButton::focusBar()
{
ui->pushButton->setFocus();
}
void CookPanelButton::focusInfoButton()
{
ui->showInfoButton->setFocus();
}
void CookPanelButton::focusDeleteButton()
{
ui->deleteButton->setFocus();
}
void CookPanelButton::setLongPressEnabled(bool enabled)
{
longPressEnabled = enabled;
}
void CookPanelButton::setEnabled(bool enabled)
{
ui->pushButton->setEnabled(enabled);
ui->showInfoButton->setEnabled(enabled);
ui->deleteButton->setEnabled(enabled);
}
void CookPanelButton::emitLongPressed()
{
emitted = true;
emit longPressed(this);
}
void CookPanelButton::on_showInfoButton_clicked()
{
emit infoClicked(this);
}
void CookPanelButton::on_pushButton_clicked()
{
if (longPressEnabled && emitted)
return;
CookHistory::start(record, parentWidget());
}
void CookPanelButton::on_deleteButton_clicked()
{
emit deleteClicked(this);
}
void CookPanelButton::on_pushButton_pressed()
{
longPressedTimer.start();
emitted = false;
}
void CookPanelButton::on_pushButton_released()
{
longPressedTimer.stop();
}