2f6b55128
김태훈
다중 요리 구현
|
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
|
#include "multicookview.h"
#include <QMouseEvent>
#include <QPainter>
#include <QDebug>
MultiCookView::MultiCookView(QWidget *parent)
: QWidget(parent),
timePosition(0)
{
barPixmap.load(":/images/multi/bar.png");
connect(&checkTimer, SIGNAL(timeout()), SLOT(check()));
}
void MultiCookView::setContainer(MultiCookContainer *container)
{
this->container = container;
rects = calcRects();
checkTimer.start(33);
}
void MultiCookView::setTimeBar(MultiCookTimeBar *bar)
{
this->bar = bar;
}
void MultiCookView::showNow()
{
timePosition = 0;
updateView();
bar->showNow();
}
void MultiCookView::showNext()
{
if (timePosition < 0 || !nothingOnRight())
{
timePosition++;
updateView();
bar->showNext();
}
}
void MultiCookView::showPrev()
{
if (timePosition > 0)
{
timePosition--;
updateView();
bar->showPrev();
}
}
void MultiCookView::updateView()
{
rects = calcRects();
update();
}
void MultiCookView::mousePressEvent(QMouseEvent *event)
{
int x = event->x();
int y = event->y();
pressedSlot = calcSlot(x, y);
}
void MultiCookView::mouseReleaseEvent(QMouseEvent *event)
{
if (pressedSlot == -1)
return;
int x = event->x();
int y = event->y();
if (calcSlot(x, y) == pressedSlot)
emit clicked(pressedSlot);
}
void MultiCookView::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
paintGrids(painter);
paintBars(painter);
paintCurrentTime(painter);
}
void MultiCookView::resizeEvent(QResizeEvent *event)
{
rects = calcRects();
QWidget::resizeEvent(event);
}
void MultiCookView::check()
{
bool needUpdate = false;
QList<QRect> rects = calcRects();
for (int i = 0; i < 10; i++)
{
if (rects.at(i) != this->rects.at(i))
{
needUpdate = true;
break;
}
}
if (needUpdate)
{
this->rects = rects;
update();
}
}
QList<QRect> MultiCookView::calcRects()
{
int w = width();
int h = height();
int x = w * (2-timePosition) / 10 + 1;
|
2f6b55128
김태훈
다중 요리 구현
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
int w = width();
int h = height();
painter.setBrush(Qt::NoBrush);
painter.setPen(QColor(70,70,70));
for (int i = 1; i < 10; i++)
painter.drawLine(0, h * i / 10, w, h * i / 10);
for (int i = 1; i < 10; i++)
painter.drawLine(w * i / 10, padding, w * i / 10, h - padding);
}
void MultiCookView::paintBars(QPainter &painter)
{
for (int i = 0; i < 10; i++)
{
MultiCook *cook = container->at(i);
if (cook == Q_NULLPTR)
continue;
QRect r = rects.at(i);
if (!r.isNull())
paintBar(painter, r);
|
2f6b55128
김태훈
다중 요리 구현
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
static const int bodyOffset = headWidth;
static const int tailOffset = fullWidth - tailWidth;
int w = r.width();
if (w < tailWidth)
{
// Clip tail
QRect sourceRect(tailWidth - w + tailOffset, 0, w, height);
painter.drawPixmap(r, barPixmap, sourceRect);
}
else if (w < headWidth + tailWidth)
{
// Full tail
QRect sourceRect(tailOffset, 0, tailWidth, height);
QRect targetRect(r.x() + w - tailWidth, r.y(), tailWidth, height);
painter.drawPixmap(targetRect, barPixmap, sourceRect);
// Clip head
// sourceRect = QRect(0, 0, w - tailWidth, height);
// targetRect = QRect(r.x(), r.y(), w - tailWidth, height);
// painter.drawPixmap(targetRect, barPixmap, sourceRect);
sourceRect = QRect(headWidth - (w - tailWidth), 0, w - tailWidth, height);
targetRect = QRect(r.x(), r.y(), w - tailWidth, height);
painter.drawPixmap(targetRect, barPixmap, sourceRect);
}
else
{
// Full tail
QRect sourceRect(tailOffset, 0, tailWidth, height);
QRect targetRect(r.x() + w - tailWidth, r.y(), tailWidth, height);
painter.drawPixmap(targetRect, barPixmap, sourceRect);
// Full head
sourceRect = QRect(0, 0, headWidth, height);
targetRect = QRect(r.x(), r.y(), headWidth, height);
painter.drawPixmap(targetRect, barPixmap, sourceRect);
// Stretch body
sourceRect = QRect(bodyOffset, 0, bodyWidth, 0);
targetRect = QRect(r.x() + bodyOffset, r.y(), w - headWidth - tailWidth, height);
painter.drawPixmap(targetRect, barPixmap, sourceRect);
}
}
bool MultiCookView::nothingOnRight()
{
int rightMost = width() * 2 / 3;
foreach (QRect r, rects)
if (r.right() > rightMost)
return false;
return true;
}
|