diff options
author | Henning Gruendl <henning.gruendl@qt.io> | 2020-06-12 14:28:55 +0200 |
---|---|---|
committer | Henning Gründl <henning.gruendl@qt.io> | 2020-06-12 16:12:15 +0000 |
commit | fe5636e53b1be9fcc0f8a5d302163eb42cec0b6b (patch) | |
tree | 369e2cb8399f8259846b8db9fb00eb7939b2d1ae | |
parent | d52cb22b441d1d95e06814506e63db4884831477 (diff) |
QmlDesigner: Add fit selection to screen button
* Add fit selection to screen action to designer actions
* Add button to form editor taskbar to trigger the action
Change-Id: I3774802f034892ea07782717c769c5141eae4bea
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
5 files changed, 41 insertions, 2 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h index e6ecc114b7..2fa19a5c24 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h +++ b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h @@ -84,6 +84,7 @@ const char flowAssignEffectCommandId[] = "AssignFlowEffect"; const char flowAssignCustomEffectCommandId[] = "AssignFlowCustomEffect"; const char addToGroupItemCommandId[] = "AddToGroupItem"; const char fitRootToScreenCommandId[] = "FitRootToScreen"; +const char fitSelectionToScreenCommandId[] = "FitSelectionToScreen"; const char selectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Selection"); const char flowConnectionCategoryDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Connect"); @@ -157,6 +158,7 @@ const char flowAssignEffectDisplayName[] = "Assign FlowEffect "; const char flowAssignCustomEffectDisplayName[] = "Assign Custom FlowEffect "; const char fitRootToScreenDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fit root to screen"); +const char fitSelectionToScreenDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fit selection to screen"); const char raiseToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Raise selected item."); const char lowerToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Lower selected item."); @@ -177,6 +179,7 @@ const char addItemToStackedContainerToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerCo const char addFlowActionToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add flow action."); const char fitRootToScreenToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fit the root element inside the available space."); +const char fitSelectionToScreenToolTip[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Fit the selected elements inside the available space."); const int priorityFirst = 280; const int prioritySelectionCategory = 220; diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index ceb8ddcdd0..479f40203c 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -831,6 +831,17 @@ void DesignerActionManager::createDefaultDesignerActions() 182, &fitRootToScreen)); + addDesignerAction(new ModelNodeAction( + fitSelectionToScreenCommandId, + fitSelectionToScreenDisplayName, + Utils::Icon({{":/utils/images/fittoview.png", Utils::Theme::IconsBaseColor}}).icon(), + fitSelectionToScreenToolTip, + genericToolBarCategory, + QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_I), + 183, + &fitSelectionToScreen, + &selectionNotEmpty)); + addDesignerAction(new SeperatorDesignerAction(editCategory, 170)); addDesignerAction(new VisiblityModelNodeAction( diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index c73f48d6af..71d1ec4534 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -352,6 +352,15 @@ void fitRootToScreen(const SelectionContext &selectionState) selectionState.view()->emitCustomNotification(QStringLiteral("fit root to screen")); } +void fitSelectionToScreen(const SelectionContext &selectionState) +{ + if (!selectionState.view()) + return; + + selectionState.view()->emitCustomNotification(QStringLiteral("fit selection to screen"), + selectionState.selectedModelNodes()); +} + void goIntoComponentOperation(const SelectionContext &selectionState) { goIntoComponent(selectionState.currentSingleSelectedNode()); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index b8bbc0e1c9..0a8e094a7e 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -50,6 +50,7 @@ void setFillHeight(const SelectionContext &selectionState); void resetSize(const SelectionContext &selectionState); void resetPosition(const SelectionContext &selectionState); void fitRootToScreen(const SelectionContext &selectionState); +void fitSelectionToScreen(const SelectionContext &selectionState); void goIntoComponentOperation(const SelectionContext &selectionState); void setId(const SelectionContext &selectionState); void resetZ(const SelectionContext &selectionState); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index db2d10849f..f64b45f351 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -442,14 +442,13 @@ void FormEditorView::documentMessagesChanged(const QList<DocumentMessage> &error m_formEditorWidget->hideErrorMessageBox(); } -void FormEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) +void FormEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &/*data*/) { if (identifier == QLatin1String("puppet crashed")) m_dragTool->clearMoveDelay(); if (identifier == QLatin1String("reset QmlPuppet")) temporaryBlockView(); if (identifier == QLatin1String("fit root to screen")) { - if (QmlItemNode(rootModelNode()).isFlowView()) { QRectF boundingRect; for (QGraphicsItem *item : scene()->items()) { @@ -470,6 +469,22 @@ void FormEditorView::customNotification(const AbstractView * /*view*/, const QSt float zoomLevel = ZoomAction::getClosestZoomLevel(scaleFactor); m_formEditorWidget->zoomAction()->forceZoomLevel(zoomLevel); } + if (identifier == QLatin1String("fit selection to screen")) { + if (nodeList.isEmpty()) + return; + + QRectF boundingRect; + for (const ModelNode &node : nodeList) { + if (FormEditorItem *item = scene()->itemForQmlItemNode(node)) + boundingRect = boundingRect.united(item->sceneBoundingRect()); + } + + m_formEditorWidget->graphicsView()->fitInView(boundingRect, + Qt::KeepAspectRatio); + const qreal scaleFactor = m_formEditorWidget->graphicsView()->viewportTransform().m11(); + float zoomLevel = ZoomAction::getClosestZoomLevel(scaleFactor); + m_formEditorWidget->zoomAction()->forceZoomLevel(zoomLevel); + } } AbstractFormEditorTool *FormEditorView::currentTool() const |