summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/mainwindow.cpp
Side-by-side diff
Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp144
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
@@ -19,2 +19,4 @@
+#include <qapplication.h>
+#include <qaction.h>
#include <qvbox.h>
@@ -23,2 +25,4 @@
#include <qdatastream.h>
+#include <qfile.h>
+#include <qimage.h>
#include <qlabel.h>
@@ -28,2 +32,3 @@
#include <qdirectpainter_qws.h>
+#include <qpe/global.h>
#include <qpe/resource.h>
@@ -31,2 +36,4 @@
#include <opie/ofiledialog.h>
+#include <opie/odevice.h>
+using namespace Opie;
@@ -37,4 +44,5 @@
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() )
@@ -53,2 +61,5 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
}
+ #endif
+
+ init();
@@ -67,2 +78,4 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) );
+
+ connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) );
};
@@ -75,2 +88,50 @@ 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 )
@@ -110,10 +171,25 @@ 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() );
@@ -121 +197,57 @@ void CameraMainWindow::showContextMenu()
+
+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." );
+ }
+}
+