diff --git a/resources/icons/dark/fitImage.svg b/resources/icons/dark/fitImage.svg
new file mode 100644
index 00000000..11a0cea6
--- /dev/null
+++ b/resources/icons/dark/fitImage.svg
@@ -0,0 +1,76 @@
+
+
+
\ No newline at end of file
diff --git a/resources/icons/light/fitImage.svg b/resources/icons/light/fitImage.svg
new file mode 100644
index 00000000..9fec4b3d
--- /dev/null
+++ b/resources/icons/light/fitImage.svg
@@ -0,0 +1,76 @@
+
+
+
\ No newline at end of file
diff --git a/resources/kImageAnnotator_resources.qrc b/resources/kImageAnnotator_resources.qrc
index 93db9434..a55400be 100644
--- a/resources/kImageAnnotator_resources.qrc
+++ b/resources/kImageAnnotator_resources.qrc
@@ -48,6 +48,7 @@
icons/dark/italic.svg
icons/dark/underline.svg
icons/dark/cut.svg
+ icons/dark/fitImage.svg
@@ -98,6 +99,7 @@
icons/light/italic.svg
icons/light/underline.svg
icons/light/cut.svg
+ icons/light/fitImage.svg
diff --git a/src/gui/annotator/settings/AnnotationGeneralSettings.cpp b/src/gui/annotator/settings/AnnotationGeneralSettings.cpp
index f4e54777..76a31e3a 100644
--- a/src/gui/annotator/settings/AnnotationGeneralSettings.cpp
+++ b/src/gui/annotator/settings/AnnotationGeneralSettings.cpp
@@ -45,6 +45,7 @@ void AnnotationGeneralSettings::initGui()
setFocusPolicy(Qt::ClickFocus);
connect(mZoomPicker, &ZoomPicker::zoomValueChanged, this, &AnnotationGeneralSettings::zoomValueChanged);
+ connect(mZoomPicker, &ZoomPicker::fitImageToViewSignal, this, &AnnotationGeneralSettings::zoomValueChanged);
}
void AnnotationGeneralSettings::updateZoomLevel(double value)
diff --git a/src/gui/scrollAndZoomView/ViewZoomer.cpp b/src/gui/scrollAndZoomView/ViewZoomer.cpp
index daf99349..1170a772 100644
--- a/src/gui/scrollAndZoomView/ViewZoomer.cpp
+++ b/src/gui/scrollAndZoomView/ViewZoomer.cpp
@@ -64,8 +64,18 @@ void ViewZoomer::wheelZoom(QWheelEvent *event)
event->accept(); // supress scrolling
}
+void ViewZoomer::fitImage()
+{
+ mView->fitInView(mView->sceneRect(), Qt::KeepAspectRatio);
+}
+
void ViewZoomer::setZoomValue(double value)
{
+ // ZoomPicker's mFitImageButton() sets value to -1
+ if (value < 0) {
+ fitImage();
+ return;
+ }
zoom(value - zoomValue());
}
diff --git a/src/gui/scrollAndZoomView/ViewZoomer.h b/src/gui/scrollAndZoomView/ViewZoomer.h
index 26b07c19..16ef8cf9 100644
--- a/src/gui/scrollAndZoomView/ViewZoomer.h
+++ b/src/gui/scrollAndZoomView/ViewZoomer.h
@@ -42,6 +42,7 @@ class ViewZoomer : public ZoomValueProvider
void zoom(double factor);
void zoomToPoint(double factor, const QPoint &viewPoint);
void wheelZoom(QWheelEvent *event);
+ void fitImage();
private:
QGraphicsView *mView;
diff --git a/src/widgets/settingsPicker/ZoomPicker.cpp b/src/widgets/settingsPicker/ZoomPicker.cpp
index a843bcf5..62e76de9 100644
--- a/src/widgets/settingsPicker/ZoomPicker.cpp
+++ b/src/widgets/settingsPicker/ZoomPicker.cpp
@@ -28,7 +28,8 @@ ZoomPicker::ZoomPicker(QWidget *parent) :
mSpinBox(new CustomSpinBox(this)),
mZoomInAction(new QAction(this)),
mZoomOutAction(new QAction(this)),
- mResetZoomAction(new QAction(this))
+ mResetZoomAction(new QAction(this)),
+ mFitImageAction(new QAction(this))
{
initGui();
}
@@ -51,9 +52,14 @@ void ZoomPicker::initGui()
mSpinBox->setSuffix(QLatin1String("%"));
mSpinBox->setWrapping(false);
+ mFitImageAction = createAction(tr("Fit Image"), IconLoader::load(QLatin1String("fitImage.svg")));
+ connect(mFitImageAction, &QAction::triggered, this, &ZoomPicker::fitImageToView);
+ mFitImageButton = createButton(mFitImageAction);
+
mZoomInAction->setShortcut(QKeySequence::ZoomIn);
mZoomOutAction->setShortcut(QKeySequence::ZoomOut);
mResetZoomAction->setShortcut(Qt::CTRL + Qt::Key_0);
+ mFitImageAction->setShortcut(Qt::CTRL + Qt::Key_F);
setToolTip(getToolTip());
@@ -69,6 +75,7 @@ void ZoomPicker::initGui()
mLayout->addWidget(mLabel);
mLayout->addWidget(mSpinBox);
+ mLayout->addWidget(mFitImageButton);
mLayout->setAlignment(Qt::AlignLeft);
setLayout(mLayout);
@@ -80,7 +87,24 @@ QString ZoomPicker::getToolTip() const
auto zoomIn = tr("Zoom In (%1)").arg(mZoomInAction->shortcut().toString());
auto zoomOut = tr("Zoom Out (%1)").arg(mZoomOutAction->shortcut().toString());
auto resetZoom = tr("Reset Zoom (%1)").arg(mResetZoomAction->shortcut().toString());
- return zoomIn + newLine + zoomOut + newLine + resetZoom;
+ auto fitZoom = tr("Fit image to view (%1)").arg(mFitImageAction->shortcut().toString());
+ return zoomIn + newLine + zoomOut + newLine + resetZoom + newLine + fitZoom;
+}
+
+QAction *ZoomPicker::createAction(const QString &tooltip, const QIcon &icon)
+{
+ auto action = new CustomToolButtonAction(this);
+ action->setIcon(icon);
+ action->setToolTip(tooltip);
+ action->updateDefaultWidget();
+ return action;
+}
+
+CustomToolButton *ZoomPicker::createButton(QAction *defaultAction)
+{
+ auto button = new CustomToolButton(this);
+ button->setAction(defaultAction);
+ return button;
}
void ZoomPicker::setZoomValue(double value)
@@ -89,6 +113,11 @@ void ZoomPicker::setZoomValue(double value)
mSpinBox->setValueSilent(zoomValue);
}
+void ZoomPicker::fitImageToView()
+{
+ emit fitImageToViewSignal(-1);
+}
+
void ZoomPicker::notifyZoomValueChanged(double value)
{
emit zoomValueChanged(value / 100.0);
diff --git a/src/widgets/settingsPicker/ZoomPicker.h b/src/widgets/settingsPicker/ZoomPicker.h
index 86225c01..55f458c0 100644
--- a/src/widgets/settingsPicker/ZoomPicker.h
+++ b/src/widgets/settingsPicker/ZoomPicker.h
@@ -23,12 +23,16 @@
#include
#include
#include
+#include
#include
#include "src/widgets/CustomSpinBox.h"
+#include "src/widgets/CustomToolButton.h"
+#include "src/widgets/CustomToolButtonAction.h"
#include "src/widgets/settingsPicker/SettingsPickerWidget.h"
#include "src/common/helper/IconLoader.h"
#include "src/common/provider/ScaledSizeProvider.h"
+#include "src/gui/scrollAndZoomView/ViewZoomer.h"
namespace kImageAnnotator {
@@ -41,9 +45,11 @@ Q_OBJECT
public slots:
void setZoomValue(double value);
+ void fitImageToView();
signals:
void zoomValueChanged(double zoomLevel);
+ void fitImageToViewSignal(double value);
protected:
QWidget* expandingWidget() override;
@@ -55,7 +61,10 @@ public slots:
QAction *mZoomInAction;
QAction *mZoomOutAction;
QAction *mResetZoomAction;
-
+ QAction *mFitImageAction;
+ CustomToolButton *mFitImageButton;
+ QAction *createAction(const QString &tooltip, const QIcon &icon);
+ CustomToolButton *createButton(QAction *defaultAction);
void initGui();
private slots: