Commit 1ccec988 authored by Jochen Becher's avatar Jochen Becher Committed by Eike Ziller

ModelEditor: Zoom with Ctrl + mouse wheel

Change-Id: I2e703345a882f0dbd80a0957d5f28bd203f4f26b
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
(cherry picked from commit 3e776dde)
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent 8fbd3cd3
......@@ -33,6 +33,8 @@
#include <projectexplorer/projectnodes.h>
#include <utils/dropsupport.h>
#include <QWheelEvent>
namespace ModelEditor {
namespace Internal {
......@@ -63,6 +65,17 @@ void EditorDiagramView::setPxNodeController(PxNodeController *pxNodeController)
d->pxNodeController = pxNodeController;
}
void EditorDiagramView::wheelEvent(QWheelEvent *wheelEvent)
{
if (wheelEvent->modifiers() == Qt::ControlModifier) {
int degree = wheelEvent->angleDelta().y() / 8;
if (degree > 0)
emit zoomIn();
else if (degree < 0)
emit zoomOut();
}
}
void EditorDiagramView::dropProjectExplorerNodes(const QList<QVariant> &values, const QPoint &pos)
{
foreach (const QVariant &value, values) {
......
......@@ -40,10 +40,18 @@ class EditorDiagramView :
public:
explicit EditorDiagramView(QWidget *parent = 0);
~EditorDiagramView();
~EditorDiagramView() override;
signals:
void zoomIn();
void zoomOut();
public:
void setPxNodeController(PxNodeController *pxNodeController);
protected:
void wheelEvent(QWheelEvent *wheelEvent) override;
private:
void dropProjectExplorerNodes(const QList<QVariant> &values, const QPoint &pos);
......
......@@ -69,6 +69,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/actionmanager/commandbutton.h>
#include <utils/fadingindicator.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
......@@ -376,6 +377,11 @@ void ModelEditor::initDocument()
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, &ModelEditor::onCurrentEditorChanged, Qt::QueuedConnection);
connect(d->diagramView, &EditorDiagramView::zoomIn,
this, &ModelEditor::zoomIn);
connect(d->diagramView, &EditorDiagramView::zoomOut,
this, &ModelEditor::zoomOut);
connect(d->modelTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &ModelEditor::onTreeViewSelectionChanged, Qt::QueuedConnection);
connect(d->modelTreeView, &qmt::ModelTreeView::treeViewActivated,
......@@ -564,6 +570,7 @@ void ModelEditor::zoomIn()
QTransform transform = d->diagramView->transform();
transform.scale(ZOOM_FACTOR, ZOOM_FACTOR);
d->diagramView->setTransform(transform);
showZoomIndicator();
}
void ModelEditor::zoomOut()
......@@ -571,11 +578,13 @@ void ModelEditor::zoomOut()
QTransform transform = d->diagramView->transform();
transform.scale(1.0 / ZOOM_FACTOR, 1.0 / ZOOM_FACTOR);
d->diagramView->setTransform(transform);
showZoomIndicator();
}
void ModelEditor::resetZoom()
{
d->diagramView->setTransform(QTransform());
showZoomIndicator();
}
qmt::MPackage *ModelEditor::guessSelectedPackage() const
......@@ -766,6 +775,15 @@ bool ModelEditor::updateButtonIconByTheme(QAbstractButton *button, const QString
return false;
}
void ModelEditor::showZoomIndicator()
{
int scale = int(d->diagramView->transform().map(QPointF(100, 100)).x() + 0.5);
Utils::FadingIndicator::showText(d->diagramStack,
QCoreApplication::translate("ModelEditor",
"Zoom: %1%").arg(scale),
Utils::FadingIndicator::SmallText);
}
void ModelEditor::onAddPackage()
{
ExtDocumentController *documentController = d->document->documentController();
......
......@@ -105,6 +105,7 @@ private:
const QIcon &icon,
const QString &toolTipBase, QWidget *parent);
bool updateButtonIconByTheme(QAbstractButton *button, const QString &name);
void showZoomIndicator();
void onAddPackage();
void onAddComponent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment