Diffstat (limited to 'noncore/multimedia/camera2/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/camera2/mainwindow.cpp | 763 |
1 files changed, 763 insertions, 0 deletions
diff --git a/noncore/multimedia/camera2/mainwindow.cpp b/noncore/multimedia/camera2/mainwindow.cpp new file mode 100644 index 0000000..45f8cdf --- a/dev/null +++ b/noncore/multimedia/camera2/mainwindow.cpp | |||
@@ -0,0 +1,763 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2006 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This program is free software; you can redistribute it and/or modify it | ||
7 | ** under the terms of the GNU General Public License as published by the | ||
8 | ** Free Software Foundation; either version 2 of the License, or (at your | ||
9 | ** option) any later version. | ||
10 | ** | ||
11 | ** A copy of the GNU GPL license version 2 is included in this package as | ||
12 | ** LICENSE.GPL. | ||
13 | ** | ||
14 | ** This program is distributed in the hope that it will be useful, but | ||
15 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | ** See the GNU General Public License for more details. | ||
18 | ** | ||
19 | ** In addition, as a special exception Trolltech gives permission to link | ||
20 | ** the code of this program with Qtopia applications copyrighted, developed | ||
21 | ** and distributed by Trolltech under the terms of the Qtopia Personal Use | ||
22 | ** License Agreement. You must comply with the GNU General Public License | ||
23 | ** in all respects for all of the code used other than the applications | ||
24 | ** licensed under the Qtopia Personal Use License Agreement. If you modify | ||
25 | ** this file, you may extend this exception to your version of the file, | ||
26 | ** but you are not obligated to do so. If you do not wish to do so, delete | ||
27 | ** this exception statement from your version. | ||
28 | ** | ||
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
30 | ** | ||
31 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
32 | ** not clear to you. | ||
33 | ** | ||
34 | **********************************************************************/ | ||
35 | |||
36 | #define QTOPIA_INTERNAL_FILEOPERATIONS | ||
37 | #include "mainwindow.h" | ||
38 | #include "videocaptureview.h" | ||
39 | #include "camerasettings.h" | ||
40 | #include "thumbbutton.h" | ||
41 | |||
42 | #include "image.h" | ||
43 | |||
44 | /* OPIE */ | ||
45 | #include <opie2/odebug.h> | ||
46 | #include <opie2/oresource.h> | ||
47 | using namespace Opie::Core; | ||
48 | |||
49 | #include <qpe/config.h> | ||
50 | #include <qpe/qpeapplication.h> | ||
51 | #include <qpe/locationcombo.h> | ||
52 | //#include <qtopia/contextmenu.h> | ||
53 | #include <qpe/qcopenvelope_qws.h> | ||
54 | #include <qpe/resource.h> | ||
55 | //#include <qtopia/services.h> | ||
56 | #include <qpe/categories.h> | ||
57 | #include <qpe/qpetoolbar.h> | ||
58 | #include <qpe/global.h> | ||
59 | |||
60 | #include <qaction.h> | ||
61 | #include <qlabel.h> | ||
62 | #include <qtoolbutton.h> | ||
63 | #include <qpushbutton.h> | ||
64 | #include <qgroupbox.h> | ||
65 | #include <qsignalmapper.h> | ||
66 | #include <qdir.h> | ||
67 | #include <qimage.h> | ||
68 | #include <qslider.h> | ||
69 | #include <qtimer.h> | ||
70 | #include <qmessagebox.h> | ||
71 | |||
72 | #include <stdlib.h> | ||
73 | |||
74 | #include <sys/types.h> | ||
75 | #include <sys/stat.h> | ||
76 | |||
77 | static const int thmarg = 2; | ||
78 | static const bool video_supported = FALSE; | ||
79 | |||
80 | CameraMainWindow::CameraMainWindow(QWidget * parent, const char *name, WFlags f) | ||
81 | :QMainWindow(parent, name, f) | ||
82 | { | ||
83 | setCaption(tr("Camera")); | ||
84 | |||
85 | picfile = Global::tempDir() + "image.jpg"; | ||
86 | camera = new CameraBase(this); | ||
87 | setCentralWidget(camera); | ||
88 | |||
89 | connect(qApp, SIGNAL(appMessage(const QCString &, const QByteArray &)), | ||
90 | this, SLOT(appMessage(const QCString &, const QByteArray &))); | ||
91 | connect(qApp, SIGNAL(linkChanged(const QString &)), this, SLOT(linkChanged(const QString &))); | ||
92 | |||
93 | Categories cats; | ||
94 | cats.load(categoryFileName()); | ||
95 | camcat = cats.id("Document View", "_Camera"); // No tr | ||
96 | if (!camcat) { | ||
97 | camcat = cats.addCategory("Document View", "_Camera"); // No tr | ||
98 | cats.save(categoryFileName()); | ||
99 | } | ||
100 | |||
101 | camera->photo->setFocus(); | ||
102 | |||
103 | connect(camera->photo, SIGNAL(clicked()), this, SLOT(takePhoto())); | ||
104 | connect(camera->video, SIGNAL(clicked()), this, SLOT(toggleVideo())); | ||
105 | |||
106 | refocusTimer = new QTimer(this); | ||
107 | connect(refocusTimer, SIGNAL(timeout()), this, SLOT(takePhotoNow())); | ||
108 | |||
109 | thumb[0] = camera->thumb1; | ||
110 | thumb[1] = camera->thumb2; | ||
111 | thumb[2] = camera->thumb3; | ||
112 | thumb[3] = camera->thumb4; | ||
113 | thumb[4] = camera->thumb5; | ||
114 | cur_thumb = -1; | ||
115 | |||
116 | QSignalMapper *sm = new QSignalMapper(this); | ||
117 | for (int i = 0; i < nthumb; i++) { | ||
118 | sm->setMapping(thumb[i], i); | ||
119 | connect(thumb[i], SIGNAL(clicked()), sm, SLOT(map())); | ||
120 | thumb[i]->installEventFilter(this); | ||
121 | } | ||
122 | connect(sm, SIGNAL(mapped(int)), this, SLOT(thumbClicked(int))); | ||
123 | |||
124 | #warning fixme | ||
125 | // AppLnk picture_viewer = Service::appLnk("PhotoEdit"); | ||
126 | // AppLnk video_viewer = Service::appLnk("Open/video/mpeg"); | ||
127 | |||
128 | a_pview = new QAction(tr("%1...", "app name").arg("" /*picture_viewer.name() */ ), | ||
129 | Resource::loadPixmap(NULL /*picture_viewer.icon() */ ), QString::null, 0, | ||
130 | this, 0); | ||
131 | connect(a_pview, SIGNAL(activated()), this, SLOT(viewPictures())); | ||
132 | a_vview = new QAction(tr("%1...", "app name").arg("" /*video_viewer.name() */ ), | ||
133 | Resource::loadIconSet(NULL /*video_viewer.icon() */ ), QString::null, 0, | ||
134 | this, 0); | ||
135 | connect(a_vview, SIGNAL(activated()), this, SLOT(viewVideos())); | ||
136 | |||
137 | a_settings = | ||
138 | new QAction(tr("Settings..."), Opie::Core::OResource::loadPixmap("camera2/settings", Opie::Core::OResource::SmallIcon), | ||
139 | QString::null, 0, this, 0); | ||
140 | connect(a_settings, SIGNAL(activated()), this, SLOT(doSettings())); | ||
141 | |||
142 | a_th_edit = new QAction(tr("Edit"), Opie::Core::OResource::loadPixmap("edit", Opie::Core::OResource::SmallIcon), | ||
143 | QString::null, 0, this, 0); | ||
144 | connect(a_th_edit, SIGNAL(activated()), this, SLOT(editThumb())); | ||
145 | a_th_del = new QAction(tr("Delete"), Opie::Core::OResource::loadPixmap("trash", Opie::Core::OResource::SmallIcon), | ||
146 | QString::null, 0, this, 0); | ||
147 | connect(a_th_del, SIGNAL(activated()), this, SLOT(delThumb())); | ||
148 | a_th_add = | ||
149 | new QAction(tr("Move to Contact..."), Opie::Core::OResource::loadPixmap("addressbook/generic-contact", Opie::Core::OResource::SmallIcon), | ||
150 | QString::null, 0, this, 0); | ||
151 | connect(a_th_add, SIGNAL(activated()), this, SLOT(moveToContact())); | ||
152 | a_send = | ||
153 | new QAction(tr("Beam to Contact..."), Opie::Core::OResource::loadPixmap("beam", Opie::Core::OResource::SmallIcon), | ||
154 | QString::null, 0, this, 0); | ||
155 | connect(a_send, SIGNAL(activated()), this, SLOT(sendFile())); | ||
156 | |||
157 | |||
158 | #ifndef QTOPIA_PHONE | ||
159 | // Create Toolbars | ||
160 | QPEToolBar *bar = new QPEToolBar(this); | ||
161 | bar->setHorizontalStretchable(TRUE); | ||
162 | setToolBarsMovable(FALSE); | ||
163 | |||
164 | a_pview->addTo(bar); | ||
165 | if (video_supported) | ||
166 | a_vview->addTo(bar); | ||
167 | a_th_edit->addTo(bar); | ||
168 | a_th_del->addTo(bar); | ||
169 | a_th_add->addTo(bar); | ||
170 | a_send->addTo(bar); | ||
171 | a_settings->addTo(bar); | ||
172 | #else | ||
173 | ContextMenu *contextMenu = new ContextMenu(this); | ||
174 | a_pview->addTo(contextMenu); | ||
175 | if (video_supported) | ||
176 | a_vview->addTo(contextMenu); | ||
177 | a_th_edit->addTo(contextMenu); | ||
178 | a_th_del->addTo(contextMenu); | ||
179 | a_th_add->addTo(contextMenu); | ||
180 | a_send->addTo(contextMenu); | ||
181 | a_settings->addTo(contextMenu); | ||
182 | #endif | ||
183 | |||
184 | installEventFilter(camera->photo); | ||
185 | installEventFilter(camera->video); | ||
186 | camera->photo->installEventFilter(this); | ||
187 | camera->video->installEventFilter(this); | ||
188 | |||
189 | // Load the allowable sizes from the camera hardware. | ||
190 | photo_size = camera->videocaptureview->photoSizes(); | ||
191 | video_size = camera->videocaptureview->videoSizes(); | ||
192 | |||
193 | settings = new CameraSettings(this, 0, TRUE); | ||
194 | // load settings from config | ||
195 | Config cfg("Camera"); | ||
196 | cfg.setGroup("General"); | ||
197 | QString l = cfg.readEntry("location"); | ||
198 | |||
199 | #warning fixme | ||
200 | /*if ( !l.isEmpty() ) | ||
201 | settings->location->setLocation(l); | ||
202 | */ | ||
203 | |||
204 | storagepath = settings->location->documentPath(); | ||
205 | cfg.setGroup("Photo"); | ||
206 | int w; | ||
207 | w = cfg.readNumEntry("width", camera->videocaptureview->recommendedPhotoSize().width()); | ||
208 | for (psize = 0; psize < (int) photo_size.count() - 1 && photo_size[psize].width() > w;) | ||
209 | psize++; | ||
210 | pquality = cfg.readNumEntry("quality", settings->photo_quality->value()); | ||
211 | cfg.setGroup("Video"); | ||
212 | w = cfg.readNumEntry("width", camera->videocaptureview->recommendedVideoSize().width()); | ||
213 | for (vsize = 0; vsize < (int) video_size.count() - 1 && video_size[vsize].width() > w;) | ||
214 | vsize++; | ||
215 | vquality = cfg.readNumEntry("quality", settings->video_quality->value()); | ||
216 | vframerate = cfg.readNumEntry("framerate", settings->video_framerate->value()); | ||
217 | |||
218 | for (int i = 0; i < (int) photo_size.count(); i++) { | ||
219 | settings->photo_size->insertItem(tr("%1 x %2").arg(photo_size[i].width()). | ||
220 | arg(photo_size[i].height())); | ||
221 | } | ||
222 | for (int i = 0; i < (int) video_size.count(); i++) { | ||
223 | settings->video_size->insertItem(tr("%1 x %2").arg(video_size[i].width()). | ||
224 | arg(video_size[i].height())); | ||
225 | } | ||
226 | |||
227 | namehint = 0; | ||
228 | recording = FALSE; | ||
229 | |||
230 | preview(); | ||
231 | |||
232 | if (!video_supported) { | ||
233 | // Room for longer text | ||
234 | camera->photo->setText(tr("Take Photo")); | ||
235 | camera->video->setEnabled(FALSE); | ||
236 | camera->video->hide(); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | CameraMainWindow::~CameraMainWindow() | ||
241 | { | ||
242 | } | ||
243 | |||
244 | void CameraMainWindow::resizeEvent(QResizeEvent *) | ||
245 | { | ||
246 | thumbw = width() / 5 - 4; | ||
247 | thumbh = thumbw * 3 / 4; | ||
248 | thumb[0]->setFixedHeight(thumbh + thmarg * 2); | ||
249 | loadThumbs(); | ||
250 | } | ||
251 | |||
252 | bool CameraMainWindow::event(QEvent * e) | ||
253 | { | ||
254 | if (e->type() == QEvent::WindowActivate) { | ||
255 | if (cur_thumb < 0) | ||
256 | camera->videocaptureview->setLive(); | ||
257 | } | ||
258 | else if (e->type() == QEvent::WindowDeactivate) { | ||
259 | camera->videocaptureview->setLive(-1); | ||
260 | } | ||
261 | return QMainWindow::event(e); | ||
262 | } | ||
263 | |||
264 | bool CameraMainWindow::eventFilter(QObject * o, QEvent * e) | ||
265 | { | ||
266 | if (e->type() == QEvent::KeyPress) { | ||
267 | QKeyEvent *ke = (QKeyEvent *) e; | ||
268 | |||
269 | #if QTOPIA_PHONE | ||
270 | if (!ke->isAutoRepeat()) { | ||
271 | if (ke->key() == Key_1) { | ||
272 | takePhoto(); | ||
273 | return TRUE; | ||
274 | } | ||
275 | else if (ke->key() == Key_2) { | ||
276 | toggleVideo(); | ||
277 | return TRUE; | ||
278 | } | ||
279 | } | ||
280 | #endif | ||
281 | if (ke->key() == Key_Up) { | ||
282 | camera->photo->setFocus(); | ||
283 | return TRUE; | ||
284 | } | ||
285 | else if (ke->key() == Key_Down) { | ||
286 | thumb[0]->setFocus(); | ||
287 | return TRUE; | ||
288 | } | ||
289 | else if (ke->key() == Key_Left) { | ||
290 | if (o == camera->video) { | ||
291 | camera->photo->setFocus(); | ||
292 | return TRUE; | ||
293 | } | ||
294 | else { | ||
295 | if (o == thumb[0]) | ||
296 | return TRUE; | ||
297 | for (int i = 1; i < nthumb; ++i) { | ||
298 | if (o == thumb[i]) { | ||
299 | thumb[i - 1]->setFocus(); | ||
300 | return TRUE; | ||
301 | } | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | else if (ke->key() == Key_Right) { | ||
306 | if (o == camera->photo) { | ||
307 | camera->video->setFocus(); | ||
308 | return TRUE; | ||
309 | } | ||
310 | else { | ||
311 | if (o == thumb[nthumb - 1]) | ||
312 | return TRUE; | ||
313 | for (int i = 0; i < nthumb - 1; ++i) { | ||
314 | if (o == thumb[i]) { | ||
315 | thumb[i + 1]->setFocus(); | ||
316 | return TRUE; | ||
317 | } | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | } | ||
322 | else if (e->type() == QEvent::FocusIn) { | ||
323 | if (o == camera->photo) | ||
324 | camera->photo->setText(tr("Take Photo")); | ||
325 | updateActions(); | ||
326 | } | ||
327 | else if (e->type() == QEvent::FocusOut) { | ||
328 | if (o == camera->photo) | ||
329 | camera->photo->setText(tr("Activate Camera")); | ||
330 | } | ||
331 | return QWidget::eventFilter(o, e); | ||
332 | } | ||
333 | |||
334 | void CameraMainWindow::updateActions() | ||
335 | { | ||
336 | bool p = FALSE, v = FALSE; | ||
337 | QWidget *foc = focusWidget(); | ||
338 | if (foc == camera->photo) { | ||
339 | p = TRUE; | ||
340 | v = FALSE; | ||
341 | } | ||
342 | else if (foc == camera->video) { | ||
343 | v = TRUE; | ||
344 | p = FALSE; | ||
345 | } | ||
346 | a_pview->setEnabled(p); | ||
347 | a_vview->setEnabled(v); | ||
348 | a_settings->setEnabled(p || v); | ||
349 | bool th = !p && !v; | ||
350 | if (th) { | ||
351 | int i; | ||
352 | for (i = 0; i < nthumb; i++) { | ||
353 | if (thumb[i] == foc) { | ||
354 | selectThumb(i); | ||
355 | break; | ||
356 | } | ||
357 | } | ||
358 | if (i == nthumb || !thumb[i]->pixmap()) | ||
359 | th = FALSE; | ||
360 | } | ||
361 | else { | ||
362 | selectThumb(-1); | ||
363 | } | ||
364 | } | ||
365 | |||
366 | void CameraMainWindow::viewPictures() | ||
367 | { | ||
368 | #warning fixme | ||
369 | // ServiceRequest req("PhotoEdit","showCategory(int)"); | ||
370 | // req << camcat; | ||
371 | // req.send(); | ||
372 | } | ||
373 | |||
374 | void CameraMainWindow::viewVideos() | ||
375 | { | ||
376 | #warning fixme | ||
377 | // Service::appLnk("Open/video/mpeg").execute(); | ||
378 | } | ||
379 | |||
380 | void CameraMainWindow::doSettings() | ||
381 | { | ||
382 | bool v = video_supported; | ||
383 | #ifdef QTOPIA_PHONE | ||
384 | bool p; | ||
385 | p = a_pview->isEnabled(); | ||
386 | v = v && a_vview->isEnabled(); | ||
387 | if (p) | ||
388 | settings->photo->show(); | ||
389 | else | ||
390 | settings->photo->hide(); | ||
391 | #endif | ||
392 | if (v) | ||
393 | settings->video->show(); | ||
394 | else | ||
395 | settings->video->hide(); | ||
396 | settings->photo_size->setCurrentItem(psize); | ||
397 | settings->video_size->setCurrentItem(vsize); | ||
398 | settings->photo_quality->setValue(pquality); | ||
399 | settings->video_quality->setValue(vquality); | ||
400 | settings->video_framerate->setValue(vframerate); | ||
401 | settings->video_quality_n->setFixedWidth(fontMetrics().width("100")); | ||
402 | settings->photo_quality_n->setFixedWidth(fontMetrics().width("100")); | ||
403 | |||
404 | if (QPEApplication::execDialog(settings)) { | ||
405 | confirmSettings(); | ||
406 | } | ||
407 | else { | ||
408 | #warning fixme | ||
409 | // settings->location->setLocation(storagepath); | ||
410 | } | ||
411 | } | ||
412 | |||
413 | void CameraMainWindow::confirmSettings() | ||
414 | { | ||
415 | storagepath = settings->location->documentPath(); | ||
416 | psize = settings->photo_size->currentItem(); | ||
417 | vsize = settings->video_size->currentItem(); | ||
418 | pquality = settings->photo_quality->value(); | ||
419 | vquality = settings->video_quality->value(); | ||
420 | vframerate = settings->video_framerate->value(); | ||
421 | |||
422 | // save settings | ||
423 | Config cfg("Camera"); | ||
424 | cfg.setGroup("General"); | ||
425 | cfg.writeEntry("location", storagepath); | ||
426 | cfg.setGroup("Photo"); | ||
427 | cfg.writeEntry("width", photo_size[psize].width()); | ||
428 | cfg.writeEntry("quality", pquality); | ||
429 | cfg.setGroup("Video"); | ||
430 | cfg.writeEntry("width", video_size[vsize].width()); | ||
431 | cfg.writeEntry("quality", vquality); | ||
432 | cfg.writeEntry("framerate", vframerate); | ||
433 | |||
434 | loadThumbs(); | ||
435 | |||
436 | preview(); | ||
437 | } | ||
438 | |||
439 | static int cmpDocLnk(const void *a, const void *b) | ||
440 | { | ||
441 | const DocLnk *la = *(const DocLnk **) a; | ||
442 | const DocLnk *lb = *(const DocLnk **) b; | ||
443 | QFileInfo fa(la->linkFileKnown()? la->linkFile() : la->file()); | ||
444 | QFileInfo fb(lb->linkFileKnown()? lb->linkFile() : lb->file()); | ||
445 | return fa.lastModified().secsTo(fb.lastModified()); | ||
446 | } | ||
447 | |||
448 | void CameraMainWindow::loadThumbs() | ||
449 | { | ||
450 | if (storagepath.isEmpty()) { | ||
451 | updateActions(); | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | DocLnkSet set(storagepath, "image/jpeg"); | ||
456 | const QList < DocLnk > &l = set.children(); | ||
457 | |||
458 | DocLnk *lnk; | ||
459 | DocLnk **array = new DocLnk *[l.count()]; | ||
460 | int n = 0; | ||
461 | for (QListIterator < DocLnk > it(l); (lnk = it.current()); ++it) { | ||
462 | if (lnk->categories().contains(camcat)) | ||
463 | array[n++] = lnk; | ||
464 | } | ||
465 | qsort(array, n, sizeof(array[0]), cmpDocLnk); | ||
466 | for (int i = 0; i < nthumb; i++) { | ||
467 | QPixmap pm; | ||
468 | if (i < n) { | ||
469 | picturefile[i] = *array[i]; | ||
470 | QImage img = Image::loadScaled(picturefile[i].file(), thumbw, thumbh); | ||
471 | pm.convertFromImage(img); | ||
472 | } | ||
473 | if (pm.isNull()) { | ||
474 | thumb[i]->setText(""); | ||
475 | } | ||
476 | else { | ||
477 | thumb[i]->setPixmap(pm); | ||
478 | } | ||
479 | thumb[i]->setEnabled(!pm.isNull()); | ||
480 | } | ||
481 | if (cur_thumb >= 0) | ||
482 | selectThumb(cur_thumb); | ||
483 | |||
484 | if (!camera->videocaptureview->available()) { | ||
485 | camera->photo->setEnabled(FALSE); | ||
486 | camera->video->setEnabled(FALSE); | ||
487 | if (!n) { | ||
488 | thumb[0]->setEnabled(FALSE); | ||
489 | } | ||
490 | else { | ||
491 | thumb[0]->setFocus(); | ||
492 | thumb[0]->setEnabled(TRUE); | ||
493 | } | ||
494 | } | ||
495 | |||
496 | updateActions(); | ||
497 | } | ||
498 | |||
499 | void CameraMainWindow::delThumb(int th) | ||
500 | { | ||
501 | switch (QMessageBox::warning(0, tr("Confirmation"), | ||
502 | tr("<qt>Delete '%1'?</qt>", | ||
503 | "%1 = file name").arg(picturefile[th].name()), QMessageBox::Yes, | ||
504 | QMessageBox::No)) { | ||
505 | case QMessageBox::Yes: | ||
506 | picturefile[th].removeFiles(); | ||
507 | |||
508 | // Rhys Hack - if we have just deleted the last image and there | ||
509 | // is no camera connected, then exit the application. This | ||
510 | // avoids a focus problem where it is impossible to exit with | ||
511 | // the back button due to the focus being in a stupid place. | ||
512 | loadThumbs(); | ||
513 | if (!camera->videocaptureview->available() && !(thumb[0]->isEnabled())) { | ||
514 | close(); | ||
515 | } | ||
516 | break; | ||
517 | default: | ||
518 | //nothing | ||
519 | break; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | void CameraMainWindow::pushThumb(const DocLnk & f, const QImage & img) | ||
524 | { | ||
525 | for (int i = nthumb; --i;) { | ||
526 | bool en = thumb[i - 1]->isEnabled(); | ||
527 | thumb[i]->setEnabled(en); | ||
528 | picturefile[i] = picturefile[i - 1]; | ||
529 | const QPixmap *pm = thumb[i - 1]->pixmap(); | ||
530 | if (en && pm) { | ||
531 | thumb[i]->setPixmap(*pm); | ||
532 | } | ||
533 | else { | ||
534 | thumb[i]->setText(""); | ||
535 | } | ||
536 | } | ||
537 | QPixmap pm; | ||
538 | QSize sz = Image::aspectScaleSize(img.width(), img.height(), thumbw, thumbh); | ||
539 | QImage simg = img.smoothScale(sz.width(), sz.height()); | ||
540 | pm.convertFromImage(simg); | ||
541 | thumb[0]->setPixmap(pm); | ||
542 | thumb[0]->setEnabled(TRUE); | ||
543 | picturefile[0] = f; | ||
544 | } | ||
545 | |||
546 | void CameraMainWindow::takePhoto() | ||
547 | { | ||
548 | if (camera->photo != focusWidget()) { | ||
549 | camera->photo->setFocus(); | ||
550 | return; | ||
551 | } | ||
552 | QSize size = photo_size[psize]; | ||
553 | if (size == camera->videocaptureview->captureSize() || | ||
554 | camera->videocaptureview->refocusDelay() == 0) { | ||
555 | |||
556 | // We can grab the current image immediately. | ||
557 | takePhotoNow(); | ||
558 | |||
559 | } | ||
560 | else { | ||
561 | |||
562 | // Change the camera size and then wait for the camera to refocus. | ||
563 | camera->videocaptureview->setCaptureSize(size); | ||
564 | refocusTimer->start(camera->videocaptureview->refocusDelay(), TRUE); | ||
565 | |||
566 | } | ||
567 | } | ||
568 | |||
569 | void CameraMainWindow::takePhotoNow() | ||
570 | { | ||
571 | QImage img = camera->videocaptureview->image(); | ||
572 | |||
573 | if (inSnapMode()) { | ||
574 | QCopEnvelope e(snap_ch, "valueSupplied(QString,QImage)"); | ||
575 | QSize s = Image::aspectScaleSize(img.width(), img.height(), snap_maxw, snap_maxh); | ||
576 | e << snap_id << img.smoothScale(s.width(), s.height()); | ||
577 | setSnapMode(FALSE); | ||
578 | close(); | ||
579 | } | ||
580 | else { | ||
581 | DocLnk f; | ||
582 | //f.setLocation(storagepath); | ||
583 | f.setType("image/jpeg"); | ||
584 | QDateTime dt = QDateTime::currentDateTime(); | ||
585 | QString date = dt.toString(); | ||
586 | f.setName(tr("Photo, " + date)); | ||
587 | |||
588 | QArray < int >c(1); | ||
589 | c[0] = camcat; | ||
590 | f.setCategories(c); | ||
591 | img.save(f.file(), "JPEG", pquality); // Save the image in its original size. | ||
592 | f.writeLink(); | ||
593 | pushThumb(f, img); | ||
594 | } | ||
595 | |||
596 | preview(); | ||
597 | } | ||
598 | |||
599 | bool CameraMainWindow::inSnapMode() const | ||
600 | { | ||
601 | return !snap_ch.isEmpty(); | ||
602 | } | ||
603 | |||
604 | void CameraMainWindow::setSnapMode(bool y) | ||
605 | { | ||
606 | if (y) { | ||
607 | camera->thumbs->hide(); | ||
608 | camera->video->hide(); | ||
609 | } | ||
610 | else { | ||
611 | camera->thumbs->show(); | ||
612 | if (video_supported) | ||
613 | camera->video->show(); | ||
614 | else | ||
615 | camera->video->hide(); | ||
616 | snap_ch = QString::null; | ||
617 | } | ||
618 | } | ||
619 | |||
620 | void CameraMainWindow::toggleVideo() | ||
621 | { | ||
622 | if (recording) | ||
623 | stopVideo(); | ||
624 | else | ||
625 | startVideo(); | ||
626 | recording = !recording; | ||
627 | camera->video->setText(recording ? tr("Stop") : tr("Video")); | ||
628 | camera->photo->setEnabled(!recording); | ||
629 | for (int i = 0; i < nthumb; i++) | ||
630 | thumb[i]->setEnabled(!recording && thumb[i]->pixmap()); | ||
631 | } | ||
632 | |||
633 | void CameraMainWindow::startVideo() | ||
634 | { | ||
635 | // XXX eg. MJPG | ||
636 | } | ||
637 | void CameraMainWindow::stopVideo() | ||
638 | { | ||
639 | } | ||
640 | |||
641 | void CameraMainWindow::thumbClicked(int i) | ||
642 | { | ||
643 | selectThumb(i); | ||
644 | } | ||
645 | |||
646 | void CameraMainWindow::editThumb() | ||
647 | { | ||
648 | picturefile[cur_thumb].execute(); | ||
649 | } | ||
650 | |||
651 | void CameraMainWindow::selectThumb(int i) | ||
652 | { | ||
653 | cur_thumb = i; | ||
654 | if (i >= 0) { | ||
655 | QImage img(picturefile[i].file()); | ||
656 | camera->videocaptureview->setStill(img); | ||
657 | thumb[i]->setFocus(); | ||
658 | } | ||
659 | else { | ||
660 | camera->videocaptureview->setLive(); | ||
661 | } | ||
662 | a_th_edit->setEnabled(i >= 0); | ||
663 | a_th_del->setEnabled(i >= 0); | ||
664 | a_th_add->setEnabled(i >= 0); | ||
665 | a_send->setEnabled(i >= 0); | ||
666 | } | ||
667 | |||
668 | void CameraMainWindow::moveToContact() | ||
669 | { | ||
670 | if (cur_thumb >= 0) { | ||
671 | #warning fixme | ||
672 | // QCopEnvelope e(Service::channel("Contacts"),"setContactImage(QImage)"); | ||
673 | // QImage img; | ||
674 | // img.load(picturefile[cur_thumb].file()); | ||
675 | // e << img; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | void CameraMainWindow::delThumb() | ||
680 | { | ||
681 | if (cur_thumb >= 0) { | ||
682 | int d = cur_thumb; | ||
683 | if (cur_thumb > 0) | ||
684 | selectThumb(cur_thumb - 1); | ||
685 | delThumb(d); | ||
686 | } | ||
687 | } | ||
688 | |||
689 | void CameraMainWindow::linkChanged(const QString &) | ||
690 | { | ||
691 | loadThumbs(); | ||
692 | } | ||
693 | |||
694 | void CameraMainWindow::appMessage(const QCString & msg, const QByteArray & data) | ||
695 | { | ||
696 | if (msg == "getImage(QCString,QString,int,int,QImage)") { | ||
697 | QDataStream ds(data, IO_ReadOnly); | ||
698 | ds >> snap_ch >> snap_id >> snap_maxw >> snap_maxh; | ||
699 | setSnapMode(TRUE); | ||
700 | QPEApplication::setKeepRunning(); | ||
701 | } | ||
702 | } | ||
703 | |||
704 | void CameraMainWindow::preview() | ||
705 | { | ||
706 | if (camera->videocaptureview->refocusDelay() > 200) { | ||
707 | camera->videocaptureview->setCaptureSize(photo_size[psize]); | ||
708 | } | ||
709 | else { | ||
710 | camera->videocaptureview->setCaptureSize(camera->videocaptureview-> | ||
711 | recommendedPreviewSize()); | ||
712 | } | ||
713 | } | ||
714 | |||
715 | void CameraMainWindow::sendFile() | ||
716 | { | ||
717 | if (cur_thumb >= 0) { | ||
718 | //copy file | ||
719 | QFile input(picturefile[cur_thumb].file()); | ||
720 | if (!input.open(IO_ReadOnly)) { | ||
721 | return; //error | ||
722 | } | ||
723 | QFile output(picfile); | ||
724 | if (!output.open(IO_WriteOnly)) { | ||
725 | return; | ||
726 | } | ||
727 | |||
728 | const int BUFFER_SIZE = 1024; | ||
729 | Q_INT8 buffer[BUFFER_SIZE]; | ||
730 | |||
731 | QDataStream srcStr(&input); | ||
732 | QDataStream destStr(&output); | ||
733 | |||
734 | while (!srcStr.atEnd()) { | ||
735 | int i = 0; | ||
736 | while (!srcStr.atEnd() && i < BUFFER_SIZE) { | ||
737 | srcStr >> buffer[i]; | ||
738 | i++; | ||
739 | } | ||
740 | for (int k = 0; k < i; k++) { | ||
741 | destStr << buffer[k]; | ||
742 | } | ||
743 | } | ||
744 | |||
745 | #warning fixme | ||
746 | // QCopEnvelope e(Service::channel("Email"),"writeMessage(QString,QString,QStringList,QStringList)"); | ||
747 | // e << QString() << QString() << QStringList() << QStringList( QString( picfile ) ); | ||
748 | } | ||
749 | } | ||
750 | |||
751 | void ThumbButton::drawButtonLabel(QPainter * p) | ||
752 | { | ||
753 | const QPixmap *pm = pixmap(); | ||
754 | if (pm) { | ||
755 | QSize s = (size() - pm->size()) / 2; | ||
756 | p->drawPixmap(s.width(), s.height(), *pm); | ||
757 | } | ||
758 | } | ||
759 | |||
760 | ThumbButton::ThumbButton(QWidget * parent, const char *name):QToolButton(parent, name) | ||
761 | { | ||
762 | } | ||
763 | |||