]> git.defcon.no Git - qopencamwidget/blobdiff - view.cpp
Changes to view reflect changes in the QOpenCamWidget.
[qopencamwidget] / view.cpp
index 72bc101ca296ec60405807ea6ff677e076112a49..bd0808a06a42553a5130e9dc04f3dd85075b130f 100644 (file)
--- a/view.cpp
+++ b/view.cpp
 
 // The View class is a QMainWindow, used to display our QOpenCamWidget
 // The constructor of the View takes care of setting up the Widget,
-// and handles the result of a user clicking (or activating) the widget's
+// and handles the result of a user clicking (or activating) the
 // "Take snapshot" button.
 
 View::View( QWidget *parent)
        : QMainWindow(parent)
 {
        
-       // Create the widget, setting the Main window (this) as its parent.
-       QOpenCamWidget *cw = new QOpenCamWidget(this);
+       QWidget *cw = new QWidget();
+       QVBoxLayout *layout = new QVBoxLayout();
+
+       // This button will be used to trigger a snapshot later on..
+       QPushButton *trigger = new QPushButton(this);
+       trigger->setText("Take picture");
 
+       // Create the widget, setting the Main window (this) as its parent.
+       QOpenCamWidget *cwcam = new QOpenCamWidget(this);
        // bool QOpenCamWidget::grabCapture(int source) tries to get a
        // video capture handle from OpenCV, using the source number
        // as the device to open. Here I use -1 as the number, meaning
        // "give me any supported and available video devica you can find".
-       if ( cw->grabCapture(-1) )
+       if ( cwcam->grabCapture(-1) )
        {
                // grabCapture() returns true on success. This means that
                // we have a capture device available, and can start streaming
                // video from the device to display on the widget.
                
-               // TODO: Document this feature..
-               cw->setSnapshotVisible(true);
-
                // Video output does not start until QOpenCamWidget::startCapture()
                // is explicitly called.
-               cw->startCapture();
+               cwcam->startCapture();
        }
 
        // The QOpenCamWidget does not provide a video stream for further
@@ -66,8 +69,16 @@ View::View( QWidget *parent)
        // will be available through QOpenCamWidget::imageReady(Qimage);
        // In this sample, I hook that signal up to a slot on this QMainWindow,
        // that saves the image, and exits the application.
-       connect( cw, SIGNAL(imageReady(QImage)), this, SLOT(saveImage(QImage)));
+       connect( cwcam, SIGNAL(imageReady(QImage)), this, SLOT(saveImage(QImage)));
+
+       // To trigger the startSnap(), we hook our previously created
+       // pushbutton to that SLOT.
+       connect( trigger, SIGNAL(clicked()), cwcam, SLOT(startSnap()));
 
+       // Add it all up, and we are ready to run.
+       layout->addWidget(cwcam);
+       layout->addWidget(trigger);
+       cw->setLayout(layout);
        this->setCentralWidget(cw);
 }