Commit 3e776dde authored by Jochen Becher's avatar Jochen Becher

ModelEditor: Zoom with Ctrl + mouse wheel

Change-Id: I2e703345a882f0dbd80a0957d5f28bd203f4f26b
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 80e52599
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <projectexplorer/projectnodes.h> #include <projectexplorer/projectnodes.h>
#include <utils/dropsupport.h> #include <utils/dropsupport.h>
#include <QWheelEvent>
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
...@@ -63,6 +65,17 @@ void EditorDiagramView::setPxNodeController(PxNodeController *pxNodeController) ...@@ -63,6 +65,17 @@ void EditorDiagramView::setPxNodeController(PxNodeController *pxNodeController)
d->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) void EditorDiagramView::dropProjectExplorerNodes(const QList<QVariant> &values, const QPoint &pos)
{ {
foreach (const QVariant &value, values) { foreach (const QVariant &value, values) {
......
...@@ -40,10 +40,18 @@ class EditorDiagramView : ...@@ -40,10 +40,18 @@ class EditorDiagramView :
public: public:
explicit EditorDiagramView(QWidget *parent = 0); explicit EditorDiagramView(QWidget *parent = 0);
~EditorDiagramView(); ~EditorDiagramView() override;
signals:
void zoomIn();
void zoomOut();
public:
void setPxNodeController(PxNodeController *pxNodeController); void setPxNodeController(PxNodeController *pxNodeController);
protected:
void wheelEvent(QWheelEvent *wheelEvent) override;
private: private:
void dropProjectExplorerNodes(const QList<QVariant> &values, const QPoint &pos); void dropProjectExplorerNodes(const QList<QVariant> &values, const QPoint &pos);
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/minisplitter.h> #include <coreplugin/minisplitter.h>
#include <coreplugin/actionmanager/commandbutton.h> #include <coreplugin/actionmanager/commandbutton.h>
#include <utils/fadingindicator.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
...@@ -376,6 +377,11 @@ void ModelEditor::initDocument() ...@@ -376,6 +377,11 @@ void ModelEditor::initDocument()
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, &ModelEditor::onCurrentEditorChanged, Qt::QueuedConnection); 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, connect(d->modelTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &ModelEditor::onTreeViewSelectionChanged, Qt::QueuedConnection); this, &ModelEditor::onTreeViewSelectionChanged, Qt::QueuedConnection);
connect(d->modelTreeView, &qmt::ModelTreeView::treeViewActivated, connect(d->modelTreeView, &qmt::ModelTreeView::treeViewActivated,
...@@ -564,6 +570,7 @@ void ModelEditor::zoomIn() ...@@ -564,6 +570,7 @@ void ModelEditor::zoomIn()
QTransform transform = d->diagramView->transform(); QTransform transform = d->diagramView->transform();
transform.scale(ZOOM_FACTOR, ZOOM_FACTOR); transform.scale(ZOOM_FACTOR, ZOOM_FACTOR);
d->diagramView->setTransform(transform); d->diagramView->setTransform(transform);
showZoomIndicator();
} }
void ModelEditor::zoomOut() void ModelEditor::zoomOut()
...@@ -571,11 +578,13 @@ void ModelEditor::zoomOut() ...@@ -571,11 +578,13 @@ void ModelEditor::zoomOut()
QTransform transform = d->diagramView->transform(); QTransform transform = d->diagramView->transform();
transform.scale(1.0 / ZOOM_FACTOR, 1.0 / ZOOM_FACTOR); transform.scale(1.0 / ZOOM_FACTOR, 1.0 / ZOOM_FACTOR);
d->diagramView->setTransform(transform); d->diagramView->setTransform(transform);
showZoomIndicator();
} }
void ModelEditor::resetZoom() void ModelEditor::resetZoom()
{ {
d->diagramView->setTransform(QTransform()); d->diagramView->setTransform(QTransform());
showZoomIndicator();
} }
qmt::MPackage *ModelEditor::guessSelectedPackage() const qmt::MPackage *ModelEditor::guessSelectedPackage() const
...@@ -766,6 +775,15 @@ bool ModelEditor::updateButtonIconByTheme(QAbstractButton *button, const QString ...@@ -766,6 +775,15 @@ bool ModelEditor::updateButtonIconByTheme(QAbstractButton *button, const QString
return false; 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() void ModelEditor::onAddPackage()
{ {
ExtDocumentController *documentController = d->document->documentController(); ExtDocumentController *documentController = d->document->documentController();
......
...@@ -105,6 +105,7 @@ private: ...@@ -105,6 +105,7 @@ private:
const QIcon &icon, const QIcon &icon,
const QString &toolTipBase, QWidget *parent); const QString &toolTipBase, QWidget *parent);
bool updateButtonIconByTheme(QAbstractButton *button, const QString &name); bool updateButtonIconByTheme(QAbstractButton *button, const QString &name);
void showZoomIndicator();
void onAddPackage(); void onAddPackage();
void onAddComponent(); 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