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