From 18660ef51a5b5c5219052bf7c0ca7d0c5a9964f3 Mon Sep 17 00:00:00 2001 From: wangcong Date: Wed, 23 Jun 2021 11:39:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20Dbus=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BC=A0=E9=80=92Image=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 增加Dbus接口,可以传递打开Image的名称 Log: no Change-Id: I964a0f28504f953322fd103ba5075e1ed582a2b0 --- src/main.cpp | 1 + src/mainwidget.cpp | 4 ++-- src/mainwidget.h | 4 ++-- src/mainwindow.cpp | 4 ++-- src/mainwindow.h | 2 +- src/ocrapplication.cpp | 10 ++++++++++ src/ocrapplication.h | 2 ++ src/service/dbusocr_adaptor.cpp | 12 ++++++++++++ src/service/dbusocr_adaptor.h | 6 ++++++ src/service/ocrinterface.h | 19 +++++++++++++++++++ 10 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 11c93dd..89415e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) qDebug() << __FUNCTION__ << __LINE__; pOcr->openFile(QString(argv[1])); //pOcr->openImage(QImage(QSize(500, 145), QImage::Format_RGB32)); + //pOcr->openImageAndName(QImage(QSize(500, 145), QImage::Format_RGB32),"test"); return 0; } diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index d25b2d3..c51cfbb 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -273,7 +273,7 @@ void MainWidget::openImage(const QString &path) } } -void MainWidget::openImage(const QImage &img) +void MainWidget::openImage(const QImage &img,const QString & name) { createLoadingUi(); if (m_imageview) { @@ -281,7 +281,7 @@ void MainWidget::openImage(const QImage &img) QTimer::singleShot(100, [ = ] { m_imageview->fitWindow(); }); - m_imgName = ""; + m_imgName = name; } if (m_currentImg) { delete m_currentImg; diff --git a/src/mainwidget.h b/src/mainwidget.h index 7006fb5..bb1f146 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -41,8 +41,8 @@ public: void loadingUi(); - void openImage(const QString &path); - void openImage(const QImage &img); + void openImage(const QString &path ); + void openImage(const QImage &img,const QString & name=""); void loadHtml(const QString &html); void loadString(const QString &string); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 440a1b6..efd99d9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -54,8 +54,8 @@ bool MainWindow::openFile(const QString &filePaths) return true; } -bool MainWindow::openImage(const QImage &image) +bool MainWindow::openImage(const QImage &image, const QString &name) { - m_mainWidget->openImage(image); + m_mainWidget->openImage(image,name); return true; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 446db05..fdc2697 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -38,7 +38,7 @@ public: bool openFile(const QString &filePaths); - bool openImage(const QImage &image); + bool openImage(const QImage &image,const QString & name=""); private: MainWidget *m_mainWidget{nullptr}; }; diff --git a/src/ocrapplication.cpp b/src/ocrapplication.cpp index eb079c1..0fb2d57 100644 --- a/src/ocrapplication.cpp +++ b/src/ocrapplication.cpp @@ -46,3 +46,13 @@ void OcrApplication::openImage(QImage image) win->resize(800, 600); win->show(); } + +void OcrApplication::openImageAndName(QImage image, QString imageName) +{ + qDebug() << __FUNCTION__ << __LINE__ << image.size(); + MainWindow *win = new MainWindow(); + win->openImage(image,imageName); + win->resize(800, 600); + win->show(); +} + diff --git a/src/ocrapplication.h b/src/ocrapplication.h index 9aa6471..72e435d 100644 --- a/src/ocrapplication.h +++ b/src/ocrapplication.h @@ -37,6 +37,8 @@ public: Q_INVOKABLE void openImage(QImage image); + Q_INVOKABLE void openImageAndName( QImage image, QString imageName); + signals: diff --git a/src/service/dbusocr_adaptor.cpp b/src/service/dbusocr_adaptor.cpp index daee46a..85caa59 100644 --- a/src/service/dbusocr_adaptor.cpp +++ b/src/service/dbusocr_adaptor.cpp @@ -51,6 +51,17 @@ bool DbusOcrAdaptor::openFile(QString filePath) return true; } +void DbusOcrAdaptor::openImageAndName(QByteArray images,QString imageName) +{ + qDebug() << __FUNCTION__ << __LINE__; + QByteArray data = images; + QString tmp_data = QString::fromLatin1(data.data(), data.size()); + QByteArray srcData = QByteArray::fromBase64(tmp_data.toLatin1()); + data = qUncompress(srcData); + QImage image; + image.loadFromData(data); + QMetaObject::invokeMethod(parent(), "openImageAndName", Q_ARG(QImage, image), Q_ARG(QString, imageName)); +} void DbusOcrAdaptor::openImage(QByteArray images) { qDebug() << __FUNCTION__ << __LINE__; @@ -62,3 +73,4 @@ void DbusOcrAdaptor::openImage(QByteArray images) image.loadFromData(data); QMetaObject::invokeMethod(parent(), "openImage", Q_ARG(QImage, image)); } + diff --git a/src/service/dbusocr_adaptor.h b/src/service/dbusocr_adaptor.h index 409aecd..aa9a051 100644 --- a/src/service/dbusocr_adaptor.h +++ b/src/service/dbusocr_adaptor.h @@ -46,6 +46,11 @@ class DbusOcrAdaptor: public QDBusAbstractAdaptor " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" @@ -58,6 +63,7 @@ public: public Q_SLOTS: // METHODS void openImage(QByteArray images); + void openImageAndName(QByteArray images,QString imageName); bool openFile(QString filePath); diff --git a/src/service/ocrinterface.h b/src/service/ocrinterface.h index d6fbdf8..14a0859 100644 --- a/src/service/ocrinterface.h +++ b/src/service/ocrinterface.h @@ -81,6 +81,25 @@ public Q_SLOTS: // METHODS return call(QStringLiteral("openImage"), QVariant::fromValue(data)); } + /* + * @bref:openImages + * @param: image 图片 + * @param: imageName 图片名称 + * @return: QDBusPendingReply + * @note: + */ + inline QDBusPendingReply<> openImageAndName(const QImage &image,const QString &imageName) + { + qDebug() << __FUNCTION__; + QByteArray data; + QBuffer buf(&data); + if (image.save(&buf, "PNG")) { + data = qCompress(data, 9); + data = data.toBase64(); + } + return call(QStringLiteral("openImage"), QVariant::fromValue(data),imageName); + } + Q_SIGNALS: // SIGNALS };