]> git.defcon.no Git - qopencamwidget/blobdiff - qopencamwidget.cpp
Sizes are now code-settable using c'tor parameters. Default values allow for code...
[qopencamwidget] / qopencamwidget.cpp
index eb5e6768d333c06a208725bb8d815c693cbd088c..9b9146165ac9d230619a9332de1b5ef7b0bba4c3 100644 (file)
  *
  * \endcode
  *
+ * Setting sizes is done during construction, and are not modifiable
+ * after the fact:
+ * \code
+ * QOpenCamWidget *cw = new QOpenCamWidget(this,
+ *                      new QSize(320, 240),
+ *                      new QSize(960, 720));
+ * \endcode
+ *
  * \param *parent The parent widget containing this widget, defaults to NULL.
+ * \param *viewSize The size of the image displayed, thus the size of the widget,
+ *          defaults to 640x480
+ * \param *resolution The actual resolution captured, and size of the snapshot
+ *          created, defaults t0 960x720, should be larger than viewSize
  *
  **/   
-QOpenCamWidget::QOpenCamWidget(QWidget *parent
+QOpenCamWidget::QOpenCamWidget(QWidget *parent, QSize *viewSize, QSize *resolution)
        : QWidget(parent) 
 {
        // Setting sane default values (i.e. NULL) for 
@@ -74,6 +86,20 @@ QOpenCamWidget::QOpenCamWidget(QWidget *parent)
        // private QTimer    *frametimer from class definition
        nextFrame = NULL;
        frametimer = NULL;
+        if ( viewSize == NULL )
+        {
+            vSize = new QSize(640, 480);
+        }
+        else vSize = viewSize;
+        if ( resolution == NULL )
+        {
+            res = new QSize(960, 720);
+        }
+        else res = resolution;
+
+        this->setMinimumSize(*vSize);
+        this->setMaximumSize(*vSize);
+
 }
 
 QOpenCamWidget::~QOpenCamWidget(void)
@@ -109,7 +135,8 @@ QOpenCamWidget::paintEvent ( QPaintEvent * event )
                // To make the widget as blazingly fast as possible
                // we output the last captured frame direclty onto
                // the widget area.
-               paint->drawImage(event->rect(), *nextFrame);
+                // It has been slowed down a bit by doing a resize tho...
+                paint->drawImage(event->rect(), nextFrame->scaled( vSize->width(), vSize->height() ));
        }
        else
        {
@@ -142,15 +169,11 @@ QOpenCamWidget::grabCapture(int source)
                qDebug() << "QOpenCamWidget::grabCapture(" << source << ") failed";
                return false;
        }
-        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 960 );
-        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 );
+        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, res->width() );
+        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, res->height() );
 
         cvGrabFrame(capture); // Grab a single frame, do resizing based on it.
         IplImage *image = cvRetrieveFrame(capture);
-        QSize t_size = QSize(image->width,image->height);
-
-       this->setMinimumSize(t_size);
-       this->setMaximumSize(t_size);
 
        return true;
 }