-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 | 42 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 22 |
7 files changed, 234 insertions, 18 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 @@ -16,5 +16,5 @@ SOURCES = zcameraio.cpp \ INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 +LIBS += -lqpe -lopie -lopiecore2 INTERFACES = TARGET = opiecam 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 @@ -18,8 +18,12 @@ #include "zcameraio.h" +#include <qapplication.h> +#include <qaction.h> #include <qvbox.h> #include <qcombobox.h> #include <qcursor.h> #include <qdatastream.h> +#include <qfile.h> +#include <qimage.h> #include <qlabel.h> #include <qpopupmenu.h> @@ -27,7 +31,10 @@ #include <qmessagebox.h> #include <qdirectpainter_qws.h> +#include <qpe/global.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <opie/ofiledialog.h> +#include <opie/odevice.h> +using namespace Opie; #include <opie2/odebug.h> @@ -36,6 +43,7 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) - :QMainWindow( parent, name, f ) + :QMainWindow( parent, name, f ), _pics( 0 ) { + #ifdef QT_NO_DEBUG if ( !ZCameraIO::instance()->isOpen() ) { @@ -52,4 +60,7 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags return; } + #endif + + init(); _rotation = 270; //TODO: grab these from the actual settings @@ -66,4 +77,6 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); + + connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); }; @@ -74,4 +87,52 @@ CameraMainWindow::~CameraMainWindow() +void CameraMainWindow::init() +{ + // TODO: Save this stuff in config + quality = 50; + zoom = 1; + captureX = 640; + captureY = 480; + captureFormat = "JPEG"; + + resog = new QActionGroup( 0, "reso", true ); + resog->setToggleAction( true ); + new QAction( " 64 x 48", 0, 0, resog, 0, true ); + new QAction( "128 x 96", 0, 0, resog, 0, true ); + new QAction( "192 x 144", 0, 0, resog, 0, true ); + new QAction( "256 x 192", 0, 0, resog, 0, true ); + new QAction( "320 x 240", 0, 0, resog, 0, true ); + new QAction( "384 x 288", 0, 0, resog, 0, true ); + new QAction( "448 x 336", 0, 0, resog, 0, true ); + new QAction( "512 x 384", 0, 0, resog, 0, true ); + new QAction( "576 x 432", 0, 0, resog, 0, true ); + ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); + + qualityg = new QActionGroup( 0, "quality", true ); + qualityg->setToggleAction( true ); + new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); + new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); + ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); + new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); + new QAction( "100 (best)", 0, 0, qualityg, 0, true ); + + zoomg = new QActionGroup( 0, "zoom", true ); + zoomg->setToggleAction( true ); + ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true ); + new QAction( "x 2", 0, 0, zoomg, 0, true ); + + outputg = new QActionGroup( 0, "output", true ); + outputg->setToggleAction( true ); + ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); + new QAction( "PNG", 0, 0, outputg, 0, true ); + new QAction( "BMP", 0, 0, outputg, 0, true ); + + connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); + connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); + connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); + connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); +} + + void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) { @@ -109,13 +170,84 @@ void CameraMainWindow::changeZoom( int zoom ) } - void CameraMainWindow::showContextMenu() { + QPopupMenu reso; + reso.setCheckable( true ); + resog->addTo( &reso ); + + QPopupMenu quality; + quality.setCheckable( true ); + qualityg->addTo( &quality ); + + QPopupMenu zoom; + zoom.setCheckable( true ); + zoomg->addTo( &zoom ); + + QPopupMenu output; + output.setCheckable( true ); + outputg->addTo( &output ); + QPopupMenu m( this ); - m.insertItem( "Item 1" ); - m.insertItem( "Item 1" ); - m.insertItem( "Item 1" ); - m.insertItem( "Item 1" ); + m.insertItem( "&Resolution", &reso ); + m.insertItem( "&Zoom", &zoom ); + m.insertItem( "&Quality", &quality ); + m.insertItem( "&Output As", &output ); m.exec( QCursor::pos() ); } + +void CameraMainWindow::resoMenuItemClicked( QAction* a ) +{ + captureX = a->text().left(3).toInt(); + captureY = a->text().right(3).toInt(); + odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; +} + + +void CameraMainWindow::qualityMenuItemClicked( QAction* a ) +{ + quality = a->text().left(3).toInt(); + odebug << "Quality now: " << quality << oendl; +} + + +void CameraMainWindow::zoomMenuItemClicked( QAction* a ) +{ + zoom = QString( a->text()[2] ).toInt(); + odebug << "Zoom now: " << zoom << oendl; + ZCameraIO::instance()->setZoom( zoom ); +} + + +void CameraMainWindow::outputMenuItemClicked( QAction* a ) +{ + captureFormat = a->text(); + odebug << "Output format now: " << captureFormat << oendl; +} + + +void CameraMainWindow::shutterClicked() +{ + Global::statusMessage( "CAPTURING..." ); + qApp->processEvents(); + + odebug << "Shutter has been pressed" << oendl; + ODevice::inst()->touchSound(); + QString name; + name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); + QImage i; + ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); + QImage im = i.convertDepth( 32 ); + bool result = im.save( name, captureFormat, quality ); + if ( !result ) + { + oerr << "imageio-Problem while writing." << oendl; + Global::statusMessage( "Error!" ); + } + else + { + odebug << captureFormat << "-image has been successfully captured" << oendl; + Global::statusMessage( "Ok." ); + } +} + 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 @@ -22,4 +22,6 @@ #include <qpixmap.h> +class QAction; +class QActionGroup; class QIconSet; class QToolButton; @@ -40,8 +42,13 @@ class CameraMainWindow: public QMainWindow void changeZoom( int ); void systemMessage( const QCString&, const QByteArray& ); - void showContextMenu(); + void resoMenuItemClicked( QAction* ); + void qualityMenuItemClicked( QAction* ); + void zoomMenuItemClicked( QAction* ); + void outputMenuItemClicked( QAction* ); + void shutterClicked(); protected: + void init(); private: @@ -49,4 +56,17 @@ class CameraMainWindow: public QMainWindow int _rotation; QCopChannel* _sysChannel; + + QActionGroup* resog; + QActionGroup* qualityg; + QActionGroup* zoomg; + QActionGroup* outputg; + + int quality; + int zoom; + int captureX; + int captureY; + QString captureFormat; + + int _pics; }; 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 @@ -19,4 +19,6 @@ #include <opie2/odebug.h> +#include <assert.h> + PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) :QLabel( parent, name, f ) @@ -28,7 +30,9 @@ PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) #endif - - startTimer( 150 ); - //startTimer( 2000 ); + #ifndef QT_NO_DEBUG + if ( ZCameraIO::instance()->isOpen() ) startTimer( 1500 ); + #else + if ( ZCameraIO::instance()->isOpen() ) startTimer( 200 ); + #endif }; @@ -63,2 +67,8 @@ void PreviewWidget::timerEvent( QTimerEvent* ) } + +void PreviewWidget::mousePressEvent( QMouseEvent* ) +{ + emit contextMenuRequested(); +} + 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 @@ -35,4 +35,8 @@ class PreviewWidget: public QLabel virtual void timerEvent( QTimerEvent* ); virtual void resizeEvent( QResizeEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + + signals: + void contextMenuRequested(); private: 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 @@ -61,4 +61,5 @@ void ZCameraIO::init() else { + _timer = new QTime(); setReadMode( STATUS ); } @@ -84,6 +85,16 @@ bool ZCameraIO::isOpen() const bool ZCameraIO::isShutterPressed() { - return _status[0] == 'S'; + if ( _timer->elapsed() < 1000 ) //TODO: make this customizable? + { + clearShutterLatch(); + return false; + } + if ( _status[0] == 'S' ) + { + _timer->restart(); clearShutterLatch(); + return true; + } + else return false; } @@ -125,4 +136,10 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) +bool ZCameraIO::setZoom( int zoom ) +{ + return setCaptureFrame( _width, _height, zoom*256, _rot ); +} + + void ZCameraIO::setReadMode( int mode ) { @@ -130,6 +147,9 @@ void ZCameraIO::setReadMode( int mode ) sprintf( b, "M=%d", mode ); write( b, mode <= 9 ? 3 : 4 ); - if ( mode & 1 ) // STATUS bit is set + if ( mode & STATUS ) // STATUS bit is set + { read( _status, 4 ); + if ( isShutterPressed() ) emit shutterClicked(); + } } @@ -137,6 +157,5 @@ void ZCameraIO::setReadMode( int mode ) void ZCameraIO::clearShutterLatch() { - char b = 'B'; - write( &b, 1 ); + write( "B", 1 ); } @@ -213,4 +232,5 @@ bool ZCameraIO::snapshot( QImage* image ) } + bool ZCameraIO::snapshot( unsigned char* buf ) { @@ -229,2 +249,16 @@ bool ZCameraIO::snapshot( unsigned char* buf ) } + +void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) +{ + int pw = _width; + int ph = _height; + if ( _rot ) + setCaptureFrame( h, w, zoom*256, true ); + else + setCaptureFrame( w, h, zoom*256, false ); + snapshot( image ); + setCaptureFrame( pw, ph, _zoom, _rot ); +} + + 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 @@ -17,8 +17,13 @@ #define ZCAMERAIO_H +#include <qobject.h> + class QImage; +class QTime; -class ZCameraIO +class ZCameraIO : public QObject { + Q_OBJECT + public: virtual ~ZCameraIO(); @@ -32,5 +37,8 @@ class ZCameraIO }; + // low level interface + bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); + bool setZoom( int zoom = 0 ); void setReadMode( int = IMAGE | XFLIP | YFLIP ); @@ -39,9 +47,12 @@ class ZCameraIO bool isCapturing() const; bool isFinderReversed() const; - bool isOpen() const; - bool snapshot( QImage* ); bool snapshot( unsigned char* ); + bool snapshot( QImage* ); + + // high level interface + bool isOpen() const; static ZCameraIO* instance(); + void captureFrame( int w, int h, int zoom, QImage* image ); protected: @@ -52,4 +63,7 @@ class ZCameraIO bool write( char*, int = 0 ); + signals: + void shutterClicked(); + private: int _driver; @@ -61,4 +75,6 @@ class ZCameraIO bool _rot; int _readlen; + + QTime* _timer; }; |