summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-12 15:02:32 (UTC)
committer mickeyl <mickeyl>2003-04-12 15:02:32 (UTC)
commit2cc909c36a779d1041a3382939f8ad41d84b0fc5 (patch) (unidiff)
tree42c95673d72f7ecb7a8f4acbb0f517dd75ecc167
parent11861d35730cee70920aa6797ba12263bbcce081 (diff)
downloadopie-2cc909c36a779d1041a3382939f8ad41d84b0fc5.zip
opie-2cc909c36a779d1041a3382939f8ad41d84b0fc5.tar.gz
opie-2cc909c36a779d1041a3382939f8ad41d84b0fc5.tar.bz2
- make main layout a full preview window and think about configuring capturing parameters later...adding an on-demand-applet to the taskbar would be spiffy
- portrait or landscape mode is now self-configuring thanks to life-rotation :-D
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/.cvsignore4
-rw-r--r--noncore/multimedia/camera/camera.pro2
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp41
-rw-r--r--noncore/multimedia/camera/mainwindow.h7
-rw-r--r--noncore/multimedia/camera/mainwindowbase.ui246
-rw-r--r--noncore/multimedia/camera/previewwidget.cpp21
-rw-r--r--noncore/multimedia/camera/previewwidget.h4
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp24
8 files changed, 87 insertions, 262 deletions
diff --git a/noncore/multimedia/camera/.cvsignore b/noncore/multimedia/camera/.cvsignore
index d89e3af..737c5b2 100644
--- a/noncore/multimedia/camera/.cvsignore
+++ b/noncore/multimedia/camera/.cvsignore
@@ -1,5 +1,5 @@
1moc
2obj
1config.in 3config.in
2mainwindowbase.h
3mainwindowbase.cpp
4Makefile 4Makefile
5 5
diff --git a/noncore/multimedia/camera/camera.pro b/noncore/multimedia/camera/camera.pro
index 2d1faa3..16da0c9 100644
--- a/noncore/multimedia/camera/camera.pro
+++ b/noncore/multimedia/camera/camera.pro
@@ -11,13 +11,13 @@ HEADERS = zcameraio.h \
11SOURCES = zcameraio.cpp \ 11SOURCES = zcameraio.cpp \
12 previewwidget.cpp \ 12 previewwidget.cpp \
13 mainwindow.cpp \ 13 mainwindow.cpp \
14 main.cpp 14 main.cpp
15 15
16INCLUDEPATH += $(OPIEDIR)/include 16INCLUDEPATH += $(OPIEDIR)/include
17DEPENDPATH += $(OPIEDIR)/include 17DEPENDPATH += $(OPIEDIR)/include
18LIBS += -lqpe -lopiecore2 18LIBS += -lqpe -lopiecore2
19INTERFACES = mainwindowbase.ui 19INTERFACES =
20TARGET = opiecam 20TARGET = opiecam
21 21
22include ( $(OPIEDIR)/include.pro ) 22include ( $(OPIEDIR)/include.pro )
23 23
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 8578bce..7080e63 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -9,46 +9,75 @@
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 "mainwindowbase.h" 17#include "previewwidget.h"
18#include "zcameraio.h" 18#include "zcameraio.h"
19 19
20#include <qvbox.h> 20#include <qvbox.h>
21#include <qcombobox.h> 21#include <qcombobox.h>
22#include <qdatastream.h>
22#include <qpushbutton.h> 23#include <qpushbutton.h>
23#include <qlabel.h> 24#include <qlabel.h>
24#include <qdirectpainter_qws.h> 25#include <qdirectpainter_qws.h>
25#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/qcopenvelope_qws.h>
26#include <opie/ofiledialog.h> 28#include <opie/ofiledialog.h>
27 29
30#include <opie2/odebug.h>
31
28#include <assert.h> 32#include <assert.h>
29 33
30CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 34CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
31 :QMainWindow( parent, name, f ) 35 :QMainWindow( parent, name, f )
32{ 36{
33 mw = new MainWindowBase( this, "main widget" ); 37 _rotation = 270; //TODO: grab these from the actual settings
34 ZCameraIO::instance()->setCaptureFrame( 240, 160, 256 ); 38
35 setCentralWidget( mw ); 39 preview = new PreviewWidget( this, "camera preview widget" );
36 mw->show(); 40 //setCentralWidget( preview ); <--- don't do this!
41 preview->resize( QSize( 240, 288 ) );
42 preview->show();
43
44 // construct a System Channel to receive setRotation messages
45 _sysChannel = new QCopChannel( "QPE/System", this );
46 connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ),
47 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
37 48
38 connect( mw->zoom, SIGNAL( activated( int ) ), this, SLOT( changeZoom(int) ) );
39}; 49};
40 50
41 51
42CameraMainWindow::~CameraMainWindow() 52CameraMainWindow::~CameraMainWindow()
43{ 53{
44} 54}
45 55
46 56
57void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
58{
59 QDataStream stream( data, IO_ReadOnly );
60 odebug << "received system message: " << msg << oendl;
61 if ( msg == "setCurrentRotation(int)" )
62 {
63 stream >> _rotation;
64 odebug << "received setCurrentRotation(" << _rotation << ")" << oendl;
65
66 switch ( _rotation )
67 {
68 case 270: preview->resize( QSize( 240, 288 ) ); break;
69 case 180: preview->resize( QSize( 320, 208 ) ); break;
70 default: assert( 0 ); // not yet handled
71 }
72 }
73}
74
75
47void CameraMainWindow::changeZoom( int zoom ) 76void CameraMainWindow::changeZoom( int zoom )
48{ 77{
49 int z; 78 int z;
50 switch ( zoom ) 79 switch ( zoom )
51 { 80 {
52 case 0: z = 128; break; 81 case 0: z = 128; break;
53 case 1: z = 256; break; 82 case 1: z = 256; break;
54 case 2: z = 512; break; 83 case 2: z = 512; break;
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h
index 7ccdcf8..cc12840 100644
--- a/noncore/multimedia/camera/mainwindow.h
+++ b/noncore/multimedia/camera/mainwindow.h
@@ -20,27 +20,32 @@
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
24class QIconSet; 24class QIconSet;
25class QToolButton; 25class QToolButton;
26class QLabel; 26class QLabel;
27class MainWindowBase; 27class MainWindowBase;
28class QCopChannel;
29class PreviewWidget;
28 30
29class CameraMainWindow: public QMainWindow 31class CameraMainWindow: public QMainWindow
30{ 32{
31 Q_OBJECT 33 Q_OBJECT
32 34
33 public: 35 public:
34 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); 36 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 );
35 virtual ~CameraMainWindow(); 37 virtual ~CameraMainWindow();
36 38
37 public slots: 39 public slots:
38 void changeZoom( int ); 40 void changeZoom( int );
41 void systemMessage( const QCString&, const QByteArray& );
39 42
40 protected: 43 protected:
41 44
42 private: 45 private:
43 MainWindowBase* mw; 46 PreviewWidget* preview;
47 int _rotation;
48 QCopChannel* _sysChannel;
44}; 49};
45 50
46#endif 51#endif
diff --git a/noncore/multimedia/camera/mainwindowbase.ui b/noncore/multimedia/camera/mainwindowbase.ui
deleted file mode 100644
index 8da884a..0000000
--- a/noncore/multimedia/camera/mainwindowbase.ui
+++ b/dev/null
@@ -1,246 +0,0 @@
1<!DOCTYPE UI><UI>
2<class>MainWindowBase</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>MainWindowBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>242</width>
15 <height>329</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Form1</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <grid>
29 <property stdset="1">
30 <name>margin</name>
31 <number>0</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <widget row="1" column="0" >
38 <class>QLayoutWidget</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>Layout1</cstring>
42 </property>
43 <hbox>
44 <property stdset="1">
45 <name>margin</name>
46 <number>0</number>
47 </property>
48 <property stdset="1">
49 <name>spacing</name>
50 <number>6</number>
51 </property>
52 <widget>
53 <class>QLabel</class>
54 <property stdset="1">
55 <name>name</name>
56 <cstring>TextLabel1</cstring>
57 </property>
58 <property stdset="1">
59 <name>text</name>
60 <string>Reso:</string>
61 </property>
62 </widget>
63 <widget>
64 <class>QComboBox</class>
65 <item>
66 <property>
67 <name>text</name>
68 <string>240x160</string>
69 </property>
70 </item>
71 <item>
72 <property>
73 <name>text</name>
74 <string>480x320</string>
75 </property>
76 </item>
77 <property stdset="1">
78 <name>name</name>
79 <cstring>resolution</cstring>
80 </property>
81 </widget>
82 <widget>
83 <class>QLabel</class>
84 <property stdset="1">
85 <name>name</name>
86 <cstring>TextLabel2</cstring>
87 </property>
88 <property stdset="1">
89 <name>text</name>
90 <string>Zoom:</string>
91 </property>
92 </widget>
93 <widget>
94 <class>QComboBox</class>
95 <item>
96 <property>
97 <name>text</name>
98 <string>Half</string>
99 </property>
100 </item>
101 <item>
102 <property>
103 <name>text</name>
104 <string>Full</string>
105 </property>
106 </item>
107 <item>
108 <property>
109 <name>text</name>
110 <string>Double</string>
111 </property>
112 </item>
113 <property stdset="1">
114 <name>name</name>
115 <cstring>zoom</cstring>
116 </property>
117 </widget>
118 </hbox>
119 </widget>
120 <widget row="2" column="0" >
121 <class>QLayoutWidget</class>
122 <property stdset="1">
123 <name>name</name>
124 <cstring>Layout2</cstring>
125 </property>
126 <hbox>
127 <property stdset="1">
128 <name>margin</name>
129 <number>0</number>
130 </property>
131 <property stdset="1">
132 <name>spacing</name>
133 <number>6</number>
134 </property>
135 <spacer>
136 <property>
137 <name>name</name>
138 <cstring>Spacer1</cstring>
139 </property>
140 <property stdset="1">
141 <name>orientation</name>
142 <enum>Horizontal</enum>
143 </property>
144 <property stdset="1">
145 <name>sizeType</name>
146 <enum>Expanding</enum>
147 </property>
148 <property>
149 <name>sizeHint</name>
150 <size>
151 <width>20</width>
152 <height>20</height>
153 </size>
154 </property>
155 </spacer>
156 <widget>
157 <class>QPushButton</class>
158 <property stdset="1">
159 <name>name</name>
160 <cstring>PushButton1</cstring>
161 </property>
162 <property stdset="1">
163 <name>text</name>
164 <string>Take Photo</string>
165 </property>
166 <property stdset="1">
167 <name>default</name>
168 <bool>true</bool>
169 </property>
170 </widget>
171 <spacer>
172 <property>
173 <name>name</name>
174 <cstring>Spacer2</cstring>
175 </property>
176 <property stdset="1">
177 <name>orientation</name>
178 <enum>Horizontal</enum>
179 </property>
180 <property stdset="1">
181 <name>sizeType</name>
182 <enum>Expanding</enum>
183 </property>
184 <property>
185 <name>sizeHint</name>
186 <size>
187 <width>20</width>
188 <height>20</height>
189 </size>
190 </property>
191 </spacer>
192 </hbox>
193 </widget>
194 <spacer row="3" column="0" >
195 <property>
196 <name>name</name>
197 <cstring>Spacer3</cstring>
198 </property>
199 <property stdset="1">
200 <name>orientation</name>
201 <enum>Vertical</enum>
202 </property>
203 <property stdset="1">
204 <name>sizeType</name>
205 <enum>Expanding</enum>
206 </property>
207 <property>
208 <name>sizeHint</name>
209 <size>
210 <width>20</width>
211 <height>20</height>
212 </size>
213 </property>
214 </spacer>
215 <widget row="0" column="0" >
216 <class>PreviewWidget</class>
217 <property stdset="1">
218 <name>name</name>
219 <cstring>preview</cstring>
220 </property>
221 </widget>
222 </grid>
223</widget>
224<customwidgets>
225 <customwidget>
226 <class>PreviewWidget</class>
227 <header location="local">previewwidget.h</header>
228 <sizehint>
229 <width>240</width>
230 <height>160</height>
231 </sizehint>
232 <container>0</container>
233 <sizepolicy>
234 <hordata>0</hordata>
235 <verdata>0</verdata>
236 </sizepolicy>
237 <pixmap>image0</pixmap>
238 </customwidget>
239</customwidgets>
240<images>
241 <image>
242 <name>image0</name>
243 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
244 </image>
245</images>
246</UI>
diff --git a/noncore/multimedia/camera/previewwidget.cpp b/noncore/multimedia/camera/previewwidget.cpp
index bb84c00..cdeacf6 100644
--- a/noncore/multimedia/camera/previewwidget.cpp
+++ b/noncore/multimedia/camera/previewwidget.cpp
@@ -11,31 +11,50 @@
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>
20
19PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) 21PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f )
20 :QLabel( parent, name, f ) 22 :QLabel( parent, name, f )
21{ 23{
22 setFixedSize( QSize( 240, 160 ) ); 24 #ifndef QT_NO_DEBUG
25 setBackgroundColor( QColor( 255, 0, 0 ) );
26 #else
23 setBackgroundMode( NoBackground ); 27 setBackgroundMode( NoBackground );
28 #endif
29
24 30
25 startTimer( 150 ); 31 startTimer( 150 );
32 //startTimer( 2000 );
26}; 33};
27 34
28 35
29PreviewWidget::~PreviewWidget() 36PreviewWidget::~PreviewWidget()
30{ 37{
31} 38}
32 39
33 40
41void PreviewWidget::resizeEvent( QResizeEvent* e )
42{
43 QLabel::resizeEvent( e );
44 int w = e->size().width();
45 int h = e->size().height();
46 ZCameraIO::instance()->setCaptureFrame( e->size().width(),
47 e->size().height(),
48 256,
49 w < h );
50}
51
52
34void PreviewWidget::timerEvent( QTimerEvent* ) 53void PreviewWidget::timerEvent( QTimerEvent* )
35{ 54{
36 //QDirectPainter fb( this ); 55 //QDirectPainter fb( this );
37 //ZCameraIO::instance()->snapshot( fb.frameBuffer() ); 56 //ZCameraIO::instance()->snapshot( fb.frameBuffer() );
38 57
39 if ( ZCameraIO::instance()->snapshot( &i ) ) 58 if ( ZCameraIO::instance()->snapshot( &i ) )
40 { 59 {
41 p.convertFromImage( i ); 60 p.convertFromImage( i );
diff --git a/noncore/multimedia/camera/previewwidget.h b/noncore/multimedia/camera/previewwidget.h
index c031d95..6b64768 100644
--- a/noncore/multimedia/camera/previewwidget.h
+++ b/noncore/multimedia/camera/previewwidget.h
@@ -15,25 +15,29 @@
15 15
16#ifndef PREVIEWWIDGET_H 16#ifndef PREVIEWWIDGET_H
17#define PREVIEWWIDGET_H 17#define PREVIEWWIDGET_H
18 18
19#include <qlabel.h> 19#include <qlabel.h>
20#include <qimage.h> 20#include <qimage.h>
21#include <qpixmap.h> 21#include <qpixmap.h>
22 22
23class QTimerEvent;
24class QResizeEvent;
25
23class PreviewWidget: public QLabel 26class PreviewWidget: public QLabel
24{ 27{
25 Q_OBJECT 28 Q_OBJECT
26 29
27 public: 30 public:
28 PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); 31 PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
29 virtual ~PreviewWidget(); 32 virtual ~PreviewWidget();
30 33
31 protected: 34 protected:
32 virtual void timerEvent( QTimerEvent* ); 35 virtual void timerEvent( QTimerEvent* );
36 virtual void resizeEvent( QResizeEvent* );
33 37
34 private: 38 private:
35 QPixmap p; 39 QPixmap p;
36 QImage i; 40 QImage i;
37}; 41};
38 42
39#endif 43#endif
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp
index 56b2e13..51771a5 100644
--- a/noncore/multimedia/camera/zcameraio.cpp
+++ b/noncore/multimedia/camera/zcameraio.cpp
@@ -103,16 +103,17 @@ inline bool ZCameraIO::isCapturing() const
103inline bool ZCameraIO::isAvailable() const 103inline bool ZCameraIO::isAvailable() const
104{ 104{
105 return _status[3] == 'A'; 105 return _status[3] == 'A';
106} 106}
107 107
108 108
109bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) 109bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
110{ 110{
111 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl;
111 char b[100]; 112 char b[100];
112 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); 113 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
113 if ( write( b ) ) 114 if ( write( b ) )
114 { 115 {
115 _width = width; 116 _width = width;
116 _height = height; 117 _height = height;
117 _zoom = zoom; 118 _zoom = zoom;
118 _rot = rot; 119 _rot = rot;
@@ -168,28 +169,41 @@ bool ZCameraIO::write( char* buf, int len )
168 odebug << "writing '" << buf << "' to driver." << oendl; 169 odebug << "writing '" << buf << "' to driver." << oendl;
169 170
170 return ::write( _driver, buf, len ) == len; 171 return ::write( _driver, buf, len ) == len;
171} 172}
172 173
173 174
174bool ZCameraIO::snapshot( QImage* image ) 175bool ZCameraIO::snapshot( QImage* image )
175{ 176{
176 setReadMode( IMAGE | XFLIP | YFLIP ); 177 setReadMode( STATUS );
177 char buf[76800]; 178
179 odebug << "finder reversed = " << isFinderReversed() << oendl;
180 odebug << "rotation = " << _rot << oendl;
181
182 if ( _rot ) // Portrait
183 {
184 setReadMode( IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0 );
185 }
186 else // Landscape
187 {
188 setReadMode( IMAGE | XFLIP | YFLIP ); //isFinderReversed() ? 0 : XFLIP );
189 }
190
191 char buf[_readlen];
178 char* bp = buf; 192 char* bp = buf;
179 unsigned char* p; 193 unsigned char* p;
180 194
181 read( bp, _readlen ); 195 read( bp, _readlen );
182 196
183 image->create( 240, 160, 16 ); 197 image->create( _width, _height, 16 );
184 for ( int i = 0; i < 160; ++i ) 198 for ( int i = 0; i < _height; ++i )
185 { 199 {
186 p = image->scanLine( i ); 200 p = image->scanLine( i );
187 for ( int j = 0; j < 240; j++ ) 201 for ( int j = 0; j < _width; j++ )
188 { 202 {
189 *p = *bp; 203 *p = *bp;
190 p++; 204 p++;
191 bp++; 205 bp++;
192 *p = *bp; 206 *p = *bp;
193 p++; 207 p++;
194 bp++; 208 bp++;
195 } 209 }