feat: Dbus接口增加传递Image的名称

Description:   增加Dbus接口,可以传递打开Image的名称

Log: no
Change-Id: I964a0f28504f953322fd103ba5075e1ed582a2b0
This commit is contained in:
wangcong 2021-06-23 11:39:32 +08:00
parent 0cfed22ed4
commit 18660ef51a
10 changed files with 57 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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};
};

View File

@ -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();
}

View File

@ -37,6 +37,8 @@ public:
Q_INVOKABLE void openImage(QImage image);
Q_INVOKABLE void openImageAndName( QImage image, QString imageName);
signals:

View File

@ -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));
}

View File

@ -46,6 +46,11 @@ class DbusOcrAdaptor: public QDBusAbstractAdaptor
" <arg direction=\"in\" type=\"ay\" name=\"openImage\"/>\n"
" </method>\n"
" <method name=\"openImageAndName\">\n"
" <arg direction=\"in\" type=\"ay\" name=\"images\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"imageName\"/>\n"
" </method>\n"
" <method name=\"openFile\">\n"
" <arg direction=\"in\" type=\"s\" name=\"openFile\"/>\n"
" <arg direction=\"out\" type=\"b\"/>\n"
@ -58,6 +63,7 @@ public:
public Q_SLOTS: // METHODS
void openImage(QByteArray images);
void openImageAndName(QByteArray images,QString imageName);
bool openFile(QString filePath);

View File

@ -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
};