feat: 按钮状态更新
Description: 按钮状态更新 Log: 按钮状态更新 Change-Id: Ie561e5baed6693d9783b390c95a788fdbf61f05e
This commit is contained in:
parent
be7aac5324
commit
acd6ab1600
|
@ -25,7 +25,8 @@ HEADERS += src/mainwindow.h \
|
|||
src/resulttextview.h \
|
||||
src/textloadwidget.h \
|
||||
src/view/imageview.h \
|
||||
src/tessocrutils/tessocrutils.h
|
||||
src/tessocrutils/tessocrutils.h \
|
||||
src/loadingwidget.h
|
||||
|
||||
SOURCES += src/main.cpp \
|
||||
src/mainwindow.cpp \
|
||||
|
@ -36,7 +37,8 @@ SOURCES += src/main.cpp \
|
|||
src/textloadwidget.cpp \
|
||||
src/resulttextview.cpp \
|
||||
src/view/imageview.cpp \
|
||||
src/tessocrutils/tessocrutils.cpp
|
||||
src/tessocrutils/tessocrutils.cpp \
|
||||
src/loadingwidget.cpp
|
||||
|
||||
LIBS += -llept -ltesseract \
|
||||
|
||||
|
|
13
src/loadingwidget.cpp
Normal file
13
src/loadingwidget.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "loadingwidget.h"
|
||||
|
||||
loadingWidget::loadingWidget(QWidget *parent)
|
||||
: DLabel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void loadingWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
emit sigChangeSize();
|
||||
return DLabel::resizeEvent(event);
|
||||
}
|
18
src/loadingwidget.h
Normal file
18
src/loadingwidget.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef LOADINGWIDGET_H
|
||||
#define LOADINGWIDGET_H
|
||||
|
||||
#include <DLabel>
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class loadingWidget : public DLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
loadingWidget(QWidget *parent = nullptr);
|
||||
signals:
|
||||
void sigChangeSize();
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // LOADINGWIDGET_H
|
|
@ -1,5 +1,6 @@
|
|||
#include "mainwidget.h"
|
||||
#include "view/imageview.h"
|
||||
#include "loadingwidget.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QApplication>
|
||||
|
@ -100,25 +101,33 @@ void MainWidget::setupUi(QWidget *Widget)
|
|||
m_horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
|
||||
|
||||
m_plainTextEdit = new ResultTextView(Widget);
|
||||
m_plainTextEdit->setReadOnly(true);
|
||||
|
||||
m_plainTextEdit->setObjectName(QStringLiteral("plainTextEdit"));
|
||||
connect(m_plainTextEdit, &ResultTextView::sigChangeSize, [ = ] {
|
||||
loadingUi();
|
||||
});
|
||||
|
||||
|
||||
if (!m_imageview) {
|
||||
m_imageview = new ImageView();
|
||||
}
|
||||
|
||||
m_resultWidget = new QStackedWidget(this);
|
||||
m_resultWidget = new DStackedWidget(this);
|
||||
m_resultWidget->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
|
||||
m_loadingOcr = new loadingWidget(this);
|
||||
m_loadingOcr->setAlignment(Qt::AlignCenter);
|
||||
m_resultWidget->addWidget(m_loadingOcr);
|
||||
|
||||
m_resultWidget->addWidget(m_plainTextEdit);
|
||||
|
||||
m_noResult = new DLabel(this);
|
||||
m_noResult->setAlignment(Qt::AlignCenter);
|
||||
m_noResult->setText(tr("No text recognized"));
|
||||
|
||||
m_resultWidget->addWidget(m_noResult);
|
||||
|
||||
connect(m_loadingOcr, &loadingWidget::sigChangeSize, [ = ] {
|
||||
loadingUi();
|
||||
});
|
||||
QSplitter *mainSplitter = new QSplitter(Qt::Horizontal); //新建水平分割器
|
||||
mainSplitter->setHandleWidth(0);//分割线的宽度
|
||||
mainSplitter->setChildrenCollapsible(false);//不允许把分割出的子窗口拖小到0,最小值被限定为sizeHint或maxSize/minSize
|
||||
|
@ -216,6 +225,13 @@ void MainWidget::createLoadingUi()
|
|||
if (m_imageview) {
|
||||
m_imageview->setForegroundBrush(QColor(0, 0, 0, 77)); //设置场景的前景色,类似于遮罩
|
||||
}
|
||||
//识别时
|
||||
if (m_copyBtn) {
|
||||
m_copyBtn->setEnabled(false);
|
||||
}
|
||||
if (m_exportBtn) {
|
||||
m_exportBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::deleteLoadingUi()
|
||||
|
@ -234,8 +250,8 @@ void MainWidget::deleteLoadingUi()
|
|||
|
||||
void MainWidget::loadingUi()
|
||||
{
|
||||
if (m_loadingWidget && m_loadingTip && m_plainTextEdit) {
|
||||
int x = this->width() - m_plainTextEdit->width() / 2;
|
||||
if (m_loadingWidget && m_loadingTip && m_resultWidget) {
|
||||
int x = this->width() - m_resultWidget->width() / 2;
|
||||
int y = this->height() / 2 - 50;
|
||||
m_loadingWidget->move(x, y);
|
||||
m_loadingTip->move(x - 20, y + 24);
|
||||
|
@ -302,6 +318,13 @@ void MainWidget::loadString(const QString &string)
|
|||
if (!string.isEmpty()) {
|
||||
m_resultWidget->setCurrentWidget(m_plainTextEdit);
|
||||
m_plainTextEdit->appendPlainText(string);
|
||||
//新增识别完成按钮恢复
|
||||
if (m_copyBtn) {
|
||||
m_copyBtn->setEnabled(true);
|
||||
}
|
||||
if (m_exportBtn) {
|
||||
m_exportBtn->setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
resultEmpty();
|
||||
}
|
||||
|
@ -310,6 +333,13 @@ void MainWidget::loadString(const QString &string)
|
|||
void MainWidget::resultEmpty()
|
||||
{
|
||||
m_resultWidget->setCurrentWidget(m_noResult);
|
||||
//新增如果未识别到,按钮置灰
|
||||
if (m_copyBtn) {
|
||||
m_copyBtn->setEnabled(false);
|
||||
}
|
||||
if (m_exportBtn) {
|
||||
m_exportBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::resizeEvent(QResizeEvent *event)
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
#include <DPlainTextEdit>
|
||||
#include <DLabel>
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DStackedWidget>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QStackedWidget>
|
||||
|
||||
#include <DToolButton>
|
||||
|
||||
#include "resulttextview.h"
|
||||
|
@ -19,7 +20,7 @@ class QThread;
|
|||
class QGridLayout;
|
||||
class QHBoxLayout;
|
||||
class ImageView;
|
||||
|
||||
class loadingWidget;
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
|
@ -80,8 +81,9 @@ private:
|
|||
RecognitionResult m_result;
|
||||
QImage *m_currentImg{nullptr};
|
||||
|
||||
QStackedWidget *m_resultWidget{nullptr};
|
||||
DStackedWidget *m_resultWidget{nullptr};
|
||||
DLabel *m_noResult{nullptr};
|
||||
loadingWidget *m_loadingOcr{nullptr};
|
||||
signals:
|
||||
void sigResult(const QString &);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user