screenshot.cpp
- #include "screenshot.h"
- #include "ui_screenshot.h"
- Screenshot::Screenshot(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::Screenshot)
- {
- ui->setupUi(this);
- QObject::connect(ui->shotScreenButton,SIGNAL(clicked()),this,SLOT(newShotScreenSlot()));
- QObject::connect(ui->saveButton,SIGNAL(clicked()),this,SLOT(saveScreenSlot()));
- }
- Screenshot::~Screenshot()
- {
- delete ui;
- }
- void Screenshot::newShotScreenSlot()
- {
- if(ui->hideCheckBox->isChecked())
- {
- this->hide();
- this->timer =new QTimer;
- QObject::connect(this->timer,SIGNAL(timeout()),this,SLOT(shotScreenSlot()));
- this->timer->start(ui->timeSpinBox->value()*1000);
- }
- else
- {
- qApp->beep();
- }
- }
- void Screenshot::shotScreenSlot()
- {
- this->pixmap= QPixmap::grabWindow(QApplication::desktop()->winId());
- ui->screenLabel->setPixmap(pixmap.scaled(ui->screenLabel->size()));
- this->timer->stop();
- this->show();
- }
- #include <QFileDialog>
- #include <QDir>
- #include <QMessageBox>
- void Screenshot::saveScreenSlot()
- {
- QString fileName=QFileDialog::getSaveFileName(this,"Screen Save",QDir::currentPath());
- if(!fileName.isEmpty())
- {
- pixmap.save(fileName);
- }
- else
- {
- QMessageBox::information(this,"Error Message","Select a name ");
- return;
- }
- }
