QmlDesigner: add resetZoomLevel to ZoomAction

we always start from 100%

Change-Id: I7877fe36430e1a80dc5258ee4ed2ed68ffaadd81
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tim Jenssen
2018-05-03 10:07:50 +02:00
parent b395bffefb
commit 21faaaf2ce
2 changed files with 16 additions and 1 deletions

View File

@@ -26,6 +26,7 @@
#include "zoomaction.h"
#include <QComboBox>
#include <QAbstractItemView>
namespace QmlDesigner {
@@ -55,6 +56,13 @@ void ZoomAction::zoomOut()
emit indexChanged(m_currentComboBoxIndex + 1);
}
void ZoomAction::resetZoomLevel()
{
m_zoomLevel = 1.0;
m_currentComboBoxIndex = 8;
emit reseted();
}
void ZoomAction::setZoomLevel(double zoomLevel)
{
m_zoomLevel = qBound(0.1, zoomLevel, 16.0);
@@ -90,7 +98,12 @@ QWidget *ZoomAction::createWidget(QWidget *parent)
comboBox->setModel(m_comboBoxModel.data());
}
comboBox->setCurrentIndex(8);
comboBox->setCurrentIndex(m_currentComboBoxIndex);
connect(this, &ZoomAction::reseted, comboBox, [this, comboBox]() {
blockSignals(true);
comboBox->setCurrentIndex(m_currentComboBoxIndex);
blockSignals(false);
});
connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &ZoomAction::emitZoomLevelChanged);
connect(this, &ZoomAction::indexChanged, comboBox, &QComboBox::setCurrentIndex);

View File

@@ -44,6 +44,7 @@ public:
void zoomIn();
void zoomOut();
void resetZoomLevel();
protected:
QWidget *createWidget(QWidget *parent);
@@ -51,6 +52,7 @@ protected:
signals:
void zoomLevelChanged(double zoom);
void indexChanged(int);
void reseted();
private:
void emitZoomLevelChanged(int index);