forked from qt-creator/qt-creator
QmlDesigner: Add MouseArea Shortcut
Task-number: QDS-7675 Change-Id: Ibc0bdeecbd83a063d99973fd6bc945907f4a124a Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -92,6 +92,7 @@ const char removeGroupItemCommandId[] = "RemoveToGroupItem";
|
||||
const char fitRootToScreenCommandId[] = "FitRootToScreen";
|
||||
const char fitSelectionToScreenCommandId[] = "FitSelectionToScreen";
|
||||
const char editAnnotationCommandId[] = "EditAnnotation";
|
||||
const char addMouseAreaFillCommandId[] = "AddMouseAreaFill";
|
||||
|
||||
const char openSignalDialogCommandId[] = "OpenSignalDialog";
|
||||
const char update3DAssetCommandId[] = "Update3DAsset";
|
||||
@@ -137,6 +138,7 @@ const char addSignalHandlerDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContext
|
||||
const char moveToComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Move Component into Separate File");
|
||||
const char editMaterialDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit Material");
|
||||
const char editAnnotationDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit Annotation");
|
||||
const char addMouseAreaFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Add Mouse Area");
|
||||
|
||||
const char openSignalDialogDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Open Signal Dialog");
|
||||
const char update3DAssetDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Update 3D Asset");
|
||||
|
@@ -1474,6 +1474,17 @@ void DesignerActionManager::createDefaultDesignerActions()
|
||||
&singleSelection,
|
||||
&singleSelection));
|
||||
|
||||
addDesignerAction(new ModelNodeContextMenuAction(
|
||||
addMouseAreaFillCommandId,
|
||||
addMouseAreaFillDisplayName,
|
||||
{},
|
||||
rootCategory,
|
||||
QKeySequence(),
|
||||
(priorityLast+7),
|
||||
&addMouseAreaFill,
|
||||
&addMouseAreaFillCheck,
|
||||
&singleSelection));
|
||||
|
||||
const bool standaloneMode = QmlProjectManager::QmlProject::isQtDesignStudio();
|
||||
|
||||
if (!standaloneMode) {
|
||||
|
@@ -64,6 +64,18 @@ inline bool singleSelection(const SelectionContext &selectionState)
|
||||
return selectionState.singleNodeIsSelected();
|
||||
}
|
||||
|
||||
inline bool addMouseAreaFillCheck(const SelectionContext &selectionContext)
|
||||
{
|
||||
if (selectionContext.isValid() && selectionContext.singleNodeIsSelected()) {
|
||||
ModelNode node = selectionContext.currentSingleSelectedNode();
|
||||
if (node.hasMetaInfo()) {
|
||||
NodeMetaInfo nodeInfo = node.metaInfo();
|
||||
return nodeInfo.isSuitableForMouseAreaFill();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isModel(const SelectionContext &selectionState)
|
||||
{
|
||||
ModelNode node = selectionState.currentSingleSelectedNode();
|
||||
|
@@ -1620,6 +1620,34 @@ void editAnnotation(const SelectionContext &selectionContext)
|
||||
ModelNodeEditorProxy::fromModelNode<AnnotationEditor>(selectedNode);
|
||||
}
|
||||
|
||||
void addMouseAreaFill(const SelectionContext &selectionContext)
|
||||
{
|
||||
if (!selectionContext.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectionContext.singleNodeIsSelected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectionContext.view()->executeInTransaction("DesignerActionManager|addMouseAreaFill", [selectionContext]() {
|
||||
ModelNode modelNode = selectionContext.currentSingleSelectedNode();
|
||||
if (modelNode.isValid()) {
|
||||
NodeMetaInfo itemMetaInfo = selectionContext.view()->model()->metaInfo("QtQuick.MouseArea", -1, -1);
|
||||
QTC_ASSERT(itemMetaInfo.isValid(), return);
|
||||
|
||||
QmlDesigner::ModelNode mouseAreaNode =
|
||||
selectionContext.view()->createModelNode("QtQuick.MouseArea", itemMetaInfo.majorVersion(), itemMetaInfo.minorVersion());
|
||||
|
||||
modelNode.defaultNodeListProperty().reparentHere(mouseAreaNode);
|
||||
QmlItemNode mouseAreaItemNode(mouseAreaNode);
|
||||
if (mouseAreaItemNode.isValid()) {
|
||||
mouseAreaItemNode.anchors().fill();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QVariant previewImageDataForGenericNode(const ModelNode &modelNode)
|
||||
{
|
||||
if (modelNode.isValid())
|
||||
|
@@ -93,6 +93,7 @@ void selectFlowEffect(const SelectionContext &selectionContext);
|
||||
void mergeWithTemplate(const SelectionContext &selectionContext);
|
||||
void removeGroup(const SelectionContext &selectionContext);
|
||||
void editAnnotation(const SelectionContext &selectionContext);
|
||||
void addMouseAreaFill(const SelectionContext &selectionContext);
|
||||
|
||||
void openSignalDialog(const SelectionContext &selectionContext);
|
||||
void updateImported3DAsset(const SelectionContext &selectionContext);
|
||||
|
@@ -95,6 +95,7 @@ public:
|
||||
bool availableInVersion(int majorVersion, int minorVersion) const;
|
||||
bool isSubclassOf(const TypeName &type, int majorVersion = -1, int minorVersion = -1) const;
|
||||
|
||||
bool isSuitableForMouseAreaFill() const;
|
||||
bool isGraphicalItem() const;
|
||||
bool isQmlItem() const;
|
||||
bool isLayoutable() const;
|
||||
|
@@ -1659,6 +1659,14 @@ bool NodeMetaInfo::isSubclassOf(const TypeName &type, int majorVersion, int mino
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isSuitableForMouseAreaFill() const
|
||||
{
|
||||
return isSubclassOf("QtQuick.Item")
|
||||
&& !isSubclassOf("QtQuick.MouseArea")
|
||||
&& !isSubclassOf("QtQuick.Controls.Control")
|
||||
&& !isSubclassOf("QtQuick.Templates.Control");
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isGraphicalItem() const
|
||||
{
|
||||
return isSubclassOf("QtQuick.Item")
|
||||
|
Reference in New Issue
Block a user