chore: tweak fit-in-view menu action behavior
This commit is contained in:
parent
635199b85b
commit
4c07a89ca3
@ -75,35 +75,35 @@ void GraphicsView::showImage(const QPixmap &pixmap)
|
|||||||
{
|
{
|
||||||
resetTransform();
|
resetTransform();
|
||||||
scene()->showImage(pixmap);
|
scene()->showImage(pixmap);
|
||||||
checkAndDoFitInView();
|
displayScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::showImage(const QImage &image)
|
void GraphicsView::showImage(const QImage &image)
|
||||||
{
|
{
|
||||||
resetTransform();
|
resetTransform();
|
||||||
scene()->showImage(QPixmap::fromImage(image));
|
scene()->showImage(QPixmap::fromImage(image));
|
||||||
checkAndDoFitInView();
|
displayScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::showText(const QString &text)
|
void GraphicsView::showText(const QString &text)
|
||||||
{
|
{
|
||||||
resetTransform();
|
resetTransform();
|
||||||
scene()->showText(text);
|
scene()->showText(text);
|
||||||
checkAndDoFitInView();
|
displayScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::showSvg(const QString &filepath)
|
void GraphicsView::showSvg(const QString &filepath)
|
||||||
{
|
{
|
||||||
resetTransform();
|
resetTransform();
|
||||||
scene()->showSvg(filepath);
|
scene()->showSvg(filepath);
|
||||||
checkAndDoFitInView();
|
displayScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::showAnimated(const QString &filepath)
|
void GraphicsView::showAnimated(const QString &filepath)
|
||||||
{
|
{
|
||||||
resetTransform();
|
resetTransform();
|
||||||
scene()->showAnimated(filepath);
|
scene()->showAnimated(filepath);
|
||||||
checkAndDoFitInView();
|
displayScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsScene *GraphicsView::scene() const
|
GraphicsScene *GraphicsView::scene() const
|
||||||
@ -196,15 +196,21 @@ void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly)
|
|||||||
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
|
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::checkAndDoFitInView(bool markItOnAnyway)
|
void GraphicsView::displayScene()
|
||||||
{
|
{
|
||||||
if (!isThingSmallerThanWindowWith(transform())) {
|
if (isSceneBiggerThanView()) {
|
||||||
m_enableFitInView = true;
|
|
||||||
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markItOnAnyway) {
|
m_enableFitInView = true;
|
||||||
m_enableFitInView = true;
|
}
|
||||||
|
|
||||||
|
bool GraphicsView::isSceneBiggerThanView() const
|
||||||
|
{
|
||||||
|
if (!isThingSmallerThanWindowWith(transform())) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ public:
|
|||||||
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
||||||
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
|
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
|
||||||
|
|
||||||
void checkAndDoFitInView(bool markItOnAnyway = true);
|
void displayScene();
|
||||||
|
bool isSceneBiggerThanView() const;
|
||||||
void setEnableAutoFitInView(bool enable = true);
|
void setEnableAutoFitInView(bool enable = true);
|
||||||
|
|
||||||
static QTransform resetScale(const QTransform & orig);
|
static QTransform resetScale(const QTransform & orig);
|
||||||
@ -61,6 +62,9 @@ private:
|
|||||||
void setCheckerboardEnabled(bool enabled, bool invertColor = false);
|
void setCheckerboardEnabled(bool enabled, bool invertColor = false);
|
||||||
void applyTransformationModeByScaleFactor();
|
void applyTransformationModeByScaleFactor();
|
||||||
|
|
||||||
|
// Consider switch to 3 state for "no fit", "always fit" and "fit when view is smaller"?
|
||||||
|
// ... or even more? e.g. "fit/snap width" things...
|
||||||
|
// Currently it's "no fit" when it's false and "fit when view is smaller" when it's true.
|
||||||
bool m_enableFitInView = false;
|
bool m_enableFitInView = false;
|
||||||
bool m_checkerboardEnabled = false;
|
bool m_checkerboardEnabled = false;
|
||||||
bool m_isLastCheckerboardColorInverted = false;
|
bool m_isLastCheckerboardColorInverted = false;
|
||||||
|
@ -120,7 +120,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked,
|
connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked,
|
||||||
this, [ = ](){
|
this, [ = ](){
|
||||||
m_graphicsView->rotateView();
|
m_graphicsView->rotateView();
|
||||||
m_graphicsView->checkAndDoFitInView();
|
m_graphicsView->displayScene();
|
||||||
m_gv->setVisible(false);
|
m_gv->setVisible(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -493,12 +493,12 @@ void MainWindow::toggleStayOnTop()
|
|||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::stayOnTop()
|
bool MainWindow::stayOnTop() const
|
||||||
{
|
{
|
||||||
return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
|
return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::canPaste()
|
bool MainWindow::canPaste() const
|
||||||
{
|
{
|
||||||
const QMimeData * clipboardData = QApplication::clipboard()->mimeData();
|
const QMimeData * clipboardData = QApplication::clipboard()->mimeData();
|
||||||
if (clipboardData->hasImage()) {
|
if (clipboardData->hasImage()) {
|
||||||
@ -565,10 +565,8 @@ void MainWindow::on_actionHorizontalFlip_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionFitInView_triggered()
|
void MainWindow::on_actionFitInView_triggered()
|
||||||
{
|
{
|
||||||
// TODO: maybe do it if window is smaller than original image size?
|
|
||||||
m_graphicsView->setEnableAutoFitInView(false);
|
|
||||||
|
|
||||||
m_graphicsView->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
|
m_graphicsView->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
|
||||||
|
m_graphicsView->setEnableAutoFitInView(m_graphicsView->scaleFactor() <= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionFitByWidth_triggered()
|
void MainWindow::on_actionFitByWidth_triggered()
|
||||||
|
@ -53,8 +53,8 @@ protected slots:
|
|||||||
void toggleCheckerboard();
|
void toggleCheckerboard();
|
||||||
void toggleProtectedMode();
|
void toggleProtectedMode();
|
||||||
void toggleStayOnTop();
|
void toggleStayOnTop();
|
||||||
bool stayOnTop();
|
bool stayOnTop() const;
|
||||||
bool canPaste();
|
bool canPaste() const;
|
||||||
void quitAppAction(bool force = false);
|
void quitAppAction(bool force = false);
|
||||||
void toggleFullscreen();
|
void toggleFullscreen();
|
||||||
void toggleMaximize();
|
void toggleMaximize();
|
||||||
|
Loading…
Reference in New Issue
Block a user