提交 2e3940c2 编写于 作者: 梦里藍天's avatar 梦里藍天

完成

上级
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QScreen>
#include <QString>
#include <QDebug>
#include <QPoint>
#include <QTime>
#include <QMouseEvent>
#include "screen.h"
#include <QSettings>
#include <QMessageBox>
#include <QDateTime>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonParseError>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTextCodec>
#include <QJsonArray>
#include <QClipboard>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
ui->setupUi(this);
beginPos = this->pos();
leftPress = false;
this->setProperty("CanMove", true);
//实现无边框 (Qt::FramelessWindowHint去边框) Qt::WindowStaysOnTopHint 窗体置顶 防止拖到任务栏下面
//this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint|Qt::WindowStaysOnTopHint);
QSettings *configIniWrite = new QSettings("set.ini", QSettings::IniFormat);
ui->lineEdit->setText(configIniWrite->value("key").toString());
ui->lineEdit_2->setText(configIniWrite->value("secret").toString());
delete configIniWrite;
}
void MainWindow::getNewStr(QString newstr) {
ui->textEdit->setPlainText(newstr);
if(ui->checkBox_2->isChecked() == true){
if(ui->lineEdit->text().isEmpty() || ui->lineEdit_2->text().isEmpty()){
QMessageBox::information(NULL, "错误", "百度密钥不能为空");
return;
}
getTextByApi();
}
}
/**
* @brief MainWindow::on_action_2_triggered
* 截图
*/
void MainWindow::on_action_2_triggered(){
//截图之前隐去窗体,不然截图之中就会有窗体的存在
if(ui->checkBox->isChecked() == true){
if( windowState() != Qt::WindowMinimized ){
setWindowState( Qt::WindowMinimized );//最小化父窗体
}
//延时等待父窗体最小化 延时250毫秒
QTime _Timer = QTime::currentTime().addMSecs(250);
while( QTime::currentTime() < _Timer ){
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
}
ui->textEdit->setPlainText("");
ui->textEdit_2->setPlainText("");
Screen *m = new Screen();
QObject::connect(m,SIGNAL(sendNewStr(QString)),this,SLOT(getNewStr(QString)));
m->fullScreen = QPixmap::grabWindow(QApplication::desktop()->winId());
m->showFullScreen();
}
void MainWindow::mousePressEvent(QMouseEvent *e){ //--鼠标按下事件
if (e->button() == Qt::LeftButton){//鼠标左键按下
leftPress = true;
beginPos = e->pos();//鼠标相对窗体的位置
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *e){ //--鼠标移动事件
if (leftPress){//当前鼠标相对窗体的位置-刚按下左键时的相对位置=鼠标移动的大小
move(e->pos() - beginPos + this->pos()); //鼠标移动的大小+窗体原来的位置=窗体移动后的位置
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e){ //--鼠标释放(松开)事件
leftPress = false;
}
void MainWindow::enterEvent(QEvent *e){ //--鼠标进入事件
if(this->pos().y()<=0){//鼠标进入并且已经贴边
move(pos().x(),0);//弹出整个窗体
}
}
void MainWindow::leaveEvent(QEvent *e){//--鼠标离开事件
if(this->pos().y()<=0){//窗体贴在屏幕上边
move(pos().x(),-29);//贴边
}
}
MainWindow::~MainWindow(){
delete ui;
}
/**
* @brief MainWindow::on_action_triggered
* 保存百度接口密钥
*/
void MainWindow::on_action_triggered(){
QString key = ui->lineEdit->text();
QString secret = ui->lineEdit_2->text();
QSettings *configIniWrite = new QSettings("set.ini", QSettings::IniFormat);
//向ini文件中写入内容,setValue函数的两个参数是键值对
configIniWrite->setValue("key", key);
configIniWrite->setValue("secret", secret);
//写入完成后删除指针
delete configIniWrite;
QMessageBox::information(NULL, "成功", "保存成功");
}
/**
* @brief MainWindow::getTextByApi
* 通过百度api获取图片内容
*/
void MainWindow::getTextByApi(){
getAccessToken();
recognition();
}
/**
* @brief MainWindow::recognition
* 通用文字识别
*/
void MainWindow::recognition(){
QString parm = ui->textEdit->toPlainText();
if(parm.isEmpty()){
QMessageBox::information(NULL, "错误", "图像数据不能为空");
return;
}
nam = new QNetworkAccessManager(this);
QUrl url;
if(ui->checkBox_4->isChecked()){
url.setUrl("https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token="+accessToken);
}else{
url.setUrl("https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token="+accessToken);
}
QNetworkRequest request;
request.setUrl(url);
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
QByteArray byteArr;
byteArr.append("image=");
byteArr.append(QUrl::toPercentEncoding(parm));
connect(nam, &QNetworkAccessManager::finished,this, &MainWindow::recognitionRequestFinished);
QNetworkReply* reply = nam->post(request,byteArr);
}
/**
* @brief MainWindow::getAccessToken
* 获取百度Access Token
*/
void MainWindow::getAccessToken(){
QString key = ui->lineEdit->text();
QString secret = ui->lineEdit_2->text();
QSettings *configIniWrite = new QSettings("set.ini", QSettings::IniFormat);
QDateTime time = QDateTime::currentDateTime(); //获取当前时间
int timeT = time.toTime_t(); //将当前时间转为时间戳
if((configIniWrite->value("tokenTime").toInt() + 30*24*3600) < timeT){
nam = new QNetworkAccessManager(this);
QString parm = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="+key+"&client_secret="+secret+"&";
QUrl url(parm);
connect(nam, &QNetworkAccessManager::finished,this, &MainWindow::getAccessTokenRequestFinished);
QNetworkReply* reply = nam->get(QNetworkRequest(url));
}else{
accessToken = configIniWrite->value("accessToken").toString();
}
}
/**
* @brief MainWindow::requestFinished
* @param reply
* 获取access_token后的信号槽
*/
void MainWindow::getAccessTokenRequestFinished(QNetworkReply* reply) {
QNetworkReply::NetworkError err = reply->error();
if(err != QNetworkReply::NoError) {
qDebug() << "Failed: " << reply->errorString();
}else {
// 获取返回内容
QJsonParseError json_error;
QJsonDocument parse_doucment = QJsonDocument::fromJson(reply->readAll(), &json_error);
if(parse_doucment.isObject()){
QJsonObject obj = parse_doucment.object();
accessToken = obj.take("access_token").toString();
QSettings *configIniWrite = new QSettings("set.ini", QSettings::IniFormat);
//向ini文件中写入内容,setValue函数的两个参数是键值对
configIniWrite->setValue("accessToken", accessToken);
QDateTime time = QDateTime::currentDateTime(); //获取当前时间
int timeT = time.toTime_t(); //将当前时间转为时间戳
configIniWrite->setValue("tokenTime", timeT);
//写入完成后删除指针
delete configIniWrite;
}
}
nam->deleteLater();
}
/**
* @brief MainWindow::recognitionRequestFinished
* @param reply
* 文字识别的信号槽
*/
void MainWindow::recognitionRequestFinished(QNetworkReply* reply){
QNetworkReply::NetworkError err = reply->error();
//qDebug()<<reply->readAll();
if(err != QNetworkReply::NoError) {
qDebug() << "Failed: " << reply->errorString();
}else {
// 获取返回内容
QJsonParseError json_error;
QJsonDocument parse_doucment = QJsonDocument::fromJson(reply->readAll(), &json_error);
if(parse_doucment.isObject()){
QJsonObject obj = parse_doucment.object();
int wordsNum = obj.take("words_result_num").toInt();
if(wordsNum > 0){
QString res;
QJsonArray jsonArr = obj.take("words_result").toArray();
for(int i=0;i<wordsNum;i++){
res.append(jsonArr[i].toObject().take("words").toString());
res.append("<br>");
}
ui->textEdit_2->setText(res);
if(!res.isEmpty()&&ui->checkBox_3->isChecked()){
QClipboard *board = QApplication::clipboard();
board->setText(res);
}
}else{
QMessageBox::information(NULL, "提示", "无法识别图片内容");
}
}
}
nam->deleteLater();
}
/**
* @brief MainWindow::on_action_3_triggered
* 识别按钮
*/
void MainWindow::on_action_3_triggered(){
if(ui->lineEdit->text().isEmpty() || ui->lineEdit_2->text().isEmpty()){
QMessageBox::information(NULL, "错误", "百度密钥不能为空");
return;
}
getTextByApi();
}
/**
* @brief MainWindow::on_action_4_triggered
* 复制
*/
void MainWindow::on_action_4_triggered(){
QClipboard *board = QApplication::clipboard();
board->setText(ui->textEdit_2->toPlainText());
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QNetworkReply>
#include <QNetworkAccessManager>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void enterEvent(QEvent *e); //--鼠标进入事件
void leaveEvent(QEvent *e); //--鼠标离开事件
void mousePressEvent(QMouseEvent *e); //--鼠标按下事件
void mouseMoveEvent(QMouseEvent *e); //--鼠标移动事件
void mouseReleaseEvent(QMouseEvent *e); //--鼠标释放(松开)事件
void setMainTextEdit(QString hex);
void getAccessToken();
void getTextByApi();
void recognition();
private slots:
void on_action_2_triggered();
void getNewStr(QString);
void getAccessTokenRequestFinished(QNetworkReply* reply);
void recognitionRequestFinished(QNetworkReply* reply);
void on_action_triggered();
void on_action_3_triggered();
void on_action_4_triggered();
private:
Ui::MainWindow *ui;
bool leftPress;
QPoint beginPos;
QString accessToken;
QNetworkAccessManager *nam;
};
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>620</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>620</width>
<height>620</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>620</width>
<height>620</height>
</size>
</property>
<property name="windowTitle">
<string>OCR-QQ306524624</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>截图隐藏窗口</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>601</width>
<height>221</height>
</rect>
</property>
<property name="title">
<string>截图BASE64结果</string>
</property>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>581</width>
<height>191</height>
</rect>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>601</width>
<height>231</height>
</rect>
</property>
<property name="title">
<string>图片识别结果</string>
</property>
<widget class="QTextEdit" name="textEdit_2">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>581</width>
<height>201</height>
</rect>
</property>
</widget>
</widget>
<widget class="QCheckBox" name="checkBox_2">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>自动识别</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>200</x>
<y>10</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>百度API Key</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>200</x>
<y>40</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>百度Secret Key</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>300</x>
<y>10</y>
<width>311</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>300</x>
<y>40</y>
<width>311</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>130</x>
<y>70</y>
<width>481</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>默认通用识别50000次/天,高精度500次/天;不保证并发;最短边至少15px,最长边最大4096px</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_3">
<property name="geometry">
<rect>
<x>100</x>
<y>40</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>自动复制</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_4">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>高精度识别</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_2"/>
<addaction name="action_3"/>
<addaction name="action_4"/>
<addaction name="action"/>
</widget>
<action name="action_2">
<property name="text">
<string>截图 Ctrl+J</string>
</property>
<property name="shortcut">
<string>Ctrl+J</string>
</property>
</action>
<action name="action_3">
<property name="text">
<string>识别</string>
</property>
</action>
<action name="action_4">
<property name="text">
<string>复制</string>
</property>
</action>
<action name="action">
<property name="text">
<string>保存密钥</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
#-------------------------------------------------
#
# Project created by QtCreator 2019-03-08T14:22:28
#
#-------------------------------------------------
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ocr
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
screen.cpp
HEADERS += \
mainwindow.h \
screen.h
FORMS += \
mainwindow.ui \
screen.ui
#include "screen.h"
#include <QDebug>
#include <QImage>
#include <QBuffer>
#include <QString>
#include "mainwindow.h"
Screen::Screen(QWidget *parent) :QWidget(parent){
beginPos = QPoint(-1,-1);
endPos = beginPos;
leftPres = false;
setMouseTracking(true);//开启鼠标实时追踪,实时的显示鼠标的位置
rect = new QRect(0,0,QApplication::desktop()->width(),QApplication::desktop()->height());
menu = new QMenu(this);//创建右键菜单
menu->addAction("百度识别(ALT+B)", this, SLOT(baiduDiscern()));
menu->addAction("复制(CTRL+C)", this, SLOT(copyScreen()));
menu->addAction("截图另存为(ALT+C)", this, SLOT(saveScreenOther()));
menu->addAction("全屏截图(ALT+A)", this, SLOT(grapFullScreen()));
menu->addAction("退出截图(ESC)", this, SLOT(hide()));
}
void Screen::copyScreen() //将截图复制到粘贴板
{
QGuiApplication::clipboard()->setPixmap(fullScreen.copy(*rect));
}
void Screen::baiduDiscern(){
QImage image = fullScreen.copy(*rect).toImage();
QByteArray ba;
QBuffer buf(&ba);
image.save(&buf, "jpg");
QByteArray hexed = ba.toBase64();
buf.close();
emit sendNewStr(QString(hexed));
close();
}
void Screen::contextMenuEvent(QContextMenuEvent *) //右键菜单事件
{
this->setCursor(Qt::ArrowCursor);//设置鼠标的样式为箭头
menu->exec(cursor().pos());//菜单显示的位置跟随鼠标
}
void Screen::mousePressEvent(QMouseEvent *e) //--鼠标按下事件
{
//添加menu->isActiveWindow()条件是为了在右键菜单时不进行截图区域调整
if (e->button() == Qt::LeftButton && !menu->isActiveWindow())//鼠标左键按下
{
leftPres = true;
setBeginPos(e->pos());//鼠标相对窗体的位置,记录截图的开始位置
}
}
void Screen::mouseMoveEvent(QMouseEvent *e) //--鼠标移动事件
{
if(leftPres)
{
setEndPos(e->pos());//不断的更新截图的结束位置
update();//重绘、触发画图事件
}
}
void Screen::mouseReleaseEvent(QMouseEvent *e) //--鼠标释放(松开)事件
{
if(e->button() == Qt::LeftButton)//鼠标左键释放
{
leftPres = false;
setEndPos(e->pos());//记录截图的结束位置
//使得起始点在左上角,结束点在右下角
if(beginPos.x()>endPos.x())
{
beginPos.setX(beginPos.x() + endPos.x());
endPos.setX(beginPos.x() - endPos.x());
beginPos.setX(beginPos.x() - endPos.x());
}
if(beginPos.y()>endPos.y())
{
beginPos.setY(beginPos.y() + endPos.y());
endPos.setY(beginPos.y() - endPos.y());
beginPos.setY(beginPos.y() - endPos.y());
}
rect->setRect(beginPos.x(),beginPos.y(),endPos.x()-beginPos.x(),endPos.y()-beginPos.y());
}
}
QPoint Screen::getBeginPos()//获取鼠标的起始位置
{
return beginPos;
}
QPoint Screen::getEndPos()//获取鼠标的结束位置
{
return endPos;
}
void Screen::setBeginPos(QPoint p)//设置鼠标的起始位置
{
this->beginPos = p;
}
void Screen::setEndPos(QPoint p)//设置鼠标的结束位置
{
this->endPos = p;
}
void Screen::paintEvent(QPaintEvent *) //--画图事件
{
QPainter painter(this); //将当前窗体对象设置为画布
QPen pen;
pen.setColor(Qt::red);//设置笔色
pen.setWidth(1); //画笔线条宽度
painter.setPen(pen);//设置画笔
int lx = beginPos.x()<endPos.x()?beginPos.x():endPos.x();//矩形截图区域左上角x坐标
int ly = beginPos.y()<endPos.y()?beginPos.y():endPos.y();//矩形截图区域右上角x坐标
int w = beginPos.x()<endPos.x()?endPos.x()-beginPos.x():beginPos.x()-endPos.x();//矩形截图区域宽度
int h = beginPos.y()<endPos.y()?endPos.y()-beginPos.y():beginPos.y()-endPos.y();//矩形截图区域高度
QRect rect = QRect(lx,ly,w,h);//矩形截图区域
if(lx!=-1 && w>0 && h>0)//防止第一次就重绘 并且宽高大于0时才进行截图操作
{
painter.drawPixmap(rect,fullScreen,rect);//重绘截图矩形部分,即恢复原图,达到去除幕布效果
painter.drawRect(lx, ly, w, h);//画截图矩形
//截图区域大小位置提示
if(ly>10)//避免看不到提示,在截图矩形上边不接近屏幕上边时,提示在截图矩形的上边的上面
{
painter.drawText(lx + 2, ly - 8, tr("截图范围(%1,%2) - (%3,%4) 截图大小:(%5 x %6)") .arg(lx).arg(ly).arg(lx + w).arg(ly + h).arg(w).arg(h));
}
else//在截图矩形上边接近屏幕上边时,提示在截图矩形的上边的下面
{
painter.drawText(lx + 2, ly + 12, tr("截图范围(%1,%2) - (%3,%4) 截图大小:(%5 x %6)") .arg(lx).arg(ly).arg(lx + w).arg(ly + h).arg(w).arg(h));
}
}
//实时显示鼠标的位置
painter.drawText(cursor().pos().x(), cursor().pos().y(), tr("(%1,%2)") .arg(cursor().pos().x()).arg(cursor().pos().y()));
}
void Screen::showEvent(QShowEvent *) //--窗体show事件
{
//设置透明度实现模糊背景
setWindowOpacity(0.7);
}
void Screen::saveScreenOther()//截图另存为
{
QString fileName = QFileDialog::getSaveFileName(this, "截图另存为", "test.bmp", "Image (*.jpg *.png *.bmp)");
if (fileName.length() > 0)
{
fullScreen.copy(*rect).save(fileName,"bmp");
this->close();
}
}
void Screen::grapFullScreen()//全屏截图
{
endPos.setX(-1);//此时避免画截图矩形
QString fileName = QFileDialog::getSaveFileName(this, "保存全屏截图", "test.bmp", "Image Files (*.bmp)");
if (fileName.length() > 0)
{
fullScreen.save(fileName, "bmp");
close();
}
this->hide();
}
void Screen::keyPressEvent(QKeyEvent *e) //按键事件--实现快捷键功能
{
/// Esc 键退出截图;
if (e->key() == Qt::Key_Escape)
{
hide();
}///CTRL+C 复制
else if(e->key() == Qt::Key_C && e->modifiers() == Qt::ControlModifier)
{
QGuiApplication::clipboard()->setPixmap(fullScreen.copy(*rect));
}///截图另存为(ALT+C)
else if(e->key() == Qt::Key_C && e->modifiers() == Qt::AltModifier)
{
saveScreenOther();
}///全屏截图(ALT+A)
else if(e->key() == Qt::Key_A && e->modifiers() == Qt::AltModifier)
{
grapFullScreen();
}///百度识别(ALT+B)
else if(e->key() == Qt::Key_B && e->modifiers() == Qt::AltModifier)
{
baiduDiscern();
}
else
{
e->ignore();//忽略
}
}
#ifndef SCREEN_H
#define SCREEN_H
#include <QWidget>
#include <QPoint>
#include <QMouseEvent>
#include <QContextMenuEvent>
#include <QMenu>//右键菜单
#include <QPaintEvent>
#include <QPainter>//画笔
#include <QPixmap>
#include <QDebug>
#include <QDesktopWidget>
#include <QApplication>
#include <QFileDialog>
#include <QShowEvent>
#include <QClipboard>
#include <QKeyEvent>
#include <QRect>
#include <QFile>
class Screen : public QWidget
{
Q_OBJECT
public:
explicit Screen(QWidget *parent = 0);
signals:
void sendNewStr(QString);
public slots:
void saveScreenOther();//截图另存为
void grapFullScreen();//全屏截图
void copyScreen(); //右键复制到粘贴板
void baiduDiscern();
protected:
void contextMenuEvent(QContextMenuEvent *); //--右键菜单事件
void mousePressEvent(QMouseEvent *e); //--鼠标按下事件
void mouseMoveEvent(QMouseEvent *e); //--鼠标移动事件
void mouseReleaseEvent(QMouseEvent *e); //--鼠标释放(松开)事件
void paintEvent(QPaintEvent *); //--画图事件
void showEvent(QShowEvent *); //--窗体show事件
void keyPressEvent(QKeyEvent *e); //--按键事件
private:
QPoint beginPos;//记录鼠标的起始位置
QPoint endPos;//记录鼠标的结束位置
QMenu *menu; //右键菜单对象
bool leftPres;//记录鼠标左键是否按下,按下为true
QRect * rect; //矩形截图区域
public:
QPixmap fullScreen;//全屏截图
public:
QPoint getBeginPos();//获取鼠标的起始位置
QPoint getEndPos();//获取鼠标的结束位置
void setBeginPos(QPoint p);//设置鼠标的起始位置
void setEndPos(QPoint p);//设置鼠标的结束位置
};
#endif // SCREEN_H
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>Screen</class>
<widget class="QWidget" name="Screen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册