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

View File

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