-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 36 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 2 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 2 |
4 files changed, 42 insertions, 8 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 7080e63..34ebe9e 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp @@ -1,89 +1,121 @@ /********************************************************************** ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "mainwindow.h" #include "previewwidget.h" #include "zcameraio.h" #include <qvbox.h> #include <qcombobox.h> +#include <qcursor.h> #include <qdatastream.h> -#include <qpushbutton.h> #include <qlabel.h> +#include <qpopupmenu.h> +#include <qpushbutton.h> +#include <qmessagebox.h> #include <qdirectpainter_qws.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <opie/ofiledialog.h> #include <opie2/odebug.h> #include <assert.h> CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) :QMainWindow( parent, name, f ) { + if ( !ZCameraIO::instance()->isOpen() ) + { + QVBox* v = new QVBox( this ); + v->setMargin( 10 ); + QLabel* l1 = new QLabel( v ); + l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); + QLabel* l2 = new QLabel( v ); + l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" + "* Is the sharpzdc_cs module loaded ?<br>" + "* Is /dev/sharpzdc read/writable ?<p>" ); + connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); + setCentralWidget( v ); + return; + } + _rotation = 270; //TODO: grab these from the actual settings preview = new PreviewWidget( this, "camera preview widget" ); //setCentralWidget( preview ); <--- don't do this! preview->resize( QSize( 240, 288 ) ); preview->show(); // construct a System Channel to receive setRotation messages _sysChannel = new QCopChannel( "QPE/System", this ); connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); + connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); }; CameraMainWindow::~CameraMainWindow() { } void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) { QDataStream stream( data, IO_ReadOnly ); odebug << "received system message: " << msg << oendl; if ( msg == "setCurrentRotation(int)" ) { stream >> _rotation; odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; switch ( _rotation ) { case 270: preview->resize( QSize( 240, 288 ) ); break; case 180: preview->resize( QSize( 320, 208 ) ); break; - default: assert( 0 ); // not yet handled + default: QMessageBox::warning( this, "opie-camera", + "This rotation is not supported.\n" + "Supported are 180° and 270°" ); } } } void CameraMainWindow::changeZoom( int zoom ) { int z; switch ( zoom ) { case 0: z = 128; break; case 1: z = 256; break; case 2: z = 512; break; default: assert( 0 ); break; } ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); } + +void CameraMainWindow::showContextMenu() +{ + QPopupMenu m( this ); + m.insertItem( "Item 1" ); + m.insertItem( "Item 1" ); + m.insertItem( "Item 1" ); + m.insertItem( "Item 1" ); + m.exec( QCursor::pos() ); +} + diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h index cc12840..df66204 100644 --- a/noncore/multimedia/camera/mainwindow.h +++ b/noncore/multimedia/camera/mainwindow.h @@ -1,51 +1,53 @@ /********************************************************************** ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> #include <qdatetime.h> #include <qimage.h> #include <qpixmap.h> class QIconSet; class QToolButton; class QLabel; class MainWindowBase; class QCopChannel; class PreviewWidget; class CameraMainWindow: public QMainWindow { Q_OBJECT public: CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); virtual ~CameraMainWindow(); public slots: void changeZoom( int ); void systemMessage( const QCString&, const QByteArray& ); + void showContextMenu(); + protected: private: PreviewWidget* preview; int _rotation; QCopChannel* _sysChannel; }; #endif diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index 51771a5..b37ae8c 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp @@ -30,122 +30,122 @@ #define SHARPZDC "/dev/sharp_zdc" ZCameraIO* ZCameraIO::_instance = 0; ZCameraIO* ZCameraIO::instance() { if ( !ZCameraIO::_instance ) { odebug << "Creating ZCameraIO::_instance" << oendl; ZCameraIO::_instance = new ZCameraIO(); } return ZCameraIO::_instance; } ZCameraIO::ZCameraIO() :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) { _driver = ::open( SHARPZDC, O_RDWR ); if ( _driver == -1 ) oerr << "Can't open camera driver: " << strerror(errno) << oendl; else init(); } void ZCameraIO::init() { if ( ZCameraIO::_instance ) ofatal << "Don't create more than one ZCameraIO instances." << oendl; else { setReadMode( STATUS ); } } ZCameraIO::~ZCameraIO() { if ( _driver != -1 ) { setReadMode( 0 ); ::close( _driver ); } } -inline bool ZCameraIO::isOpen() const +bool ZCameraIO::isOpen() const { return _driver != -1; } -inline bool ZCameraIO::isShutterPressed() +bool ZCameraIO::isShutterPressed() { return _status[0] == 'S'; clearShutterLatch(); } -inline bool ZCameraIO::isFinderReversed() const +bool ZCameraIO::isFinderReversed() const { return _status[1] == 'M'; } -inline bool ZCameraIO::isCapturing() const +bool ZCameraIO::isCapturing() const { return _status[2] == 'C'; } -inline bool ZCameraIO::isAvailable() const +bool ZCameraIO::isAvailable() const { return _status[3] == 'A'; } bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) { odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl; char b[100]; sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); if ( write( b ) ) { _width = width; _height = height; _zoom = zoom; _rot = rot; _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel return true; } return false; } void ZCameraIO::setReadMode( int mode ) { char b[10]; sprintf( b, "M=%d", mode ); write( b, mode <= 9 ? 3 : 4 ); if ( mode & 1 ) // STATUS bit is set read( _status, 4 ); } void ZCameraIO::clearShutterLatch() { char b = 'B'; write( &b, 1 ); } bool ZCameraIO::read( char* b, int len ) { #ifndef NO_TIMING QTime t; t.start(); #endif int rlen = ::read( _driver, b, len ); #ifndef NO_TIMING diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h index bc4926b..9d4b1d7 100644 --- a/noncore/multimedia/camera/zcameraio.h +++ b/noncore/multimedia/camera/zcameraio.h @@ -1,65 +1,65 @@ /********************************************************************** ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef ZCAMERAIO_H #define ZCAMERAIO_H class QImage; class ZCameraIO { public: virtual ~ZCameraIO(); enum ReadMode { IMAGE = 0, STATUS = 1, FASTER = 0, BETTER = 2, XNOFLIP = 0, XFLIP = 4, YNOFLIP = 0, YFLIP = 8 }; bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); void setReadMode( int = IMAGE | XFLIP | YFLIP ); bool isShutterPressed(); // not const, because it calls clearShutterLatch bool isAvailable() const; bool isCapturing() const; bool isFinderReversed() const; - bool isOpen() const; + bool snapshot( QImage* ); bool snapshot( unsigned char* ); static ZCameraIO* instance(); protected: ZCameraIO(); void clearShutterLatch(); void init(); bool read( char*, int ); bool write( char*, int = 0 ); private: int _driver; char _status[4]; static ZCameraIO* _instance; int _height; int _width; int _zoom; bool _rot; int _readlen; }; #endif |