| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "viewpanel.h" |
| 22 |
#include "navigationwidget.h" |
| 23 |
#include "scen/imageview.h" |
| 24 |
#include "dimagebutton.h" |
| 25 |
|
| 26 |
#include "utils/baseutils.h" |
| 27 |
|
| 28 |
#include <QTimer> |
| 29 |
#include <DBlurEffectWidget> |
| 30 |
#include <DFontSizeManager> |
| 31 |
#include <DFloatingWidget> |
| 32 |
|
| 33 |
DWIDGET_USE_NAMESPACE |
| 34 |
|
| 35 |
void ViewPanel::initFloatingComponent() |
| 36 |
{ |
| 37 |
// initSwitchButtons(); |
| 38 |
initScaleLabel(); |
| 39 |
#ifndef tablet_PC |
| 40 |
initNavigation(); |
| 41 |
#endif |
| 42 |
} |
| 43 |
|
| 44 |
void ViewPanel::initScaleLabel() |
| 45 |
{ |
| 46 |
using namespace utils::base; |
| 47 |
DAnchors<DFloatingWidget> scalePerc = new DFloatingWidget(this); |
| 48 |
scalePerc->setBlurBackgroundEnabled(true); |
| 49 |
|
| 50 |
QHBoxLayout *layout = new QHBoxLayout(); |
| 51 |
scalePerc->setLayout(layout); |
| 52 |
QLabel *label = new QLabel(); |
| 53 |
layout->addWidget(label); |
| 54 |
scalePerc->setAttribute(Qt::WA_TransparentForMouseEvents); |
| 55 |
scalePerc.setAnchor(Qt::AnchorHorizontalCenter, this, Qt::AnchorHorizontalCenter); |
| 56 |
scalePerc.setAnchor(Qt::AnchorBottom, this, Qt::AnchorBottom); |
| 57 |
scalePerc.setBottomMargin(75 + 14); |
| 58 |
label->setAlignment(Qt::AlignCenter); |
| 59 |
// scalePerc->setFixedSize(82, 48); |
| 60 |
scalePerc->setFixedWidth(90 + 10); |
| 61 |
scalePerc->setFixedHeight(40 + 10); |
| 62 |
scalePerc->adjustSize(); |
| 63 |
label->setText("100%"); |
| 64 |
DFontSizeManager::instance()->bind(label, DFontSizeManager::T6); |
| 65 |
scalePerc->hide(); |
| 66 |
|
| 67 |
QTimer *hideT = new QTimer(this); |
| 68 |
hideT->setSingleShot(true); |
| 69 |
connect(hideT, &QTimer::timeout, scalePerc, &QLabel::hide); |
| 70 |
|
| 71 |
connect(m_viewB, &ImageView::scaled, this, [ = ](qreal perc) { |
| 72 |
int p = static_cast<int>(perc); |
| 73 |
label->setText(QString("%1%").arg(QString::number(p))); |
| 74 |
if (perc > 100) { |
| 75 |
emit dApp->signalM->enterScaledMode(true); |
| 76 |
} else { |
| 77 |
emit dApp->signalM->enterScaledMode(false); |
| 78 |
} |
| 79 |
}); |
| 80 |
connect(m_viewB, &ImageView::showScaleLabel, this, [ = ]() { |
| 81 |
scalePerc->show(); |
| 82 |
hideT->start(1000); |
| 83 |
}); |
| 84 |
} |
| 85 |
|
| 86 |
void ViewPanel::initNavigation() |
| 87 |
{ |
| 88 |
m_nav = new NavigationWidget(this); |
| 89 |
m_nav.setBottomMargin(100); |
| 90 |
m_nav.setLeftMargin(10); |
| 91 |
m_nav.setAnchor(Qt::AnchorLeft, this, Qt::AnchorLeft); |
| 92 |
m_nav.setAnchor(Qt::AnchorBottom, this, Qt::AnchorBottom); |
| 93 |
|
| 94 |
connect(this, &ViewPanel::imageChanged, this, [ = ](const QString & path) { |
| 95 |
if (path.isEmpty()) m_nav->setVisible(false); |
| 96 |
m_nav->setImage(m_viewB->image()); |
| 97 |
}); |
| 98 |
connect(m_nav, &NavigationWidget::requestMove, [this](int x, int y) { |
| 99 |
m_viewB->centerOn(x, y); |
| 100 |
}); |
| 101 |
connect(m_viewB, &ImageView::transformChanged, [this]() { |
| 102 |
m_nav->setVisible(! m_nav->isAlwaysHidden() && ! m_viewB->isWholeImageVisible()); |
| 103 |
m_nav->setRectInImage(m_viewB->visibleImageRect()); |
| 104 |
}); |
| 105 |
connect(m_viewB, &ImageView::hideNavigation, this, [ = ]() { |
| 106 |
m_nav->setVisible(false); |
| 107 |
}); |
| 108 |
|
| 109 |
} |