diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index afbf6ab..b903a1f 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #define App (static_cast(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 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); diff --git a/src/mainwidget.h b/src/mainwidget.h index 0ea2fef..ac4d3de 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -49,6 +49,8 @@ public: void loadString(const QString &string); void resultEmpty(); + //缩放显示label + void initScaleLabel(); protected: void resizeEvent(QResizeEvent *event); private slots: diff --git a/src/view/imageview.cpp b/src/view/imageview.cpp index b062d55..4f03cc3 100644 --- a/src/view/imageview.cpp +++ b/src/view/imageview.cpp @@ -303,7 +303,8 @@ void ImageView::setScaleValue(qreal v) // } else { // emit disCheckAdaptImageBtn(); // } - + emit scaled(m_scal * 100); + emit showScaleLabel(); } diff --git a/src/view/imageview.h b/src/view/imageview.h index 252e01c..0dad3e7 100644 --- a/src/view/imageview.h +++ b/src/view/imageview.h @@ -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