Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 144 |
1 files changed, 138 insertions, 6 deletions
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 | |||
@@ -17,26 +17,34 @@ | |||
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 ); |
@@ -51,6 +59,9 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags | |||
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 | ||
@@ -65,6 +76,8 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags | |||
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 | ||
@@ -73,6 +86,54 @@ CameraMainWindow::~CameraMainWindow() | |||
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 ); |
@@ -108,14 +169,85 @@ void CameraMainWindow::changeZoom( int zoom ) | |||
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 | |||