#include "mycameradialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
mycameradialog::mycameradialog(QWidget *parent)
: QDialog(parent)
{
this->setFixedSize(700,400);
camera =new QCamera();
cameraViewfinder =new QCameraViewfinder();
cameraImageCapture = new QCameraImageCapture(camera);
captureBtn = new QPushButton();
saveBtn = new QPushButton();
exitBtn = new QPushButton();
displayLabel = new QLabel();
displayLabel->setFixedSize(160, 120);
displayLabel->setScaledContents(true);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(displayLabel);
rightLayout->addStretch();
rightLayout->addWidget(captureBtn);
rightLayout->addWidget(saveBtn);
rightLayout->addWidget(exitBtn);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(cameraViewfinder);
mainLayout->addLayout(rightLayout);
connect(captureBtn,SIGNAL(clicked()),this,SLOT(captureBtnResponded()));
connect(saveBtn,SIGNAL(clicked()),this,SLOT(saveBtnResponded()));
connect(exitBtn,SIGNAL(clicked()),this,SLOT(exitBtnResponded()));
connect(cameraImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(cameraImageCaptured(int,QImage)));
cameraImageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->setViewfinder(cameraViewfinder);
camera->start();
this->setLayout(mainLayout);
this->translateLanguage();
}
mycameradialog::~mycameradialog()
{
}
void mycameradialog::translateLanguage()
{
this->setWindowTitle("testcapture");
captureBtn->setText(tr("capture"));
saveBtn->setText(tr("save"));
exitBtn->setText(tr("exit"));
}
void mycameradialog::captureBtnResponded()
{
cameraImageCapture->capture();
}
void mycameradialog::saveBtnResponded()
{
const QPixmap *pixmap = displayLabel->pixmap();
// QString filename=QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"+'.jpg');
if(pixmap)
{
pixmap->save("D:\\QT_learing\\myCamera\\picture.jpg");
}
}
void mycameradialog::exitBtnResponded()
{
camera->stop();
this->close();
}
void mycameradialog::cameraImageCaptured(int id, QImage image)
{
displayLabel->setPixmap(QPixmap::fromImage(image));
}