Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Make sure that Fit View modes still show actual zoom in the statusbar
Dmitry Kazakovb45f44694bd4
diff --git a/libs/widgets/KoZoomAction.cpp b/libs/widgets/KoZoomAction.cppindex e44cbb3054..5ea16c75f5 100644--- a/libs/widgets/KoZoomAction.cpp+++ b/libs/widgets/KoZoomAction.cpp@@ -138,7 +138,10 @@ void KoZoomAction::regenerateItems()setCurrentItem(d->currentActionState.currentRealLevelIndex);}- Q_EMIT sigInternalUpdateZoomLevelsComboState(values, d->currentActionState.currentRealLevelIndex);+ Q_EMIT sigInternalUpdateZoomLevelsComboState(+ values,+ d->currentActionState.currentRealLevelIndex,+ d->currentActionState.currentRealLevelText);}void KoZoomAction::sliderValueChanged(int value)diff --git a/libs/widgets/KoZoomAction.h b/libs/widgets/KoZoomAction.hindex 11cc0dfcad..3b3291d6d1 100644--- a/libs/widgets/KoZoomAction.h+++ b/libs/widgets/KoZoomAction.h@@ -72,7 +72,7 @@ Q_SIGNALS:void sigUsePrintResolutionModeChanged(bool value);- void sigInternalUpdateZoomLevelsComboState(const QStringList &values, int index);+ void sigInternalUpdateZoomLevelsComboState(const QStringList &values, int index, const QString &activeText);void sigInternalUpdateZoomLevelsSliderState(int size, int index);void sigInternalUpdateUsePrintResolutionMode(bool value);diff --git a/libs/widgets/KoZoomActionState.cpp b/libs/widgets/KoZoomActionState.cppindex 41a00b7397..8f47f275f4 100644--- a/libs/widgets/KoZoomActionState.cpp+++ b/libs/widgets/KoZoomActionState.cpp@@ -52,9 +52,11 @@ KoZoomActionState::KoZoomActionState(const KoZoomState &state)void KoZoomActionState::setZoomState(const KoZoomState &newState){- bool changedGuiLevels = false;+ const bool forceInitialization = realGuiLevels.isEmpty();+ bool needsUpdateRealLevels = forceInitialization;- if (!qFuzzyCompare(newState.minZoom, zoomState.minZoom) ||+ if (forceInitialization ||+ !qFuzzyCompare(newState.minZoom, zoomState.minZoom) ||!qFuzzyCompare(newState.maxZoom, zoomState.maxZoom)) {auto newStandardLevels = KoZoomMode::generateStandardZoomLevels(newState.minZoom, newState.maxZoom);@@ -63,14 +65,14 @@ void KoZoomActionState::setZoomState(const KoZoomState &newState)auto newGuiLevels = generateZoomGuiItems(newStandardLevels);if (newGuiLevels != guiLevels) {guiLevels = newGuiLevels;- changedGuiLevels = true;+ needsUpdateRealLevels = true;}}}int proposedCurrentIndex = currentRealLevelIndex;- if (changedGuiLevels || !qFuzzyCompare(newState.zoom, zoomState.zoom) || newState.mode != zoomState.mode) {+ if (needsUpdateRealLevels || !qFuzzyCompare(newState.zoom, zoomState.zoom) || newState.mode != zoomState.mode) {realGuiLevels = guiLevels;const qreal eps = 1e-5;@@ -93,20 +95,30 @@ void KoZoomActionState::setZoomState(const KoZoomState &newState)proposedCurrentIndex = std::distance(realGuiLevels.begin(), it);}+ auto textForFixedMode = [&] (const int index) {+ ZoomItem zoomItem = realGuiLevels[index];+ return i18nc("concatenate mode name (e.g. \"Fit Page\") and real zoom percent string", "%1 (%2)",+ get<QString>(zoomItem),+ zoomToString(newState.zoom));+ };+switch (newState.mode) {case KoZoomMode::ZOOM_PAGE:currentRealLevelIndex = 0;+ currentRealLevelText = textForFixedMode(currentRealLevelIndex);break;case KoZoomMode::ZOOM_WIDTH:currentRealLevelIndex = 1;+ currentRealLevelText = textForFixedMode(currentRealLevelIndex);break;case KoZoomMode::ZOOM_HEIGHT:currentRealLevelIndex = 2;+ currentRealLevelText = textForFixedMode(currentRealLevelIndex);break;-case KoZoomMode::ZOOM_CONSTANT:default:currentRealLevelIndex = proposedCurrentIndex;+ currentRealLevelText = get<QString>(realGuiLevels[currentRealLevelIndex]);break;}diff --git a/libs/widgets/KoZoomActionState.h b/libs/widgets/KoZoomActionState.hindex 7c68f76665..559420a0eb 100644--- a/libs/widgets/KoZoomActionState.h+++ b/libs/widgets/KoZoomActionState.h@@ -24,6 +24,7 @@ public:QVector<ZoomItem> guiLevels;QVector<ZoomItem> realGuiLevels;int currentRealLevelIndex = 0;+ QString currentRealLevelText;KoZoomActionState(const KoZoomState &state);void setZoomState(const KoZoomState &state);diff --git a/libs/widgets/KoZoomInput.cpp b/libs/widgets/KoZoomInput.cppindex 6c22ba6b42..2bf331b645 100644--- a/libs/widgets/KoZoomInput.cpp+++ b/libs/widgets/KoZoomInput.cpp@@ -158,9 +158,14 @@ void KoZoomInput::setZoomLevels(const QStringList& levels)}void KoZoomInput::setCurrentZoomLevel(int index)+{+ setCurrentZoomLevel(index, d->combo->itemText(index));+}++void KoZoomInput::setCurrentZoomLevel(int index, const QString &activeText){d->combo->setCurrentIndex(index);- d->label->setText(d->combo->itemText(index));+ d->label->setText(activeText);}void KoZoomInput::setCurrentZoomLevel(const QString& level)diff --git a/libs/widgets/KoZoomInput.h b/libs/widgets/KoZoomInput.hindex f91b88a7c1..c754a8a30c 100644--- a/libs/widgets/KoZoomInput.h+++ b/libs/widgets/KoZoomInput.h@@ -21,6 +21,7 @@ class KoZoomInput : public QStackedWidgetvoid setZoomLevels(const QStringList& levels);void setCurrentZoomLevel(const QString& level);void setCurrentZoomLevel(int index);+ void setCurrentZoomLevel(int index, const QString &activeText);bool eventFilter(QObject* watched, QEvent* event) override;diff --git a/libs/widgets/KoZoomWidget.cpp b/libs/widgets/KoZoomWidget.cppindex 75b653c304..718241f61d 100644--- a/libs/widgets/KoZoomWidget.cpp+++ b/libs/widgets/KoZoomWidget.cpp@@ -98,11 +98,11 @@ void KoZoomWidget::setSliderState(int size, int index)d->slider->setValue(index);}-void KoZoomWidget::setZoomLevelsState(const QStringList &values, int index)+void KoZoomWidget::setZoomLevelsState(const QStringList &values, int index, const QString &activeText){QSignalBlocker b(d->input);d->input->setZoomLevels(values);- d->input->setCurrentZoomLevel(index);+ d->input->setCurrentZoomLevel(index, activeText);}void KoZoomWidget::setCurrentZoomLevel(int index)diff --git a/libs/widgets/KoZoomWidget.h b/libs/widgets/KoZoomWidget.hindex 5bfa4fe32d..f4af5c57ad 100644--- a/libs/widgets/KoZoomWidget.h+++ b/libs/widgets/KoZoomWidget.h@@ -43,7 +43,7 @@ Q_SIGNALS:public Q_SLOTS:void setSliderState(int size, int index);- void setZoomLevelsState(const QStringList &values, int index);+ void setZoomLevelsState(const QStringList &values, int index, const QString &activeText);void setCurrentZoomLevel(const QString &valueString);void setCurrentZoomLevel(int index);void setSliderValue(int value);diff --git a/libs/widgets/tests/TestKoZoomAction.cpp b/libs/widgets/tests/TestKoZoomAction.cppindex e36580ebb7..eae44825b8 100644--- a/libs/widgets/tests/TestKoZoomAction.cpp+++ b/libs/widgets/tests/TestKoZoomAction.cpp@@ -111,6 +111,7 @@ void TestKoZoomAction::testZoomActionState_data()QTest::addColumn<QVector<LightZoomItem>>("expectedGuiLevels");QTest::addColumn<QVector<LightZoomItem>>("expectedRealLevels");QTest::addColumn<int>("expectedRealIndex");+ QTest::addColumn<QString>("expectedRealText");const std::optional<KoZoomState> noZoomState = std::nullopt;@@ -129,7 +130,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.45), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 5;+ << 5+ << "45.0%";QTest::addRow("constant-exact")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 0.5, 0.1, 2.0)@@ -144,7 +146,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 5;+ << 5+ << "50.0%";QTest::addRow("constant-fuzzy-left")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 0.5 - 1e-7, 0.1, 2.0)@@ -159,7 +162,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 5;+ << 5+ << "50.0%";QTest::addRow("constant-fuzzy-right")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 0.5 - 1e-7, 0.1, 2.0)@@ -174,7 +178,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 5;+ << 5+ << "50.0%";QTest::addRow("constant-low")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 0.11, 0.1, 2.0)@@ -189,7 +194,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.11), zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 3;+ << 3+ << "11.0%";QTest::addRow("constant-high")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 2.1, 0.1, 2.0)@@ -204,7 +210,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0), zi(2.1)}- << 10;+ << 10+ << "210.0%";QTest::addRow("page")<< KoZoomState(KoZoomMode::ZOOM_PAGE, 0.5, 0.1, 2.0)@@ -219,7 +226,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 0;+ << 0+ << "Fit View (50.0%)";QTest::addRow("width")<< KoZoomState(KoZoomMode::ZOOM_WIDTH, 0.5, 0.1, 2.0)@@ -234,7 +242,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 1;+ << 1+ << "Fit View Width (50.0%)";QTest::addRow("height")<< KoZoomState(KoZoomMode::ZOOM_HEIGHT, 0.5, 0.1, 2.0)@@ -249,7 +258,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 2;+ << 2+ << "Fit View Height (50.0%)";QTest::addRow("page-to-same-constant")<< KoZoomState(KoZoomMode::ZOOM_PAGE, 0.5, 0.1, 2.0)@@ -264,7 +274,8 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 5; // the mode has changed!+ << 5 // the mode has changed!+ << "50.0%";QTest::addRow("constant-to-same-page")<< KoZoomState(KoZoomMode::ZOOM_CONSTANT, 0.45, 0.1, 2.0)@@ -279,11 +290,15 @@ void TestKoZoomAction::testZoomActionState_data()zi(KoZoomMode::ZOOM_PAGE), zi(KoZoomMode::ZOOM_WIDTH), zi(KoZoomMode::ZOOM_HEIGHT),zi(0.25), zi(0.333333), zi(0.45), zi(0.5), zi(0.666667), zi(1.0), zi(1.33333), zi(2.0)}- << 0;+ << 0+ << "Fit View (45.0%)";}void TestKoZoomAction::testZoomActionState(){+ // to be able to compare zoom strings+ QLocale::setDefault(QLocale::C);+QFETCH(KoZoomState, zoomState);QFETCH(std::optional<KoZoomState>, additionalSwitchState);QFETCH(QVector<qreal>, expectedStandardLevels);@@ -291,6 +306,7 @@ void TestKoZoomAction::testZoomActionState()QFETCH(QVector<LightZoomItem>, expectedGuiLevels);QFETCH(QVector<LightZoomItem>, expectedRealLevels);QFETCH(int, expectedRealIndex);+ QFETCH(QString, expectedRealText);KoZoomActionState actionState(zoomState);QCOMPARE(actionState.zoomState, zoomState);@@ -314,7 +330,15 @@ void TestKoZoomAction::testZoomActionState()QCOMPARE(actionState.currentRealLevelIndex, expectedRealIndex);QCOMPARE(actionState.calcNearestStandardLevel(actionState.zoomState.zoom), expectedStandardLevelIndex);+ QCOMPARE(actionState.currentRealLevelText, expectedRealText);}+void TestKoZoomAction::testInitWithDefault()+{+ KoZoomActionState actionState(KoZoomState{});+ QVERIFY(actionState.standardLevels.size() > 0);+ QVERIFY(actionState.guiLevels.size() > 0);+ QVERIFY(actionState.realGuiLevels.size() > 0);+}SIMPLE_TEST_MAIN(TestKoZoomAction)diff --git a/libs/widgets/tests/TestKoZoomAction.h b/libs/widgets/tests/TestKoZoomAction.hindex 8bc05f7fa9..0b94bf82e0 100644--- a/libs/widgets/tests/TestKoZoomAction.h+++ b/libs/widgets/tests/TestKoZoomAction.h@@ -17,6 +17,7 @@ class TestKoZoomAction : public QObjectprivate Q_SLOTS:void testZoomActionState_data();void testZoomActionState();+ void testInitWithDefault();};#endif /* __TEST_KO_ZOOM_ACTION_H */