summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp')
-rw-r--r--src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp198
1 files changed, 192 insertions, 6 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
index 0facd04494..041bdf5b32 100644
--- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
+++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
@@ -30,6 +30,7 @@
#include "designeractionmanager.h"
#include "modelnodecontextmenu_helper.h"
#include <nodeproperty.h>
+#include <nodemetainfo.h>
namespace QmlDesigner {
@@ -246,6 +247,65 @@ public:
}
};
+class FillLayoutModelNodeAction : public ModelNodeAction
+{
+public:
+ FillLayoutModelNodeAction(const QString &description, const QByteArray &category, int priority,
+ ModelNodeOperations::SelectionAction action,
+ SelectionContextFunction enabled = &SelectionContextFunctors::always,
+ SelectionContextFunction visibility = &SelectionContextFunctors::always) :
+ ModelNodeAction(description, category, priority, action, enabled, visibility)
+ {}
+ virtual void updateContext()
+ {
+ defaultAction()->setSelectionContext(selectionContext());
+ if (selectionContext().isValid()) {
+ defaultAction()->setEnabled(isEnabled(selectionContext()));
+ defaultAction()->setVisible(isVisible(selectionContext()));
+
+ defaultAction()->setCheckable(true);
+ QmlItemNode itemNode = QmlItemNode(selectionContext().currentSingleSelectedNode());
+ if (itemNode.isValid()) {
+ bool flag = false;
+ if (itemNode.modelNode().hasProperty(m_propertyName)
+ || itemNode.propertyAffectedByCurrentState(m_propertyName))
+ flag = itemNode.modelValue(m_propertyName).toBool();
+ defaultAction()->setChecked(flag);
+ } else {
+ defaultAction()->setEnabled(false);
+ }
+ }
+ }
+protected:
+ PropertyName m_propertyName;
+};
+
+class FillWidthModelNodeAction : public FillLayoutModelNodeAction
+{
+public:
+ FillWidthModelNodeAction(const QString &description, const QByteArray &category, int priority,
+ ModelNodeOperations::SelectionAction action,
+ SelectionContextFunction enabled = &SelectionContextFunctors::always,
+ SelectionContextFunction visibility = &SelectionContextFunctors::always) :
+ FillLayoutModelNodeAction(description, category, priority, action, enabled, visibility)
+ {
+ m_propertyName = "Layout.fillWidth";
+ }
+};
+
+class FillHeightModelNodeAction : public FillLayoutModelNodeAction
+{
+public:
+ FillHeightModelNodeAction(const QString &description, const QByteArray &category, int priority,
+ ModelNodeOperations::SelectionAction action,
+ SelectionContextFunction enabled = &SelectionContextFunctors::always,
+ SelectionContextFunction visibility = &SelectionContextFunctors::always) :
+ FillLayoutModelNodeAction(description, category, priority, action, enabled, visibility)
+ {
+ m_propertyName = "Layout.fillHeight";
+ }
+};
+
class SelectionModelNodeAction : public MenuDesignerAction
{
public:
@@ -328,9 +388,42 @@ bool selectionHasSameParentAndInBaseState(const SelectionContext &context)
return selectionHasSameParent(context) && inBaseState(context);
}
+bool isNotInLayout(const SelectionContext &context)
+{
+ if (selectionNotEmpty(context)) {
+ ModelNode selectedModelNode = context.selectedModelNodes().first();
+ ModelNode parentModelNode;
+
+ if (selectedModelNode.hasParentProperty())
+ parentModelNode = selectedModelNode.parentProperty().parentModelNode();
+
+ if (parentModelNode.isValid() && parentModelNode.metaInfo().isValid())
+ return !parentModelNode.metaInfo().isLayoutable();
+ }
+
+ return true;
+}
+
bool selectionCanBeLayouted(const SelectionContext &context)
{
- return selectionHasSameParentAndInBaseState(context) && inBaseState(context);
+ return selectionHasSameParentAndInBaseState(context)
+ && inBaseState(context)
+ && isNotInLayout(context);
+}
+
+bool hasQtQuickLayoutImport(const SelectionContext &context)
+{
+ if (context.qmlModelView() && context.qmlModelView()->model()) {
+ Import import = Import::createLibraryImport(QLatin1String("QtQuick.Layouts"), QLatin1String("1.0"));
+ return context.qmlModelView()->model()->hasImport(import, true, true);
+ }
+
+ return false;
+}
+
+bool selectionCanBeLayoutedAndasQtQuickLayoutImport(const SelectionContext &context)
+{
+ return selectionCanBeLayouted(context) && hasQtQuickLayoutImport(context);
}
bool selectionNotEmptyAndHasZProperty(const SelectionContext &context)
@@ -350,6 +443,34 @@ bool selectionNotEmptyAndHasXorYProperty(const SelectionContext &context)
&& selectionHasProperty1or2(context, xProperty, yProperty);
}
+bool singleSelectionAndInQtQuickLayout(const SelectionContext &context)
+{
+ if (!singleSelection(context))
+ return false;
+
+ ModelNode currentSelectedNode = context.currentSingleSelectedNode();
+ if (!currentSelectedNode.isValid())
+ return false;
+
+ if (!currentSelectedNode.hasParentProperty())
+ return false;
+
+ ModelNode parentModelNode = currentSelectedNode.parentProperty().parentModelNode();
+
+ NodeMetaInfo metaInfo = parentModelNode.metaInfo();
+
+ if (!metaInfo.isValid())
+ return false;
+
+ return metaInfo.isSubclassOf("QtQuick.Layouts.Layout", -1, -1);
+}
+
+bool layoutOptionVisible(const SelectionContext &context)
+{
+ return multiSelectionAndInBaseState(context)
+ || singleSelectionAndInQtQuickLayout(context);
+}
+
void DesignerActionManager::createDefaultDesignerActions()
{
using namespace SelectionContextFunctors;
@@ -387,15 +508,80 @@ void DesignerActionManager::createDefaultDesignerActions()
(anchorsResetDisplayName, anchorsCategory, 180, &anchorsReset, &singleSelectionItemIsAnchored));
addDesignerAction(new MenuDesignerAction(layoutCategoryDisplayName, layoutCategory,
- priorityLayoutCategory, &multiSelectionAndInBaseState));
+ priorityLayoutCategory, &layoutOptionVisible));
addDesignerAction(new ModelNodeAction
- (layoutRowDisplayName, layoutCategory, 200, &layoutRow, &selectionCanBeLayouted));
+ (layoutRowPositionerDisplayName,
+ layoutCategory,
+ 200,
+ &layoutRowPositioner,
+ &selectionCanBeLayouted,
+ selectionCanBeLayouted));
+
addDesignerAction(new ModelNodeAction
- (layoutColumnDisplayName, layoutCategory, 180, &layoutColumn, &selectionCanBeLayouted));
+ (layoutColumnPositionerDisplayName,
+ layoutCategory,
+ 180,
+ &layoutColumnPositioner,
+ &selectionCanBeLayouted,
+ selectionCanBeLayouted));
+
+ addDesignerAction(new ModelNodeAction
+ (layoutGridPositionerDisplayName,
+ layoutCategory,
+ 160,
+ &layoutGridPositioner,
+ &selectionCanBeLayouted,
+ selectionCanBeLayouted));
+
addDesignerAction(new ModelNodeAction
- (layoutGridDisplayName, layoutCategory, 160, &layoutGrid, &selectionCanBeLayouted));
+ (layoutFlowPositionerDisplayName,
+ layoutCategory,
+ 140,
+ &layoutFlowPositioner,
+ &selectionCanBeLayouted,
+ selectionCanBeLayouted));
+
+ addDesignerAction(new SeperatorDesignerAction(layoutCategory, 120));
+
+ addDesignerAction(new ModelNodeAction
+ (layoutRowLayoutDisplayName,
+ layoutCategory,
+ 100,
+ &layoutRowLayout,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport));
+
+ addDesignerAction(new ModelNodeAction
+ (layoutColumnLayoutDisplayName,
+ layoutCategory,
+ 80,
+ &layoutColumnLayout,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport));
+
addDesignerAction(new ModelNodeAction
- (layoutFlowDisplayName, layoutCategory, 140, &layoutFlow, &selectionCanBeLayouted));
+ (layoutGridLayoutDisplayName,
+ layoutCategory,
+ 60,
+ &layoutGridLayout,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport,
+ &selectionCanBeLayoutedAndasQtQuickLayoutImport));
+
+ addDesignerAction(new FillWidthModelNodeAction
+ (layoutFillWidthDisplayName,
+ layoutCategory,
+ 40,
+ &setFillWidth,
+ singleSelectionAndInQtQuickLayout,
+ singleSelectionAndInQtQuickLayout));
+
+ addDesignerAction(new FillHeightModelNodeAction
+ (layoutFillHeightDisplayName,
+ layoutCategory,
+ 20,
+ &setFillHeight,
+ singleSelectionAndInQtQuickLayout,
+ singleSelectionAndInQtQuickLayout));
addDesignerAction(new SeperatorDesignerAction(rootCategory, priorityTopLevelSeperator));
addDesignerAction(new ModelNodeAction