author | mickeyl <mickeyl> | 2003-04-13 22:27:57 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-13 22:27:57 (UTC) |
commit | f47258125bac368987a90ca49a118721ecbc3a8b (patch) (unidiff) | |
tree | 04d137fce8890a311d0cc1c3ab2853acc64ccb45 | |
parent | 053c38bb48ae8e7563293bc029f3c9d029b947f7 (diff) | |
download | opie-f47258125bac368987a90ca49a118721ecbc3a8b.zip opie-f47258125bac368987a90ca49a118721ecbc3a8b.tar.gz opie-f47258125bac368987a90ca49a118721ecbc3a8b.tar.bz2 |
make opiecam work!
-rw-r--r-- | noncore/multimedia/camera/camera.pro | 2 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 144 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 22 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.cpp | 16 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.h | 4 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 44 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 22 |
7 files changed, 235 insertions, 19 deletions
diff --git a/noncore/multimedia/camera/camera.pro b/noncore/multimedia/camera/camera.pro index 16da0c9..ffd5f37 100644 --- a/noncore/multimedia/camera/camera.pro +++ b/noncore/multimedia/camera/camera.pro | |||
@@ -6,18 +6,18 @@ CONFIG = qt warn_on debug | |||
6 | 6 | ||
7 | HEADERS = zcameraio.h \ | 7 | HEADERS = zcameraio.h \ |
8 | previewwidget.h \ | 8 | previewwidget.h \ |
9 | mainwindow.h | 9 | mainwindow.h |
10 | 10 | ||
11 | SOURCES = zcameraio.cpp \ | 11 | SOURCES = zcameraio.cpp \ |
12 | previewwidget.cpp \ | 12 | previewwidget.cpp \ |
13 | mainwindow.cpp \ | 13 | mainwindow.cpp \ |
14 | main.cpp | 14 | main.cpp |
15 | 15 | ||
16 | INCLUDEPATH += $(OPIEDIR)/include | 16 | INCLUDEPATH += $(OPIEDIR)/include |
17 | DEPENDPATH += $(OPIEDIR)/include | 17 | DEPENDPATH += $(OPIEDIR)/include |
18 | LIBS += -lqpe -lopiecore2 | 18 | LIBS += -lqpe -lopie -lopiecore2 |
19 | INTERFACES = | 19 | INTERFACES = |
20 | TARGET = opiecam | 20 | TARGET = opiecam |
21 | 21 | ||
22 | include ( $(OPIEDIR)/include.pro ) | 22 | include ( $(OPIEDIR)/include.pro ) |
23 | 23 | ||
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 34ebe9e..8e89039 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp | |||
@@ -8,80 +8,141 @@ | |||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "mainwindow.h" | 16 | #include "mainwindow.h" |
17 | #include "previewwidget.h" | 17 | #include "previewwidget.h" |
18 | #include "zcameraio.h" | 18 | #include "zcameraio.h" |
19 | 19 | ||
20 | #include <qapplication.h> | ||
21 | #include <qaction.h> | ||
20 | #include <qvbox.h> | 22 | #include <qvbox.h> |
21 | #include <qcombobox.h> | 23 | #include <qcombobox.h> |
22 | #include <qcursor.h> | 24 | #include <qcursor.h> |
23 | #include <qdatastream.h> | 25 | #include <qdatastream.h> |
26 | #include <qfile.h> | ||
27 | #include <qimage.h> | ||
24 | #include <qlabel.h> | 28 | #include <qlabel.h> |
25 | #include <qpopupmenu.h> | 29 | #include <qpopupmenu.h> |
26 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
27 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
28 | #include <qdirectpainter_qws.h> | 32 | #include <qdirectpainter_qws.h> |
33 | #include <qpe/global.h> | ||
29 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
30 | #include <qpe/qcopenvelope_qws.h> | 35 | #include <qpe/qcopenvelope_qws.h> |
31 | #include <opie/ofiledialog.h> | 36 | #include <opie/ofiledialog.h> |
37 | #include <opie/odevice.h> | ||
38 | using namespace Opie; | ||
32 | 39 | ||
33 | #include <opie2/odebug.h> | 40 | #include <opie2/odebug.h> |
34 | 41 | ||
35 | #include <assert.h> | 42 | #include <assert.h> |
36 | 43 | ||
37 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 44 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) |
38 | :QMainWindow( parent, name, f ) | 45 | :QMainWindow( parent, name, f ), _pics( 0 ) |
39 | { | 46 | { |
47 | #ifdef QT_NO_DEBUG | ||
40 | if ( !ZCameraIO::instance()->isOpen() ) | 48 | if ( !ZCameraIO::instance()->isOpen() ) |
41 | { | 49 | { |
42 | QVBox* v = new QVBox( this ); | 50 | QVBox* v = new QVBox( this ); |
43 | v->setMargin( 10 ); | 51 | v->setMargin( 10 ); |
44 | QLabel* l1 = new QLabel( v ); | 52 | QLabel* l1 = new QLabel( v ); |
45 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); | 53 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); |
46 | QLabel* l2 = new QLabel( v ); | 54 | QLabel* l2 = new QLabel( v ); |
47 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" | 55 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" |
48 | "* Is the sharpzdc_cs module loaded ?<br>" | 56 | "* Is the sharpzdc_cs module loaded ?<br>" |
49 | "* Is /dev/sharpzdc read/writable ?<p>" ); | 57 | "* Is /dev/sharpzdc read/writable ?<p>" ); |
50 | connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); | 58 | connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); |
51 | setCentralWidget( v ); | 59 | setCentralWidget( v ); |
52 | return; | 60 | return; |
53 | } | 61 | } |
62 | #endif | ||
63 | |||
64 | init(); | ||
54 | 65 | ||
55 | _rotation = 270; //TODO: grab these from the actual settings | 66 | _rotation = 270; //TODO: grab these from the actual settings |
56 | 67 | ||
57 | preview = new PreviewWidget( this, "camera preview widget" ); | 68 | preview = new PreviewWidget( this, "camera preview widget" ); |
58 | //setCentralWidget( preview ); <--- don't do this! | 69 | //setCentralWidget( preview ); <--- don't do this! |
59 | preview->resize( QSize( 240, 288 ) ); | 70 | preview->resize( QSize( 240, 288 ) ); |
60 | preview->show(); | 71 | preview->show(); |
61 | 72 | ||
62 | // construct a System Channel to receive setRotation messages | 73 | // construct a System Channel to receive setRotation messages |
63 | _sysChannel = new QCopChannel( "QPE/System", this ); | 74 | _sysChannel = new QCopChannel( "QPE/System", this ); |
64 | connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 75 | connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
65 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 76 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
66 | 77 | ||
67 | connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); | 78 | connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); |
79 | |||
80 | connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); | ||
68 | }; | 81 | }; |
69 | 82 | ||
70 | 83 | ||
71 | CameraMainWindow::~CameraMainWindow() | 84 | CameraMainWindow::~CameraMainWindow() |
72 | { | 85 | { |
73 | } | 86 | } |
74 | 87 | ||
75 | 88 | ||
89 | void CameraMainWindow::init() | ||
90 | { | ||
91 | // TODO: Save this stuff in config | ||
92 | quality = 50; | ||
93 | zoom = 1; | ||
94 | captureX = 640; | ||
95 | captureY = 480; | ||
96 | captureFormat = "JPEG"; | ||
97 | |||
98 | resog = new QActionGroup( 0, "reso", true ); | ||
99 | resog->setToggleAction( true ); | ||
100 | new QAction( " 64 x 48", 0, 0, resog, 0, true ); | ||
101 | new QAction( "128 x 96", 0, 0, resog, 0, true ); | ||
102 | new QAction( "192 x 144", 0, 0, resog, 0, true ); | ||
103 | new QAction( "256 x 192", 0, 0, resog, 0, true ); | ||
104 | new QAction( "320 x 240", 0, 0, resog, 0, true ); | ||
105 | new QAction( "384 x 288", 0, 0, resog, 0, true ); | ||
106 | new QAction( "448 x 336", 0, 0, resog, 0, true ); | ||
107 | new QAction( "512 x 384", 0, 0, resog, 0, true ); | ||
108 | new QAction( "576 x 432", 0, 0, resog, 0, true ); | ||
109 | ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); | ||
110 | |||
111 | qualityg = new QActionGroup( 0, "quality", true ); | ||
112 | qualityg->setToggleAction( true ); | ||
113 | new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); | ||
114 | new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); | ||
115 | ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); | ||
116 | new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); | ||
117 | new QAction( "100 (best)", 0, 0, qualityg, 0, true ); | ||
118 | |||
119 | zoomg = new QActionGroup( 0, "zoom", true ); | ||
120 | zoomg->setToggleAction( true ); | ||
121 | ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true ); | ||
122 | new QAction( "x 2", 0, 0, zoomg, 0, true ); | ||
123 | |||
124 | outputg = new QActionGroup( 0, "output", true ); | ||
125 | outputg->setToggleAction( true ); | ||
126 | ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); | ||
127 | new QAction( "PNG", 0, 0, outputg, 0, true ); | ||
128 | new QAction( "BMP", 0, 0, outputg, 0, true ); | ||
129 | |||
130 | connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); | ||
131 | connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); | ||
132 | connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); | ||
133 | connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); | ||
134 | } | ||
135 | |||
136 | |||
76 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) | 137 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) |
77 | { | 138 | { |
78 | QDataStream stream( data, IO_ReadOnly ); | 139 | QDataStream stream( data, IO_ReadOnly ); |
79 | odebug << "received system message: " << msg << oendl; | 140 | odebug << "received system message: " << msg << oendl; |
80 | if ( msg == "setCurrentRotation(int)" ) | 141 | if ( msg == "setCurrentRotation(int)" ) |
81 | { | 142 | { |
82 | stream >> _rotation; | 143 | stream >> _rotation; |
83 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; | 144 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; |
84 | 145 | ||
85 | switch ( _rotation ) | 146 | switch ( _rotation ) |
86 | { | 147 | { |
87 | case 270: preview->resize( QSize( 240, 288 ) ); break; | 148 | case 270: preview->resize( QSize( 240, 288 ) ); break; |
@@ -99,23 +160,94 @@ void CameraMainWindow::changeZoom( int zoom ) | |||
99 | int z; | 160 | int z; |
100 | switch ( zoom ) | 161 | switch ( zoom ) |
101 | { | 162 | { |
102 | case 0: z = 128; break; | 163 | case 0: z = 128; break; |
103 | case 1: z = 256; break; | 164 | case 1: z = 256; break; |
104 | case 2: z = 512; break; | 165 | case 2: z = 512; break; |
105 | default: assert( 0 ); break; | 166 | default: assert( 0 ); break; |
106 | } | 167 | } |
107 | 168 | ||
108 | ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); | 169 | ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); |
109 | } | 170 | } |
110 | 171 | ||
111 | |||
112 | void CameraMainWindow::showContextMenu() | 172 | void CameraMainWindow::showContextMenu() |
113 | { | 173 | { |
174 | QPopupMenu reso; | ||
175 | reso.setCheckable( true ); | ||
176 | resog->addTo( &reso ); | ||
177 | |||
178 | QPopupMenu quality; | ||
179 | quality.setCheckable( true ); | ||
180 | qualityg->addTo( &quality ); | ||
181 | |||
182 | QPopupMenu zoom; | ||
183 | zoom.setCheckable( true ); | ||
184 | zoomg->addTo( &zoom ); | ||
185 | |||
186 | QPopupMenu output; | ||
187 | output.setCheckable( true ); | ||
188 | outputg->addTo( &output ); | ||
189 | |||
114 | QPopupMenu m( this ); | 190 | QPopupMenu m( this ); |
115 | m.insertItem( "Item 1" ); | 191 | m.insertItem( "&Resolution", &reso ); |
116 | m.insertItem( "Item 1" ); | 192 | m.insertItem( "&Zoom", &zoom ); |
117 | m.insertItem( "Item 1" ); | 193 | m.insertItem( "&Quality", &quality ); |
118 | m.insertItem( "Item 1" ); | 194 | m.insertItem( "&Output As", &output ); |
119 | m.exec( QCursor::pos() ); | 195 | m.exec( QCursor::pos() ); |
120 | } | 196 | } |
121 | 197 | ||
198 | |||
199 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) | ||
200 | { | ||
201 | captureX = a->text().left(3).toInt(); | ||
202 | captureY = a->text().right(3).toInt(); | ||
203 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; | ||
204 | } | ||
205 | |||
206 | |||
207 | void CameraMainWindow::qualityMenuItemClicked( QAction* a ) | ||
208 | { | ||
209 | quality = a->text().left(3).toInt(); | ||
210 | odebug << "Quality now: " << quality << oendl; | ||
211 | } | ||
212 | |||
213 | |||
214 | void CameraMainWindow::zoomMenuItemClicked( QAction* a ) | ||
215 | { | ||
216 | zoom = QString( a->text()[2] ).toInt(); | ||
217 | odebug << "Zoom now: " << zoom << oendl; | ||
218 | ZCameraIO::instance()->setZoom( zoom ); | ||
219 | } | ||
220 | |||
221 | |||
222 | void CameraMainWindow::outputMenuItemClicked( QAction* a ) | ||
223 | { | ||
224 | captureFormat = a->text(); | ||
225 | odebug << "Output format now: " << captureFormat << oendl; | ||
226 | } | ||
227 | |||
228 | |||
229 | void CameraMainWindow::shutterClicked() | ||
230 | { | ||
231 | Global::statusMessage( "CAPTURING..." ); | ||
232 | qApp->processEvents(); | ||
233 | |||
234 | odebug << "Shutter has been pressed" << oendl; | ||
235 | ODevice::inst()->touchSound(); | ||
236 | QString name; | ||
237 | name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); | ||
238 | QImage i; | ||
239 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); | ||
240 | QImage im = i.convertDepth( 32 ); | ||
241 | bool result = im.save( name, captureFormat, quality ); | ||
242 | if ( !result ) | ||
243 | { | ||
244 | oerr << "imageio-Problem while writing." << oendl; | ||
245 | Global::statusMessage( "Error!" ); | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | odebug << captureFormat << "-image has been successfully captured" << oendl; | ||
250 | Global::statusMessage( "Ok." ); | ||
251 | } | ||
252 | } | ||
253 | |||
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h index df66204..7a12452 100644 --- a/noncore/multimedia/camera/mainwindow.h +++ b/noncore/multimedia/camera/mainwindow.h | |||
@@ -12,42 +12,62 @@ | |||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #ifndef MAINWINDOW_H | 16 | #ifndef MAINWINDOW_H |
17 | #define MAINWINDOW_H | 17 | #define MAINWINDOW_H |
18 | 18 | ||
19 | #include <qmainwindow.h> | 19 | #include <qmainwindow.h> |
20 | #include <qdatetime.h> | 20 | #include <qdatetime.h> |
21 | #include <qimage.h> | 21 | #include <qimage.h> |
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | 23 | ||
24 | class QAction; | ||
25 | class QActionGroup; | ||
24 | class QIconSet; | 26 | class QIconSet; |
25 | class QToolButton; | 27 | class QToolButton; |
26 | class QLabel; | 28 | class QLabel; |
27 | class MainWindowBase; | 29 | class MainWindowBase; |
28 | class QCopChannel; | 30 | class QCopChannel; |
29 | class PreviewWidget; | 31 | class PreviewWidget; |
30 | 32 | ||
31 | class CameraMainWindow: public QMainWindow | 33 | class CameraMainWindow: public QMainWindow |
32 | { | 34 | { |
33 | Q_OBJECT | 35 | Q_OBJECT |
34 | 36 | ||
35 | public: | 37 | public: |
36 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); | 38 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); |
37 | virtual ~CameraMainWindow(); | 39 | virtual ~CameraMainWindow(); |
38 | 40 | ||
39 | public slots: | 41 | public slots: |
40 | void changeZoom( int ); | 42 | void changeZoom( int ); |
41 | void systemMessage( const QCString&, const QByteArray& ); | 43 | void systemMessage( const QCString&, const QByteArray& ); |
42 | |||
43 | void showContextMenu(); | 44 | void showContextMenu(); |
45 | void resoMenuItemClicked( QAction* ); | ||
46 | void qualityMenuItemClicked( QAction* ); | ||
47 | void zoomMenuItemClicked( QAction* ); | ||
48 | void outputMenuItemClicked( QAction* ); | ||
49 | void shutterClicked(); | ||
44 | 50 | ||
45 | protected: | 51 | protected: |
52 | void init(); | ||
46 | 53 | ||
47 | private: | 54 | private: |
48 | PreviewWidget* preview; | 55 | PreviewWidget* preview; |
49 | int _rotation; | 56 | int _rotation; |
50 | QCopChannel* _sysChannel; | 57 | QCopChannel* _sysChannel; |
58 | |||
59 | QActionGroup* resog; | ||
60 | QActionGroup* qualityg; | ||
61 | QActionGroup* zoomg; | ||
62 | QActionGroup* outputg; | ||
63 | |||
64 | int quality; | ||
65 | int zoom; | ||
66 | int captureX; | ||
67 | int captureY; | ||
68 | QString captureFormat; | ||
69 | |||
70 | int _pics; | ||
51 | }; | 71 | }; |
52 | 72 | ||
53 | #endif | 73 | #endif |
diff --git a/noncore/multimedia/camera/previewwidget.cpp b/noncore/multimedia/camera/previewwidget.cpp index cdeacf6..f87dcc9 100644 --- a/noncore/multimedia/camera/previewwidget.cpp +++ b/noncore/multimedia/camera/previewwidget.cpp | |||
@@ -9,36 +9,40 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "previewwidget.h" | 16 | #include "previewwidget.h" |
17 | #include "zcameraio.h" | 17 | #include "zcameraio.h" |
18 | 18 | ||
19 | #include <opie2/odebug.h> | 19 | #include <opie2/odebug.h> |
20 | 20 | ||
21 | #include <assert.h> | ||
22 | |||
21 | PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) | 23 | PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) |
22 | :QLabel( parent, name, f ) | 24 | :QLabel( parent, name, f ) |
23 | { | 25 | { |
24 | #ifndef QT_NO_DEBUG | 26 | #ifndef QT_NO_DEBUG |
25 | setBackgroundColor( QColor( 255, 0, 0 ) ); | 27 | setBackgroundColor( QColor( 255, 0, 0 ) ); |
26 | #else | 28 | #else |
27 | setBackgroundMode( NoBackground ); | 29 | setBackgroundMode( NoBackground ); |
28 | #endif | 30 | #endif |
29 | 31 | ||
30 | 32 | #ifndef QT_NO_DEBUG | |
31 | startTimer( 150 ); | 33 | if ( ZCameraIO::instance()->isOpen() ) startTimer( 1500 ); |
32 | //startTimer( 2000 ); | 34 | #else |
35 | if ( ZCameraIO::instance()->isOpen() ) startTimer( 200 ); | ||
36 | #endif | ||
33 | }; | 37 | }; |
34 | 38 | ||
35 | 39 | ||
36 | PreviewWidget::~PreviewWidget() | 40 | PreviewWidget::~PreviewWidget() |
37 | { | 41 | { |
38 | } | 42 | } |
39 | 43 | ||
40 | 44 | ||
41 | void PreviewWidget::resizeEvent( QResizeEvent* e ) | 45 | void PreviewWidget::resizeEvent( QResizeEvent* e ) |
42 | { | 46 | { |
43 | QLabel::resizeEvent( e ); | 47 | QLabel::resizeEvent( e ); |
44 | int w = e->size().width(); | 48 | int w = e->size().width(); |
@@ -53,12 +57,18 @@ void PreviewWidget::resizeEvent( QResizeEvent* e ) | |||
53 | void PreviewWidget::timerEvent( QTimerEvent* ) | 57 | void PreviewWidget::timerEvent( QTimerEvent* ) |
54 | { | 58 | { |
55 | //QDirectPainter fb( this ); | 59 | //QDirectPainter fb( this ); |
56 | //ZCameraIO::instance()->snapshot( fb.frameBuffer() ); | 60 | //ZCameraIO::instance()->snapshot( fb.frameBuffer() ); |
57 | 61 | ||
58 | if ( ZCameraIO::instance()->snapshot( &i ) ) | 62 | if ( ZCameraIO::instance()->snapshot( &i ) ) |
59 | { | 63 | { |
60 | p.convertFromImage( i ); | 64 | p.convertFromImage( i ); |
61 | setPixmap( p ); | 65 | setPixmap( p ); |
62 | } | 66 | } |
63 | } | 67 | } |
64 | 68 | ||
69 | |||
70 | void PreviewWidget::mousePressEvent( QMouseEvent* ) | ||
71 | { | ||
72 | emit contextMenuRequested(); | ||
73 | } | ||
74 | |||
diff --git a/noncore/multimedia/camera/previewwidget.h b/noncore/multimedia/camera/previewwidget.h index 6b64768..dada301 100644 --- a/noncore/multimedia/camera/previewwidget.h +++ b/noncore/multimedia/camera/previewwidget.h | |||
@@ -25,19 +25,23 @@ class QResizeEvent; | |||
25 | 25 | ||
26 | class PreviewWidget: public QLabel | 26 | class PreviewWidget: public QLabel |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | 29 | ||
30 | public: | 30 | public: |
31 | PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); | 31 | PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); |
32 | virtual ~PreviewWidget(); | 32 | virtual ~PreviewWidget(); |
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | virtual void timerEvent( QTimerEvent* ); | 35 | virtual void timerEvent( QTimerEvent* ); |
36 | virtual void resizeEvent( QResizeEvent* ); | 36 | virtual void resizeEvent( QResizeEvent* ); |
37 | virtual void mousePressEvent( QMouseEvent* ); | ||
38 | |||
39 | signals: | ||
40 | void contextMenuRequested(); | ||
37 | 41 | ||
38 | private: | 42 | private: |
39 | QPixmap p; | 43 | QPixmap p; |
40 | QImage i; | 44 | QImage i; |
41 | }; | 45 | }; |
42 | 46 | ||
43 | #endif | 47 | #endif |
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index b37ae8c..9af0c25 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp | |||
@@ -51,49 +51,60 @@ ZCameraIO::ZCameraIO() | |||
51 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; | 51 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; |
52 | else | 52 | else |
53 | init(); | 53 | init(); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | void ZCameraIO::init() | 57 | void ZCameraIO::init() |
58 | { | 58 | { |
59 | if ( ZCameraIO::_instance ) | 59 | if ( ZCameraIO::_instance ) |
60 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; | 60 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; |
61 | else | 61 | else |
62 | { | 62 | { |
63 | _timer = new QTime(); | ||
63 | setReadMode( STATUS ); | 64 | setReadMode( STATUS ); |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
68 | ZCameraIO::~ZCameraIO() | 69 | ZCameraIO::~ZCameraIO() |
69 | { | 70 | { |
70 | if ( _driver != -1 ) | 71 | if ( _driver != -1 ) |
71 | { | 72 | { |
72 | setReadMode( 0 ); | 73 | setReadMode( 0 ); |
73 | ::close( _driver ); | 74 | ::close( _driver ); |
74 | } | 75 | } |
75 | } | 76 | } |
76 | 77 | ||
77 | 78 | ||
78 | bool ZCameraIO::isOpen() const | 79 | bool ZCameraIO::isOpen() const |
79 | { | 80 | { |
80 | return _driver != -1; | 81 | return _driver != -1; |
81 | } | 82 | } |
82 | 83 | ||
83 | 84 | ||
84 | bool ZCameraIO::isShutterPressed() | 85 | bool ZCameraIO::isShutterPressed() |
85 | { | 86 | { |
86 | return _status[0] == 'S'; | 87 | if ( _timer->elapsed() < 1000 ) //TODO: make this customizable? |
87 | clearShutterLatch(); | 88 | { |
89 | clearShutterLatch(); | ||
90 | return false; | ||
91 | } | ||
92 | if ( _status[0] == 'S' ) | ||
93 | { | ||
94 | _timer->restart(); | ||
95 | clearShutterLatch(); | ||
96 | return true; | ||
97 | } | ||
98 | else return false; | ||
88 | } | 99 | } |
89 | 100 | ||
90 | 101 | ||
91 | bool ZCameraIO::isFinderReversed() const | 102 | bool ZCameraIO::isFinderReversed() const |
92 | { | 103 | { |
93 | return _status[1] == 'M'; | 104 | return _status[1] == 'M'; |
94 | } | 105 | } |
95 | 106 | ||
96 | 107 | ||
97 | bool ZCameraIO::isCapturing() const | 108 | bool ZCameraIO::isCapturing() const |
98 | { | 109 | { |
99 | return _status[2] == 'C'; | 110 | return _status[2] == 'C'; |
@@ -115,38 +126,46 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) | |||
115 | { | 126 | { |
116 | _width = width; | 127 | _width = width; |
117 | _height = height; | 128 | _height = height; |
118 | _zoom = zoom; | 129 | _zoom = zoom; |
119 | _rot = rot; | 130 | _rot = rot; |
120 | _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel | 131 | _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel |
121 | return true; | 132 | return true; |
122 | } | 133 | } |
123 | return false; | 134 | return false; |
124 | } | 135 | } |
125 | 136 | ||
126 | 137 | ||
138 | bool ZCameraIO::setZoom( int zoom ) | ||
139 | { | ||
140 | return setCaptureFrame( _width, _height, zoom*256, _rot ); | ||
141 | } | ||
142 | |||
143 | |||
127 | void ZCameraIO::setReadMode( int mode ) | 144 | void ZCameraIO::setReadMode( int mode ) |
128 | { | 145 | { |
129 | char b[10]; | 146 | char b[10]; |
130 | sprintf( b, "M=%d", mode ); | 147 | sprintf( b, "M=%d", mode ); |
131 | write( b, mode <= 9 ? 3 : 4 ); | 148 | write( b, mode <= 9 ? 3 : 4 ); |
132 | if ( mode & 1 ) // STATUS bit is set | 149 | if ( mode & STATUS ) // STATUS bit is set |
150 | { | ||
133 | read( _status, 4 ); | 151 | read( _status, 4 ); |
152 | if ( isShutterPressed() ) emit shutterClicked(); | ||
153 | } | ||
134 | } | 154 | } |
135 | 155 | ||
136 | 156 | ||
137 | void ZCameraIO::clearShutterLatch() | 157 | void ZCameraIO::clearShutterLatch() |
138 | { | 158 | { |
139 | char b = 'B'; | 159 | write( "B", 1 ); |
140 | write( &b, 1 ); | ||
141 | } | 160 | } |
142 | 161 | ||
143 | 162 | ||
144 | bool ZCameraIO::read( char* b, int len ) | 163 | bool ZCameraIO::read( char* b, int len ) |
145 | { | 164 | { |
146 | #ifndef NO_TIMING | 165 | #ifndef NO_TIMING |
147 | QTime t; | 166 | QTime t; |
148 | t.start(); | 167 | t.start(); |
149 | #endif | 168 | #endif |
150 | int rlen = ::read( _driver, b, len ); | 169 | int rlen = ::read( _driver, b, len ); |
151 | #ifndef NO_TIMING | 170 | #ifndef NO_TIMING |
152 | int time = t.elapsed(); | 171 | int time = t.elapsed(); |
@@ -203,28 +222,43 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
203 | *p = *bp; | 222 | *p = *bp; |
204 | p++; | 223 | p++; |
205 | bp++; | 224 | bp++; |
206 | *p = *bp; | 225 | *p = *bp; |
207 | p++; | 226 | p++; |
208 | bp++; | 227 | bp++; |
209 | } | 228 | } |
210 | } | 229 | } |
211 | 230 | ||
212 | return true; | 231 | return true; |
213 | } | 232 | } |
214 | 233 | ||
234 | |||
215 | bool ZCameraIO::snapshot( unsigned char* buf ) | 235 | bool ZCameraIO::snapshot( unsigned char* buf ) |
216 | { | 236 | { |
217 | setReadMode( IMAGE | XFLIP | YFLIP ); | 237 | setReadMode( IMAGE | XFLIP | YFLIP ); |
218 | 238 | ||
219 | read( (char*) buf, _readlen ); | 239 | read( (char*) buf, _readlen ); |
220 | 240 | ||
221 | /* //TESTCODE | 241 | /* //TESTCODE |
222 | int fd = open( "/tmp/cam", O_RDONLY ); | 242 | int fd = open( "/tmp/cam", O_RDONLY ); |
223 | if ( ::read( fd, (char*) buf, 76800 ) != 76800 ) | 243 | if ( ::read( fd, (char*) buf, 76800 ) != 76800 ) |
224 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; | 244 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; |
225 | // TESTCODE */ | 245 | // TESTCODE */ |
226 | 246 | ||
227 | 247 | ||
228 | return true; | 248 | return true; |
229 | } | 249 | } |
230 | 250 | ||
251 | |||
252 | void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) | ||
253 | { | ||
254 | int pw = _width; | ||
255 | int ph = _height; | ||
256 | if ( _rot ) | ||
257 | setCaptureFrame( h, w, zoom*256, true ); | ||
258 | else | ||
259 | setCaptureFrame( w, h, zoom*256, false ); | ||
260 | snapshot( image ); | ||
261 | setCaptureFrame( pw, ph, _zoom, _rot ); | ||
262 | } | ||
263 | |||
264 | |||
diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h index 9d4b1d7..edce143 100644 --- a/noncore/multimedia/camera/zcameraio.h +++ b/noncore/multimedia/camera/zcameraio.h | |||
@@ -7,59 +7,75 @@ | |||
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #ifndef ZCAMERAIO_H | 16 | #ifndef ZCAMERAIO_H |
17 | #define ZCAMERAIO_H | 17 | #define ZCAMERAIO_H |
18 | 18 | ||
19 | #include <qobject.h> | ||
20 | |||
19 | class QImage; | 21 | class QImage; |
22 | class QTime; | ||
20 | 23 | ||
21 | class ZCameraIO | 24 | class ZCameraIO : public QObject |
22 | { | 25 | { |
26 | Q_OBJECT | ||
27 | |||
23 | public: | 28 | public: |
24 | virtual ~ZCameraIO(); | 29 | virtual ~ZCameraIO(); |
25 | 30 | ||
26 | enum ReadMode | 31 | enum ReadMode |
27 | { | 32 | { |
28 | IMAGE = 0, STATUS = 1, | 33 | IMAGE = 0, STATUS = 1, |
29 | FASTER = 0, BETTER = 2, | 34 | FASTER = 0, BETTER = 2, |
30 | XNOFLIP = 0, XFLIP = 4, | 35 | XNOFLIP = 0, XFLIP = 4, |
31 | YNOFLIP = 0, YFLIP = 8 | 36 | YNOFLIP = 0, YFLIP = 8 |
32 | }; | 37 | }; |
33 | 38 | ||
39 | // low level interface | ||
40 | |||
34 | bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); | 41 | bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); |
42 | bool setZoom( int zoom = 0 ); | ||
35 | void setReadMode( int = IMAGE | XFLIP | YFLIP ); | 43 | void setReadMode( int = IMAGE | XFLIP | YFLIP ); |
36 | 44 | ||
37 | bool isShutterPressed(); // not const, because it calls clearShutterLatch | 45 | bool isShutterPressed(); // not const, because it calls clearShutterLatch |
38 | bool isAvailable() const; | 46 | bool isAvailable() const; |
39 | bool isCapturing() const; | 47 | bool isCapturing() const; |
40 | bool isFinderReversed() const; | 48 | bool isFinderReversed() const; |
41 | bool isOpen() const; | ||
42 | 49 | ||
43 | bool snapshot( QImage* ); | ||
44 | bool snapshot( unsigned char* ); | 50 | bool snapshot( unsigned char* ); |
51 | bool snapshot( QImage* ); | ||
52 | |||
53 | // high level interface | ||
54 | bool isOpen() const; | ||
45 | static ZCameraIO* instance(); | 55 | static ZCameraIO* instance(); |
56 | void captureFrame( int w, int h, int zoom, QImage* image ); | ||
46 | 57 | ||
47 | protected: | 58 | protected: |
48 | ZCameraIO(); | 59 | ZCameraIO(); |
49 | void clearShutterLatch(); | 60 | void clearShutterLatch(); |
50 | void init(); | 61 | void init(); |
51 | bool read( char*, int ); | 62 | bool read( char*, int ); |
52 | bool write( char*, int = 0 ); | 63 | bool write( char*, int = 0 ); |
53 | 64 | ||
65 | signals: | ||
66 | void shutterClicked(); | ||
67 | |||
54 | private: | 68 | private: |
55 | int _driver; | 69 | int _driver; |
56 | char _status[4]; | 70 | char _status[4]; |
57 | static ZCameraIO* _instance; | 71 | static ZCameraIO* _instance; |
58 | int _height; | 72 | int _height; |
59 | int _width; | 73 | int _width; |
60 | int _zoom; | 74 | int _zoom; |
61 | bool _rot; | 75 | bool _rot; |
62 | int _readlen; | 76 | int _readlen; |
77 | |||
78 | QTime* _timer; | ||
63 | }; | 79 | }; |
64 | 80 | ||
65 | #endif | 81 | #endif |