支持打开功能,增加发送截图
This commit is contained in:
parent
ed78634032
commit
a2309b6572
|
@ -123,7 +123,10 @@ void MainWindow::readyRead()
|
|||
type = JO.value("type").toString();
|
||||
if (type == "text") {
|
||||
QString message = JO.value("message").toString();
|
||||
if (message == "Capture") {
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "] " + message);
|
||||
} else if (type == "command") {
|
||||
QString command = JO.value("message").toString();
|
||||
if (command == "capture") {
|
||||
QScreen *screen = QApplication::primaryScreen();
|
||||
QPixmap pixmap = screen->grabWindow(QApplication::desktop()->winId());
|
||||
QDateTime time = QDateTime::currentDateTime();
|
||||
|
@ -131,7 +134,11 @@ void MainWindow::readyRead()
|
|||
QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + filename;
|
||||
pixmap.save(path, nullptr, 100);
|
||||
}
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "]:" + message);
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "] " + command);
|
||||
} else if (type == "play") {
|
||||
QString surl = JO.value("message").toString();
|
||||
QDesktopServices::openUrl(QUrl(surl));
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "] open " + surl);
|
||||
} else if (type == "file") {
|
||||
fileName = JO.value("fileName").toString();
|
||||
lastModified = JO.value("lastModified").toDouble()/1000;
|
||||
|
@ -193,6 +200,28 @@ void MainWindow::on_pushButton_send_pressed()
|
|||
});
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_capture_pressed()
|
||||
{
|
||||
qint64 port = ui->lineEdit_port->text().toInt();
|
||||
QTcpSocket *tcpSocket1 = new QTcpSocket(this);
|
||||
connect(tcpSocket1, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), [=](QAbstractSocket::SocketError socketError){
|
||||
qDebug() << socketError;
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<QAbstractSocket::SocketError>();
|
||||
QString errorString = metaEnum.valueToKey(socketError);
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] " + errorString);
|
||||
});
|
||||
tcpSocket1->connectToHost(QHostAddress(ui->lineEdit_ip->text()), port);
|
||||
connect(tcpSocket1, &QTcpSocket::connected, [=](){
|
||||
QJsonObject JO;
|
||||
JO.insert("type", "command");
|
||||
JO.insert("message", "capture");
|
||||
QString s = QJsonDocument(JO).toJson(QJsonDocument::Compact);
|
||||
tcpSocket1->write(s.toUtf8());
|
||||
tcpSocket1->close();
|
||||
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] command capture");
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::upload(QString filepath)
|
||||
{
|
||||
if (ui->lineEdit_ip->text() == IP) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QScreen>
|
||||
#include <QDesktopWidget>
|
||||
#include <QStandardPaths>
|
||||
#include <QDesktopServices>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -54,6 +55,7 @@ private slots:
|
|||
void newConnect();
|
||||
void readyRead();
|
||||
void on_pushButton_send_pressed();
|
||||
void on_pushButton_capture_pressed();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -158,6 +158,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_capture">
|
||||
<property name="text">
|
||||
<string>截图</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_clear">
|
||||
<property name="text">
|
||||
|
|
Loading…
Reference in New Issue