From 0fba2f2c093578221d35259fd7dac1b7bd36b61e Mon Sep 17 00:00:00 2001 From: 020535 <020535@07accd87-1e0b-0410-939d-c05d8a058e03> Date: Thu, 11 Jun 2009 21:52:53 +0000 Subject: [PATCH] Changes to view reflect changes in the QOpenCamWidget. Most noteably: the trigger button is now part of View, not the widget.. git-svn-id: https://dilbert.hig.no/svn/student/020535/qopencamwidget/trunk@172 07accd87-1e0b-0410-939d-c05d8a058e03 --- view.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/view.cpp b/view.cpp index 72bc101..bd0808a 100644 --- a/view.cpp +++ b/view.cpp @@ -26,32 +26,35 @@ // 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); } -- 2.39.2