feat: 改造了复制按钮,按照需求,新增默认文件名称

Description: 改造了复制按钮,按照需求,新增默认文件名称

Log: 改造了复制按钮,按照需求,新增默认文件名称
Change-Id: Ia6a84937bc49c4399fb3ab915a978d89504a8ce3
This commit is contained in:
liuminghang 2021-06-22 11:47:36 +08:00
parent acd6ab1600
commit 40c90fc3c7
2 changed files with 27 additions and 32 deletions

View File

@ -13,6 +13,7 @@
#include <QThread>
#include <QMutexLocker>
#include <QSplitter>
#include <QTimer>
#include <DGuiApplicationHelper>
#include <DMainWindow>
@ -112,6 +113,7 @@ void MainWidget::setupUi(QWidget *Widget)
m_resultWidget = new DStackedWidget(this);
m_resultWidget->setFocusPolicy(Qt::NoFocus);
m_resultWidget->setMinimumWidth(220);
m_loadingOcr = new loadingWidget(this);
@ -261,20 +263,14 @@ void MainWidget::loadingUi()
m_pwidget->move(0, 0);
}
}
#include <QTimer>
void MainWidget::openImage(const QString &path)
{
if (m_imageview) {
QImage img(path);
m_imageview->openFilterImage(img);
QTimer::singleShot(100, [ = ] {
m_imageview->fitWindow();
});
m_imgName = path;
openImage(img);
}
}
void MainWidget::openImage(const QImage &img)
@ -350,12 +346,18 @@ void MainWidget::resizeEvent(QResizeEvent *event)
void MainWidget::slotCopy()
{
//复制所有内容
QTextDocument *document = m_plainTextEdit->document();
DPlainTextEdit *tempTextEdit = new DPlainTextEdit(this);
tempTextEdit->setDocument(document);
tempTextEdit->selectAll();
tempTextEdit->copy();
//选中内容则复制,未选中内容则不复制
if (!m_plainTextEdit->textCursor().selectedText().isEmpty()) {
m_plainTextEdit->copy();
} else {
QTextDocument *document = m_plainTextEdit->document();
DPlainTextEdit *tempTextEdit = new DPlainTextEdit(this);
tempTextEdit->setDocument(document);
tempTextEdit->selectAll();
tempTextEdit->copy();
tempTextEdit->deleteLater();
tempTextEdit = nullptr;
}
QIcon icon(":/assets/icon_toast_sucess_new.svg");
DFloatingMessage *pDFloatingMessage = new DFloatingMessage(DFloatingMessage::MessageType::TransientType, m_pwidget);
@ -364,8 +366,7 @@ void MainWidget::slotCopy()
pDFloatingMessage->setIcon(icon);
pDFloatingMessage->raise();
DMessageManager::instance()->sendMessage(m_pwidget, pDFloatingMessage);
tempTextEdit->deleteLater();
tempTextEdit = nullptr;
}
void MainWidget::slotExport()
@ -381,7 +382,13 @@ void MainWidget::slotExport()
}
}
QString fileName = QFileInfo(m_imgName).completeBaseName();
QString fileName;
if (!m_imgName.isEmpty()) {
fileName = QFileInfo(m_imgName).completeBaseName();
} else {
fileName = tr("Results");
}
QString file_path = QFileDialog::getSaveFileName(this, "save as", download + "/" + fileName, "*.txt");
qDebug() << file_path;

View File

@ -73,19 +73,12 @@ void ImageView::openFilterImage(QImage img)
}
qreal ImageView::windowRelativeScale() const
{
//替换撑满方案
QRectF bf = sceneRect();
if (this->window()->isFullScreen()) {
if (1.0 * (width()) / (height() + 15) > 1.0 * bf.width() / bf.height()) {
return 1.0 * (height() + 15) / bf.height();
} else {
return 1.0 * (width()) / bf.width();
}
if (1.0 * width() / height() > 1.0 * bf.width() / bf.height()) {
return 1.0 * height() / bf.height();
} else {
if (1.0 * (width() - 20) / (height() - 180) > 1.0 * bf.width() / bf.height()) {
return 1.0 * (height() - 180) / bf.height();
} else {
return 1.0 * (width() - 20) / bf.width();
}
return 1.0 * width() / bf.width();
}
}
void ImageView::fitWindow()
@ -95,11 +88,6 @@ void ImageView::fitWindow()
resetTransform();
scale(wrs, wrs);
// if (wrs - 1 > -0.01 && wrs - 1 < 0.01) {
// emit checkAdaptImageBtn();
// } else {
// emit disCheckAdaptImageBtn();
// }
m_isFitImage = false;
m_isFitWindow = true;