chore: add max zoom-in scale limit (1000x)
This commit is contained in:
parent
2b4bbc91a7
commit
858c9e0ccf
|
@ -21,6 +21,8 @@ ActionManager::~ActionManager()
|
|||
|
||||
void ActionManager::setupAction(MainWindow *mainWindow)
|
||||
{
|
||||
CREATE_NEW_ACTION(mainWindow, actionZoomIn);
|
||||
CREATE_NEW_ACTION(mainWindow, actionZoomOut);
|
||||
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap);
|
||||
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
|
||||
CREATE_NEW_ACTION(mainWindow, actionPaste);
|
||||
|
@ -40,6 +42,8 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
|
|||
{
|
||||
Q_UNUSED(mainWindow);
|
||||
|
||||
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
|
||||
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
|
||||
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
|
||||
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
|
||||
actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr));
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
void setupShortcuts();
|
||||
|
||||
public:
|
||||
QAction *actionZoomIn;
|
||||
QAction *actionZoomOut;
|
||||
QAction *actionCopyPixmap;
|
||||
QAction *actionCopyFilePath;
|
||||
QAction *actionPaste;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QScrollBar>
|
||||
#include <QMimeData>
|
||||
#include <QImageReader>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
GraphicsView::GraphicsView(QWidget *parent)
|
||||
: QGraphicsView (parent)
|
||||
|
@ -109,12 +110,7 @@ void GraphicsView::setScene(GraphicsScene *scene)
|
|||
|
||||
qreal GraphicsView::scaleFactor() const
|
||||
{
|
||||
int angle = static_cast<int>(m_rotateAngle);
|
||||
if (angle == 0 || angle == 180) {
|
||||
return qAbs(transform().m11());
|
||||
} else {
|
||||
return qAbs(transform().m12());
|
||||
}
|
||||
return QStyleOptionGraphicsItem::levelOfDetailFromTransform(transform());
|
||||
}
|
||||
|
||||
void GraphicsView::resetTransform()
|
||||
|
@ -209,10 +205,13 @@ void GraphicsView::resizeEvent(QResizeEvent *event)
|
|||
if (m_enableFitInView) {
|
||||
QTransform tf;
|
||||
tf.rotate(m_rotateAngle);
|
||||
if (isThingSmallerThanWindowWith(tf) && scaleFactor() >= 1) {
|
||||
bool originalSizeSmallerThanWindow = isThingSmallerThanWindowWith(tf);
|
||||
if (originalSizeSmallerThanWindow && scaleFactor() >= 1) {
|
||||
// no longer need to do fitInView()
|
||||
// but we leave the m_enableFitInView value unchanged in case
|
||||
// user resize down the window again.
|
||||
} else if (originalSizeSmallerThanWindow && scaleFactor() < 1) {
|
||||
resetScale();
|
||||
} else {
|
||||
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <QScreen>
|
||||
#include <QMenu>
|
||||
#include <QShortcut>
|
||||
#include <QCollator>
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QWindow>
|
||||
|
@ -112,9 +111,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleWindowMaximum,
|
||||
this, &MainWindow::toggleMaximize);
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked,
|
||||
this, [ = ](){ m_graphicsView->zoomView(1.25); });
|
||||
this, &MainWindow::on_actionZoomIn_triggered);
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked,
|
||||
this, [ = ](){ m_graphicsView->zoomView(0.8); });
|
||||
this, &MainWindow::on_actionZoomOut_triggered);
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleCheckerboardBtnClicked,
|
||||
this, [ = ](){ m_graphicsView->toggleCheckerboard(); });
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked,
|
||||
|
@ -354,7 +353,11 @@ void MainWindow::wheelEvent(QWheelEvent *event)
|
|||
|
||||
if (needWeelEvent) {
|
||||
if (actionIsZoom) {
|
||||
m_graphicsView->zoomView(wheelUp ? 1.25 : 0.8);
|
||||
if (wheelUp) {
|
||||
on_actionZoomIn_triggered();
|
||||
} else {
|
||||
on_actionZoomOut_triggered();
|
||||
}
|
||||
} else {
|
||||
if (wheelUp) {
|
||||
galleryPrev();
|
||||
|
@ -532,6 +535,18 @@ QSize MainWindow::sizeHint() const
|
|||
return QSize(710, 530);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionZoomIn_triggered()
|
||||
{
|
||||
if (m_graphicsView->scaleFactor() < 1000) {
|
||||
m_graphicsView->zoomView(1.25);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionZoomOut_triggered()
|
||||
{
|
||||
m_graphicsView->zoomView(0.8);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCopyPixmap_triggered()
|
||||
{
|
||||
QClipboard *cb = QApplication::clipboard();
|
||||
|
|
|
@ -62,6 +62,8 @@ protected:
|
|||
QSize sizeHint() const override;
|
||||
|
||||
private slots:
|
||||
void on_actionZoomIn_triggered();
|
||||
void on_actionZoomOut_triggered();
|
||||
void on_actionCopyPixmap_triggered();
|
||||
void on_actionCopyFilePath_triggered();
|
||||
void on_actionPaste_triggered();
|
||||
|
|
Loading…
Reference in New Issue
Block a user