fix: 解决bug85097

Description: 增加了一个缩放比例的小label

Log: 与界面有关
Bug: https://pms.uniontech.com/zentao/bug-view-85097.html
Change-Id: Ib5b003b4599044e7780adc78b6894b57c1a75264
This commit is contained in:
liuminghang 2021-06-24 14:51:15 +08:00
parent 6292e44721
commit a72a11c17b
4 changed files with 47 additions and 3 deletions

View File

@ -21,6 +21,9 @@
#include <DTitlebar>
#include <DMessageManager>
#include <DToolButton>
#include <DFloatingWidget>
#include <DAnchors>
#include <DFontSizeManager>
#define App (static_cast<QApplication*>(QCoreApplication::instance()))
MainWidget::MainWidget(QWidget *parent) :
@ -29,7 +32,7 @@ MainWidget::MainWidget(QWidget *parent) :
setupUi(this);
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
setIcons(themeType);
initScaleLabel();
setupConnect();
}
@ -359,6 +362,42 @@ void MainWidget::resultEmpty()
}
}
void MainWidget::initScaleLabel()
{
DAnchors<DFloatingWidget> scalePerc = new DFloatingWidget(this);
scalePerc->setBlurBackgroundEnabled(true);
QHBoxLayout *layout = new QHBoxLayout();
scalePerc->setLayout(layout);
DLabel *label = new DLabel();
layout->addWidget(label);
scalePerc->setAttribute(Qt::WA_TransparentForMouseEvents);
scalePerc.setAnchor(Qt::AnchorHorizontalCenter, this, Qt::AnchorHorizontalCenter);
scalePerc.setAnchor(Qt::AnchorBottom, this, Qt::AnchorBottom);
scalePerc.setBottomMargin(75 + 14);
label->setAlignment(Qt::AlignCenter);
// scalePerc->setFixedSize(82, 48);
scalePerc->setFixedWidth(90 + 10);
scalePerc->setFixedHeight(40 + 10);
scalePerc->adjustSize();
label->setText("100%");
DFontSizeManager::instance()->bind(label, DFontSizeManager::T6);
scalePerc->hide();
QTimer *hideT = new QTimer(this);
hideT->setSingleShot(true);
connect(hideT, &QTimer::timeout, scalePerc, &DLabel::hide);
connect(m_imageview, &ImageView::scaled, this, [ = ](qreal perc) {
label->setText(QString("%1%").arg(int(perc)));
});
connect(m_imageview, &ImageView::showScaleLabel, this, [ = ]() {
scalePerc->show();
scalePerc->move(m_imageview->width() / 2 - 50, m_imageview->height() - 48);
hideT->start(1000);
});
}
void MainWidget::resizeEvent(QResizeEvent *event)
{
return DWidget::resizeEvent(event);

View File

@ -49,6 +49,8 @@ public:
void loadString(const QString &string);
void resultEmpty();
//缩放显示label
void initScaleLabel();
protected:
void resizeEvent(QResizeEvent *event);
private slots:

View File

@ -303,7 +303,8 @@ void ImageView::setScaleValue(qreal v)
// } else {
// emit disCheckAdaptImageBtn();
// }
emit scaled(m_scal * 100);
emit showScaleLabel();
}

View File

@ -55,7 +55,9 @@ protected:
//二指捏合功能的触屏事件
void handleGestureEvent(QGestureEvent *gesture);
void pinchTriggered(QPinchGesture *gesture);
signals:
void scaled(qreal perc);
void showScaleLabel();
private:
QString m_currentPath;//当前图片路径
QGraphicsPixmapItem *m_pixmapItem{nullptr};//当前图像的item