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>
This commit is contained in:
Henning Gruendl
2020-06-12 14:28:55 +02:00
committed by Henning Gründl
parent d52cb22b44
commit fe5636e53b
5 changed files with 41 additions and 2 deletions

View File

@@ -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;

View File

@@ -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(

View File

@@ -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());

View File

@@ -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);

View File

@@ -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