-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrawcam.cpp
396 lines (315 loc) · 13.8 KB
/
rawcam.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/** \file */
#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSlider>
#include <QFile>
#include <QTimer>
#include <QButtonGroup>
#include <QSlider>
#include <QDebug>
#include <QSettings>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeContext>
#include <QPropertyAnimation>
#include "CameraThread.h"
#include "ExampleOverlayWidget.h"
#include "myproximitysensor.h"
#include "CameraParameters.h"
#include "dot.h"
#include "feedback.h"
QTM_USE_NAMESPACE
/***********************************************************/
/* Full camera application */
/* */
/* This example uses QT to create a full camera */
/* application for the N9. It displays viewfinder frames */
/* using an fbdev overlay. */
/***********************************************************/
QString readFile(QString filename) {
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return NULL;
}
QByteArray total;
QByteArray line;
while (!file.atEnd()) {
line = file.read(1024);
total.append(line);
}
return QString(total);
}
//void QTest::qSleep(int ms)
//{
// struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
// nanosleep(&ts, NULL);
//}
int main(int argc, char **argv) {
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("oob");
QCoreApplication::setApplicationName("rawcam");
// Make the main window
QWidget *window = new QWidget;
QSettings settings;
QHBoxLayout *layout = new QHBoxLayout(window);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
// app.setStyleSheet(readFile("/opt/rawcam/style.css"));
window->setStyleSheet(readFile("/opt/rawcam/style.css"));
ExampleOverlayWidget *overlay = new ExampleOverlayWidget();
// Make a thread that controls the camera
CameraThread* cameraThread = new CameraThread(overlay);
//overlay->setFixedSize(854, 480);
layout->addWidget(overlay);
QPushButton* w = new QPushButton();
w->setFixedSize(1,480);
w->setObjectName("w");
//w->setStyleSheet("background-color:transparent");
layout->addWidget(w);
// gallery button
QPushButton* gallery = new QPushButton("", window);
gallery->move(780, 60);
gallery->setObjectName("gallery");
gallery->hide();
// settings button
QPushButton* settingsBtn = new QPushButton("", window);
settingsBtn->move(780, 340);
settingsBtn->setObjectName("settings");
// shutter button
QPushButton* shutter = new QPushButton(QIcon("/opt/rawcam/shutter.png"),"",window);
shutter->setIconSize(QSize(90,90));
shutter->move(750,200);
shutter->setObjectName("shutter");
QObject::connect(shutter, SIGNAL(pressed()), cameraThread, SLOT(focus_on_tap()));
QObject::connect(shutter, SIGNAL(released()), cameraThread, SLOT(snapshot()));
// t->setStyleSheet("min-height: 100px;"
// "border-style: outset;"
// "border-width: 2px;"
// "border-color: beige;" );
MyProximitySensor *prx = new MyProximitySensor();
QObject::connect(prx, SIGNAL(sensorClosed()), cameraThread, SLOT(focus_on()));
// QObject::connect(prx, SIGNAL(sensorOpen()), cameraThread, SLOT(focus_off()));
prx->start();
//exposure info label
QLabel* exposureInfo = new QLabel(window);
exposureInfo->move(720,435);
exposureInfo->setAlignment(Qt::AlignRight);
exposureInfo->setFont(QFont("Nokia Pure Text", 20, 200, false));
QObject::connect(cameraThread,SIGNAL(exposureInfo(QString)), exposureInfo, SLOT(setText(QString)));
//gain info label
QLabel* gainInfo = new QLabel(window);
gainInfo->move(700,395);
gainInfo->resize(120, 30);
gainInfo->setAlignment(Qt::AlignRight);
gainInfo->setFont(QFont("Nokia Pure Text", 20, 200, false));
QObject::connect(cameraThread,SIGNAL(gainInfo(QString)), gainInfo, SLOT(setText(QString)));
//photo captured notification
QLabel* success = new QLabel("Photo captured",window);
success->move(50,50);
success->resize(754, 50);
success->setFont(QFont("Nokia Pure Text", 20, 200, false));
success->hide();
success->setObjectName("success");
QTimer* successTimer = new QTimer();
successTimer->setSingleShot(true);
successTimer->setInterval(4000);
QObject::connect(successTimer, SIGNAL(timeout()), success, SLOT(hide()));
QObject::connect(cameraThread->feedback.msgr,SIGNAL(photoTaken()), success, SLOT(show()));
QObject::connect(cameraThread->feedback.msgr,SIGNAL(photoTaken()), successTimer, SLOT(start()));
CameraParameters* params = cameraThread->parameters;
QObject::connect(cameraThread, SIGNAL(pictureSaved(QString)), gallery, SLOT(show()));
QObject::connect(cameraThread, SIGNAL(pictureSaved(QString)), params, SLOT(setLastPicture(QString)));
QObject::connect(gallery,SIGNAL(clicked()), params, SLOT(openLastPicture()));
// flash control
QButtonGroup* flash = new QButtonGroup(window);
flash->setExclusive(true);
QPushButton* noflash = new QPushButton("", window);
noflash->move(405, 15);
noflash->setObjectName("noflash");
noflash->setCheckable(true);
noflash->setChecked(true);
QPushButton* flashHalf = new QPushButton("", window);
flashHalf->move(450, 15);
flashHalf->setObjectName("flashHalf");
flashHalf->setCheckable(true);
flashHalf->setChecked(false);
QPushButton* flashFull = new QPushButton("", window);
flashFull->move(495, 15);
flashFull->setObjectName("flashFull");
flashFull->setCheckable(true);
flashFull->setChecked(false);
flash->addButton(noflash);
flash->addButton(flashHalf);
flash->addButton(flashFull);
QPushButton* backCurtain = new QPushButton("", window);
backCurtain->move(555, 15);
backCurtain->setObjectName("backCurtain");
backCurtain->setCheckable(true);
backCurtain->setChecked(false);
QObject::connect(noflash,SIGNAL(clicked()), params, SLOT(setFlashOff()));
QObject::connect(flashHalf,SIGNAL(clicked()), params, SLOT(setFlashHalf()));
QObject::connect(flashFull,SIGNAL(clicked()), params, SLOT(setFlashFull()));
QObject::connect(backCurtain,SIGNAL(toggled(bool)), params, SLOT(setBackCurtain(bool)));
// exposure control
QButtonGroup* exp = new QButtonGroup(window);
exp->setExclusive(true);
QPushButton* p = new QPushButton("P", window);
p->setFont(QFont("Nokia Pure Text", 30, 200, false));
p->move(30, 10);
p->setCheckable(true);
p->setChecked(true);
QPushButton* s = new QPushButton("S", window);
s->setFont(QFont("Nokia Pure Text", 30, 200, false));
s->move(90, 10);
s->setCheckable(true);
s->setChecked(false);
QPushButton* iso = new QPushButton("I", window);
iso->setFont(QFont("Nokia Pure Text", 30, 200, false));
iso->move(150, 10);
iso->setCheckable(true);
iso->setChecked(false);
QPushButton* m = new QPushButton("M", window);
m->setFont(QFont("Nokia Pure Text", 30, 200, false));
m->move(210,10);
m->setCheckable(true);
m->setChecked(false);
exp->addButton(p);
exp->addButton(m);
exp->addButton(s);
exp->addButton(iso);
// exposure slider
QSlider* expSlider = new QSlider(Qt::Horizontal, window);
expSlider->resize(750,40);
expSlider->move(80, 430);
expSlider->hide();
expSlider->setMinimum(0);
expSlider->setMaximum(1000);
expSlider->setValue(500);
// gain slider
QSlider* gainSlider = new QSlider(Qt::Horizontal, window);
gainSlider->resize(750,40);
gainSlider->move(80, 390);
gainSlider->hide();
gainSlider->setMinimum(0);
gainSlider->setMaximum(1000);
gainSlider->setValue(500);
QObject::connect(p,SIGNAL(clicked()), expSlider, SLOT(hide()));
QObject::connect(p,SIGNAL(clicked()), params, SLOT(setExposureModeAuto()));
QObject::connect(p,SIGNAL(clicked()), gainSlider, SLOT(hide()));
QObject::connect(m,SIGNAL(clicked()), params, SLOT(setExposureModeMan()));
QObject::connect(m,SIGNAL(clicked()), expSlider, SLOT(show()));
QObject::connect(m,SIGNAL(clicked()), params, SLOT(setGainModeMan()));
QObject::connect(m,SIGNAL(clicked()), gainSlider, SLOT(show()));
QObject::connect(s,SIGNAL(clicked()), expSlider, SLOT(show()));
QObject::connect(s,SIGNAL(clicked()), gainSlider, SLOT(hide()));
QObject::connect(s,SIGNAL(clicked()), params, SLOT(setExposureModeMan()));
QObject::connect(s,SIGNAL(clicked()), params, SLOT(setGainModeAuto()));
QObject::connect(iso,SIGNAL(clicked()), expSlider, SLOT(hide()));
QObject::connect(iso,SIGNAL(clicked()), gainSlider, SLOT(show()));
QObject::connect(iso,SIGNAL(clicked()), params, SLOT(setExposureModeAuto()));
QObject::connect(iso,SIGNAL(clicked()), params, SLOT(setGainModeMan()));
QObject::connect(expSlider,SIGNAL(valueChanged(int)), params, SLOT(setExposureValue(int)));
QObject::connect(gainSlider,SIGNAL(valueChanged(int)), params, SLOT(setGainValue(int)));
QObject::connect(cameraThread,SIGNAL(exposureChanged(int)), expSlider, SLOT(setValue(int)));
QObject::connect(cameraThread,SIGNAL(gainChanged(int)), gainSlider, SLOT(setValue(int)));
// focus control
QButtonGroup* foc = new QButtonGroup(window);
exp->setExclusive(true);
QPushButton* af = new QPushButton("AF", window);
af->setFont(QFont("Nokia Pure Text", 30, 200, false));
af->move(670, 10);
af->setCheckable(true);
af->setChecked(true);
QPushButton* sf = new QPushButton("", window);
sf->move(725, 15);
sf->setObjectName("sf");
sf->setIconSize(QSize(32,32));
sf->setCheckable(true);
sf->setChecked(false);
//focus dot (spot metering)
dot* spot = new dot(" ", window);
spot->setObjectName("spot");
spot->hide();
QPushButton* mf = new QPushButton("MF", window);
mf->setFont(QFont("Nokia Pure Text", 30, 200, false));
mf->move(780,10);
mf->setCheckable(true);
mf->setChecked(false);
foc->addButton(af);
foc->addButton(mf);
foc->addButton(sf);
// focus slider
QSlider* focusSlider = new QSlider(Qt::Vertical, window);
focusSlider->resize(40,400);
focusSlider->move(18, 60);
focusSlider->hide();
focusSlider->setMinimum(0);
focusSlider->setMaximum(1000);
focusSlider->setValue(500);
QObject::connect(af,SIGNAL(clicked()), focusSlider, SLOT(hide()));
QObject::connect(af,SIGNAL(clicked()), params, SLOT(setFocusModeAuto()));
QObject::connect(af,SIGNAL(clicked()), spot, SLOT(hide()));
QObject::connect(mf,SIGNAL(clicked()), focusSlider, SLOT(show()));
QObject::connect(mf,SIGNAL(clicked()), params, SLOT(setFocusModeMan()));
QObject::connect(mf,SIGNAL(clicked()), spot, SLOT(hide()));
QObject::connect(sf,SIGNAL(clicked()), focusSlider, SLOT(hide()));
QObject::connect(sf,SIGNAL(clicked()), params, SLOT(setFocusModeSpot()));
QObject::connect(sf,SIGNAL(clicked()), spot, SLOT(show()));
QObject::connect(focusSlider,SIGNAL(valueChanged(int)), params, SLOT(setFocusValue(int)));
// help label
QPushButton* help = new QPushButton("cover the proximity \nsensor to focus", window);
help->setFont(QFont("Nokia Pure Text", 20, 200, false));
help->resize(320,80);
help->setObjectName("help");
if (settings.value("showHelp",true)==false) help->hide();
QDeclarativeView *qmlView = new QDeclarativeView(window);
qmlView->rootContext()->setContextProperty("params", params);
qmlView->setSource(QUrl::fromLocalFile("/opt/rawcam/settings.qml"));
qmlView->hide();
// qmlView->resize(700,350);
qmlView->move(60, 0);
QObject::connect(settingsBtn,SIGNAL(clicked()), qmlView, SLOT(show()));
//QObject::connect(overlay, SIGNAL(focus(int, int)), qmlView, SLOT(hide()));
QPropertyAnimation openani(qmlView, "geometry");
openani.setDuration(200);
openani.setStartValue(QRect(60, 0, 700, 0));
openani.setEndValue(QRect(60, 0, 700, 350));
QObject::connect(settingsBtn,SIGNAL(clicked()), &openani, SLOT(start()));
QPropertyAnimation closeani(qmlView, "geometry");
closeani.setDuration(200);
closeani.setStartValue(QRect(60, 0, 700, 350));
closeani.setEndValue(QRect(60, 0, 700, 0));
QObject::connect(overlay, SIGNAL(focus(int, int)), &closeani, SLOT(start()));
QObject::connect(&closeani, SIGNAL(finished()), qmlView, SLOT(hide()));
QTimer::singleShot(8000, help, SLOT(hide()));
QObject::connect(help, SIGNAL(clicked()), help, SLOT(hide()));
//settings.setValue("helpTimeout", 68);
// Get the overlay to update when the camera has a new viewfinder
// frame
QObject::connect(cameraThread, SIGNAL(newViewfinderFrame()),
overlay, SLOT(newViewfinderFrame()));
// Connect overlay signals to cameraThread slots
QObject::connect(overlay, SIGNAL(focus(int, int)), params, SLOT(setFocusSpot(int, int)));
//connect overlay touch to spot circle label
QObject::connect(overlay, SIGNAL(focus(int, int)), spot, SLOT(move(int,int)));
// Once the camera thread stops, quit the app
QObject::connect(cameraThread, SIGNAL(finished()),
&app, SLOT(quit()));
// Connect activate and deactivate events to camerathread
QObject::connect(overlay, SIGNAL(deactivate()),
cameraThread, SLOT(pause()));
QObject::connect(overlay, SIGNAL(activate()),
cameraThread, SLOT(resume()));
QObject::connect(overlay, SIGNAL(quit()),
cameraThread, SLOT(stop()));
// Show the app full screen
window->showFullScreen();
// Launch the camera thread
cameraThread->start();
// Enter the QT main event loop
app.exec();
while (cameraThread->writer.savesPending() > 0) sleep(1);
delete cameraThread;
}