feat: fit by width
Signed-off-by: Gary Wang <wzc782970009@gmail.com>
This commit is contained in:
parent
69802a433e
commit
038d04b3da
|
@ -24,6 +24,7 @@ void ActionManager::setupAction(MainWindow *mainWindow)
|
|||
CREATE_NEW_ACTION(mainWindow, actionZoomIn);
|
||||
CREATE_NEW_ACTION(mainWindow, actionZoomOut);
|
||||
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
|
||||
CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
|
||||
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap);
|
||||
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
|
||||
CREATE_NEW_ACTION(mainWindow, actionPaste);
|
||||
|
@ -47,6 +48,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
|
|||
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
|
||||
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
|
||||
actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr));
|
||||
actionFitByWidth->setText("Fit by width"); // TODO: what should it called?
|
||||
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));
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
QAction *actionZoomIn;
|
||||
QAction *actionZoomOut;
|
||||
QAction *actionHorizontalFlip;
|
||||
QAction *actionFitByWidth;
|
||||
QAction *actionCopyPixmap;
|
||||
QAction *actionCopyFilePath;
|
||||
QAction *actionPaste;
|
||||
|
|
|
@ -171,6 +171,31 @@ void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadio
|
|||
applyTransformationModeByScaleFactor();
|
||||
}
|
||||
|
||||
void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly)
|
||||
{
|
||||
resetScale();
|
||||
|
||||
QRectF viewRect = this->viewport()->rect().adjusted(2, 2, -2, -2);
|
||||
QRectF imageRect = transform().mapRect(sceneRect());
|
||||
|
||||
qreal ratio;
|
||||
|
||||
if (ori == Qt::Horizontal) {
|
||||
ratio = viewRect.width() / imageRect.width();
|
||||
} else {
|
||||
ratio = viewRect.height() / imageRect.height();
|
||||
}
|
||||
|
||||
if (scaleDownOnly && ratio > 1) ratio = 1;
|
||||
|
||||
scale(ratio, ratio);
|
||||
centerOn(imageRect.top(), 0);
|
||||
m_enableFitInView = false;
|
||||
|
||||
applyTransformationModeByScaleFactor();
|
||||
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
|
||||
}
|
||||
|
||||
void GraphicsView::checkAndDoFitInView(bool markItOnAnyway)
|
||||
{
|
||||
if (!isThingSmallerThanWindowWith(transform())) {
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
void flipView(bool horizontal = true);
|
||||
void resetScale();
|
||||
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
||||
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
|
||||
|
||||
void checkAndDoFitInView(bool markItOnAnyway = true);
|
||||
|
||||
|
|
|
@ -421,6 +421,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
|||
menu->addSeparator();
|
||||
|
||||
menu->addAction(m_am->actionHorizontalFlip);
|
||||
menu->addAction(m_am->actionFitByWidth);
|
||||
|
||||
menu->addSeparator();
|
||||
menu->addAction(stayOnTopMode);
|
||||
|
@ -561,6 +562,11 @@ void MainWindow::on_actionHorizontalFlip_triggered()
|
|||
m_graphicsView->flipView();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionFitByWidth_triggered()
|
||||
{
|
||||
m_graphicsView->fitByOrientation();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCopyPixmap_triggered()
|
||||
{
|
||||
QClipboard *cb = QApplication::clipboard();
|
||||
|
|
|
@ -66,6 +66,7 @@ private slots:
|
|||
void on_actionZoomIn_triggered();
|
||||
void on_actionZoomOut_triggered();
|
||||
void on_actionHorizontalFlip_triggered();
|
||||
void on_actionFitByWidth_triggered();
|
||||
void on_actionCopyPixmap_triggered();
|
||||
void on_actionCopyFilePath_triggered();
|
||||
void on_actionPaste_triggered();
|
||||
|
|
Loading…
Reference in New Issue
Block a user