9 Star 32 Fork 10

留天下/截屏软件

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainwindow.cpp 2.73 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2017-09-09 23:57 +08:00 . CatchScreen
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
isPixmapClear=true;
ui->catchAllCheckBox->setChecked(true);
ui->isHideCheckBox->setChecked(false);
this->move((QApplication::desktop()->width()-this->width())/2,
(QApplication::desktop()->height()-this->height())/2);
QObject::connect(ui->Save,SIGNAL(triggered(bool)),this,SLOT(on_saveScreen_clicked()));
QObject::connect(ui->CatchScreen,SIGNAL(triggered(bool)),this,SLOT(on_catchScreenBtn_clicked()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_catchScreenBtn_clicked()
{
if(ui->catchAllCheckBox->isChecked())
{
if(ui->isHideCheckBox->isChecked())
{
timer=new QTimer;
connect(timer,SIGNAL(timeout()),this,SLOT(catchScreen()));
timer->start(ui->delayComBox->currentIndex()*1000);
this->setVisible(false);
}
else
{
this->catchScreen();
}
}
else
{
this->catchSelectScreen();
}
}
void MainWindow::on_saveScreen_clicked()
{
if(!isPixmapClear)
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"../"+QDir::currentPath()+".jpg",
tr("Images (*.png *.gif *.jpg *.bmp)"));
if(!fileName.isEmpty())
Pixmap.save(fileName);
ui->SreeenLabel->clear();
isPixmapClear=true;
}
}
void MainWindow::on_quitBtn_clicked()
{
this->close();
}
void MainWindow::catchScreen()
{
isPixmapClear=false;
QClipboard *clipbord=QApplication::clipboard();
Pixmap=QPixmap::grabWindow(QApplication::desktop()->winId());
int height=QApplication::desktop()->height();
int width=QApplication::desktop()->width();
float dx=260.0f/(float)height;
this->setMinimumSize(width,height);
ui->SreeenLabel->setMaximumSize(width-width*dx,height-260);
ui->SreeenLabel->setPixmap(Pixmap.scaled(QSize(ui->SreeenLabel->width(),ui->SreeenLabel->height())));
disconnect(timer,SIGNAL(timeout()),this,SLOT(catchScreen()));
clipbord->setPixmap(Pixmap);
delete timer;
this->setVisible(true);
}
void MainWindow::catchSelectScreen()
{
CatchDIalog catchDialog;
this->setVisible(false);
catchDialog.exec();
Pixmap=catchDialog.getPixmap();
if(Pixmap.isNull())
{
return;
}
int picHeight=Pixmap.height();
int picWidth=Pixmap.width();
this->setMinimumSize(picWidth+30,picHeight+260);
ui->SreeenLabel->setMinimumSize(picWidth,picHeight);
ui->SreeenLabel->setPixmap(Pixmap);
isPixmapClear=false;
this->setVisible(true);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lsylovews/jiepingruanjian.git
git@gitee.com:lsylovews/jiepingruanjian.git
lsylovews
jiepingruanjian
截屏软件
master

搜索帮助